Files
dsh_shenxian/scripts/switch-C-worker.sh
T
admin 452924d89c feat(config): 涉密内容外置到配置目录(档案 140)
把散落在代码里的真实部署值统一收进 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 未被误建)。
2026-09-19 15:12:19 +08:00

56 lines
2.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# C 步(在 106 上跑):把生产 Worker agent 装成 systemd 单元
# · env 与 47 的生产实例侧对齐(DSH_INSTANCE_* 必须一致 —— 实例是在 Worker 上 spawn 的)
# · token 走 env 文件(600)而不是命令行,避免 ps 泄露
# · 反向隧道复用演练时那把 key(其公钥已在 47 的 authorized_keys 里,restrict,port-forwarding)
set -uo pipefail
. "$(cd "$(dirname "$0")/.." && pwd)/config/load.sh"
# 凭据 / 地址一律来自配置(config/platform.env)—— ⛔ 不在脚本里写死
TOKEN="${DSH_PEER_AGENT_TOKEN:?config/platform.env 缺 DSH_PEER_AGENT_TOKEN}"
cat > /etc/dshs-worker.env <<ENV
# DSHS 集群 Worker(2026-09-15 切换)—— 与 47 /etc/dshs.env 的**实例侧**条目保持一致
DSHS_DATA_ROOT=$DSHS_DATA_ROOT
DSHS_ISOLATION_MODE=account
DSHS_DSH_BIN=/usr/bin/dsh
DSHS_BASE_UID=100000
DSH_INSTANCE_NODE_OPTIONS=--max-old-space-size=160
DSH_INSTANCE_UNIVER_SOCKET=auto
# 控制通道:Worker 主动拨 Manager 的反向隧道(公网入方向被云安全组挡住 ⇒ 只能这个方向)
DSHS_CLUSTER_AGENT_TOKEN=$TOKEN
DSHS_TUNNEL_TARGET=$DSHS_TUNNEL_TARGET
DSHS_TUNNEL_IDENTITY=/root/.ssh/tunnel_ed25519
ENV
chmod 600 /etc/dshs-worker.env
cat > /etc/systemd/system/dshs-worker.service <<UNIT
[Unit]
Description=DSHS cluster worker agent (hosts per-user dsh instances on 106)
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
EnvironmentFile=/etc/dshs-worker.env
ExecStart=/usr/bin/node $DSH_INSTALL_DIR-cluster/lib/cli.js worker --port 19000 --host 127.0.0.1 --host-id $DSH_PEER_HOST_ID --instance-host 127.0.0.1 --log-level info
Restart=on-failure
RestartSec=3
KillMode=mixed
[Install]
WantedBy=multi-user.target
UNIT
systemctl daemon-reload
systemctl enable dshs-worker >/dev/null 2>&1
echo " 单元已装并 enable;token 长度=${#TOKEN}"
# 旧的手工 agent 若在跑先停(按端口定位)
pid=$(ss -lntpH 'sport = :19000' 2>/dev/null | grep -oP 'pid=\K[0-9]+' | head -1)
[ -n "$pid" ] && kill "$pid" && sleep 2 && echo " 已停旧的手工 agent pid=$pid"
systemctl restart dshs-worker
sleep 6
echo " dshs-worker=$(systemctl is-active dshs-worker)"
echo " healthz: $(curl -s -m 6 http://127.0.0.1:19000/healthz | head -c 200)"