部署:update.sh 改由 deploy/update-bg.sh 在服务器上后台跑(setsid),SSH 断了它照样跑完。2026-11-03 开发机上 FlClash 切换配置重建了 TUN 网卡,SSH 正好断在 docker compose up 中间:旧容器删了、新容器只创建没启动,网站停了 40 分钟。输出写到 /var/tmp/iot_sim-update.log,--follow <提交号> 接着看输出、退出码和 update.sh 一样,这个提交的部署还没开始时返回 75;上一次还在跑就等它结束。Gitea 的"起服务"ssh 返回 255 就 10 秒后重连 --follow,75 就重新开始,最多 6 次。GitHub 备用部署也改用 update-bg.sh。部署说明同步
Deploy / deploy (push) Successful in 1m28s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-11-03 13:32:21 +08:00
1 parent 2aa267839f
commit f242308a3b
4 files changed
+85 -4

No files matched your search

+19 -2
View File
@@ -110,9 +110,26 @@ jobs:
# 先把服务器上的代码切到这个提交再跑 update.sh:不然跑的是上一版的 update.sh,改了它要晚一次部署才生效。
# 重启会结束正在运行的学生程序,上课时间尽量不要推送 main。
#
# update.sh 由 update-bg.sh 在服务器上后台跑,SSH 断了(开发机切代理、换网络)它照样跑完;
# 这边 ssh 返回 255(连接出错)就重连,用 --follow 接着看、拿退出码。
# 75 = 服务器上这个提交的部署还没开始(断在 git fetch 那里),重新开始。
- name: 起服务
timeout-minutes: 10
env:
SHA: ${{ gitea.sha }}
run: |
ssh -o BatchMode=yes -o ServerAliveInterval=15 -o ServerAliveCountMax=8 "$REMOTE" \
"cd $REMOTE_DIR && git fetch --quiet origin && git reset --quiet --hard $SHA && deploy/update.sh $SHA --prebuilt"
remote() { ssh -o BatchMode=yes -o ConnectTimeout=20 -o ServerAliveInterval=15 -o ServerAliveCountMax=8 "$REMOTE" "$1"; }
start="cd $REMOTE_DIR && git fetch --quiet origin && git reset --quiet --hard $SHA && deploy/update-bg.sh $SHA --prebuilt"
follow="cd $REMOTE_DIR && deploy/update-bg.sh --follow $SHA"
code=0; remote "$start" || code=$?
for attempt in 1 2 3 4 5 6; do
case $code in
255) echo "::warning::和服务器的 SSH 断了,部署在服务器上接着跑,10 秒后重连接着看"
sleep 10; code=0; remote "$follow" || code=$? ;;
75) echo "::warning::服务器上的部署还没开始,重新开始"
code=0; remote "$start" || code=$? ;;
*) exit $code ;;
esac
done
exit $code