把散落在代码里的真实部署值统一收进 config/,代码改为引用配置, 使仓库副本/开源导出不再带出生产域名、IP、内网路径与凭据。 新增 config/:platform.env.example(模板)· load.sh(shell 加载器)· index.cjs(node 加载器)· README.md(键一览与优先级)。 真实值放 config/platform.env —— 已 .gitignore 排除,不入库、不进导出。 TS 侧新增 src/platform-paths.ts 作部署路径的唯一解析处(零副作用): platformDir/stateDir/backupDir/artifactDir/installDir/scriptPath。 config.ts 接入这些字段;内置中继种子由生产 URL 改为空(改由 DSHS_OVERLAY_BOOTSTRAP_SEEDS 提供)。修掉 5 处硬编码绝对路径, src/** 注释中性化 116 行/53 文件。 scripts/** 36 个内部运维脚本:真令牌/PG 口令/隧道目标/主机号/路径 一律改从配置取;web/wake.html 的注册域白名单改为运行时从 location.hostname 推导;test/** 夹具 119 行/13 文件改 RFC 2606/5737 保留值,并把「内置种子必须为空」固化为回归断言。 取证:tsc 0 错;npm test 373/375(唯一失败 lease 属既有); 全仓扫描(大小写不敏感)代码面涉密标识 = 0;已部署 47 并零回归 (/opt/dsh/* 未搬家,/var/lib/dshs/platform 未被误建)。
65 lines
2.6 KiB
Bash
65 lines
2.6 KiB
Bash
#!/usr/bin/env bash
|
|
. "$(cd "$(dirname "$0")/.." && pwd)/config/load.sh"
|
|
# 在 47 初始化「控制面 PG」:独立数据目录 <data-root>-pg + 专用 unit dshs-pg.service
|
|
# 设计口径:控制面 DB 在 Manager 侧、仅 loopback、scram 认证。
|
|
set -uo pipefail
|
|
PGDATA="${DSH_PG_DATA_DIR}"
|
|
PGPORT=15432
|
|
DBPW="${DSHS_PG_PASSWORD:-dshs_cluster_2026}"
|
|
PGVER=$(/usr/bin/postgres --version | grep -oE '[0-9]+' | head -1)
|
|
echo " PG 版本: $(/usr/bin/postgres --version)"
|
|
|
|
# 别让发行版的默认单元意外起来(我们用自己的 unit + 自己的数据目录)
|
|
systemctl disable --now postgresql 2>/dev/null >/dev/null || true
|
|
|
|
if [ ! -f "$PGDATA/PG_VERSION" ]; then
|
|
install -d -o postgres -g postgres -m 700 "$PGDATA"
|
|
su - postgres -c "/usr/bin/initdb -D $PGDATA -E UTF8 --locale=C.UTF-8 --auth-local=peer --auth-host=scram-sha-256" >/tmp/initdb.log 2>&1 \
|
|
&& echo " ✓ initdb 完成" || { echo " ✗ initdb 失败"; tail -5 /tmp/initdb.log; exit 1; }
|
|
cat >> "$PGDATA/postgresql.conf" <<CONF
|
|
|
|
# ── DSHS 控制面(2026-09-15 集群化切换)──
|
|
listen_addresses = '127.0.0.1'
|
|
port = $PGPORT
|
|
unix_socket_directories = '/var/run/postgresql'
|
|
max_connections = 100
|
|
shared_buffers = 128MB
|
|
CONF
|
|
chown postgres:postgres "$PGDATA/postgresql.conf"
|
|
echo " ✓ 已写入 listen=127.0.0.1 port=$PGPORT"
|
|
fi
|
|
|
|
cat > /etc/systemd/system/dshs-pg.service <<UNIT
|
|
[Unit]
|
|
Description=DSHS control-plane PostgreSQL (cluster mode)
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=notify
|
|
User=postgres
|
|
Group=postgres
|
|
ExecStart=/usr/bin/postgres -D $PGDATA
|
|
ExecReload=/bin/kill -HUP \$MAINPID
|
|
KillMode=mixed
|
|
TimeoutStopSec=30
|
|
Restart=on-failure
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
UNIT
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable --now dshs-pg >/dev/null 2>&1
|
|
sleep 3
|
|
echo " dshs-pg: $(systemctl is-active dshs-pg) 监听: $(ss -lntp 2>/dev/null | grep -c $PGPORT)"
|
|
|
|
# 角色 + 库(幂等)
|
|
su - postgres -c "/usr/bin/psql -p $PGPORT -tAc \"select 1 from pg_roles where rolname='dshs'\"" 2>/dev/null | grep -q 1 \
|
|
|| su - postgres -c "/usr/bin/psql -p $PGPORT -c \"create role dshs login password '$DBPW'\"" >/dev/null 2>&1
|
|
su - postgres -c "/usr/bin/psql -p $PGPORT -tAc \"select 1 from pg_database where datname='dshs'\"" 2>/dev/null | grep -q 1 \
|
|
|| su - postgres -c "/usr/bin/psql -p $PGPORT -c \"create database dshs owner dshs\"" >/dev/null 2>&1
|
|
|
|
echo " --- 连接自检(dshs 角色) ---"
|
|
PGPASSWORD="$DBPW" /usr/bin/psql -h 127.0.0.1 -p $PGPORT -U dshs -d dshs -tAc "select current_user||'@'||current_database()||' pg='||version()" 2>&1 | head -1 | cut -c1-90
|
|
echo " 连接串(含密码,勿外传): postgres://dshs:$DBPW@127.0.0.1:$PGPORT/dshs"
|