Files
dsh_shenxian/dsh-server-docs/06-ops/scripts/switch-domain-alotbuy.sh
T
admin 5ec99ce227
build / build-and-scan (push) Canceled after 0s
chore: 文档库全量重新入库(2026-10-20)
2026-10-20 15:05:55 +08:00

51 lines
1.9 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
# 切换 DSH 平台服务域名 → alotbuy.com(2026-09-10)
# 幂等;带备份;drain 采用「按 pid 结束」而非 pkill -f(避免杀掉自身 ssh 会话)
set -euo pipefail
NEW_BASE=alotbuy.com
NEW_COOKIE=.alotbuy.com
ENV=/etc/dshs.env
TS=$(date +%Y%m%d-%H%M)
echo "=== 1) 备份 env ==="
cp -a "$ENV" "$ENV.bak-$TS"
echo " 备份: $ENV.bak-$TS"
echo "=== 2) 写入新域名 ==="
sed -i "s|^DSHS_BASE_DOMAIN=.*|DSHS_BASE_DOMAIN=$NEW_BASE|" "$ENV"
sed -i "s|^DSHS_COOKIE_DOMAIN=.*|DSHS_COOKIE_DOMAIN=$NEW_COOKIE|" "$ENV"
grep -E 'BASE_DOMAIN|COOKIE_DOMAIN' "$ENV" | sed 's/^/ /'
echo "=== 3) drain:停编排器 → 结束残留实例/scope → 起编排器 ==="
systemctl stop dshs
sleep 2
# 3a. 按 pid 结束 dsh 子进程(uid 形如 dsh-xxxx)
for pid in $(ps -eo pid,user,args | awk '$2 ~ /^dsh-/ {print $1}'); do
kill "$pid" 2>/dev/null || true
done
# 3b. 结束 bwrap 包装进程(用 grep 中括号技巧避免匹配自身)
for pid in $(ps -eo pid,args | grep "[b]wrap --ro-bind" | awk '{print $1}'); do
kill "$pid" 2>/dev/null || true
done
sleep 2
# 3c. 收尾残留 scope
systemctl list-units --type=scope --all --no-legend 'dsh-*' 2>/dev/null | awk '{print $1}' | while read -r u; do
[ -n "$u" ] && systemctl stop "$u" 2>/dev/null || true
done
sleep 1
echo " 残留实例数: $(ps -eo user,args | grep -c '[d]sh --profile' || true)"
echo "=== 4) 启动编排器 ==="
systemctl start dshs
sleep 3
echo " 服务: $(systemctl is-active dshs) / enabled=$(systemctl is-enabled dshs)"
echo " 编排器 pid: $(pgrep -f lib/cli.js | head -1)"
echo "=== 5) 自检 ==="
curl -sk -o /dev/null -w " 源站 https://alotbuy.com/login.html → %{http_code}\n" \
--resolve alotbuy.com:443:127.0.0.1 https://alotbuy.com/login.html
curl -s -o /dev/null -w " 经 CF https://alotbuy.com/login.html → %{http_code}\n" -m 15 \
https://alotbuy.com/login.html
echo " 完成(旧域名 301 见 dsh.alotbuy.com.conf)"