allow fast update to restart system services

This commit is contained in:
wuyang6
2026-06-12 11:36:14 +08:00
parent c4a0b6187b
commit 26e886fb57
+15 -11
View File
@@ -2,7 +2,7 @@
set -euo pipefail set -euo pipefail
# 快速更新脚本:适合已经完成首次部署后的日常代码更新。 # 快速更新脚本:适合已经完成首次部署后的日常代码更新。
# 只做 git 更新、前端 build、重启用户级服务;不检查/安装系统依赖。 # 只做 git 更新、前端 build、重启 systemd 服务;不检查/安装系统依赖。
# 如果 pyproject.toml 在本次更新中变化,会额外同步一次 Python 依赖。 # 如果 pyproject.toml 在本次更新中变化,会额外同步一次 Python 依赖。
# 如果本次改动包含依赖、systemd 模板或部署脚本变化,请使用 scripts/deploy-ubuntu.sh。 # 如果本次改动包含依赖、systemd 模板或部署脚本变化,请使用 scripts/deploy-ubuntu.sh。
@@ -73,6 +73,18 @@ sync_python_dependencies_if_needed() {
"${python_bin}" -m pip install -e . "${python_bin}" -m pip install -e .
} }
systemctl_for_scope() {
if [[ "${SERVICE_SCOPE}" == "system" ]]; then
if [[ "${EUID}" == "0" ]]; then
systemctl "$@"
else
sudo systemctl "$@"
fi
else
systemctl --user "$@"
fi
}
cd "${ROOT_DIR}" cd "${ROOT_DIR}"
[[ -d .git ]] || fail "${ROOT_DIR} 不是 git 仓库。" [[ -d .git ]] || fail "${ROOT_DIR} 不是 git 仓库。"
@@ -111,19 +123,11 @@ export PATH="$(dirname "${npm_bin}"):${PATH}"
"${npm_bin}" run build "${npm_bin}" run build
log "重启 ${SERVICE_SCOPE} 服务" log "重启 ${SERVICE_SCOPE} 服务"
if [[ "${SERVICE_SCOPE}" == "system" ]]; then systemctl_for_scope restart "${BACKEND_SERVICE}" "${FRONTEND_SERVICE}"
systemctl restart "${BACKEND_SERVICE}" "${FRONTEND_SERVICE}"
else
systemctl --user restart "${BACKEND_SERVICE}" "${FRONTEND_SERVICE}"
fi
log "健康检查" log "健康检查"
sleep 1 sleep 1
if [[ "${SERVICE_SCOPE}" == "system" ]]; then systemctl_for_scope --no-pager --lines=0 status "${BACKEND_SERVICE}" "${FRONTEND_SERVICE}"
systemctl --no-pager --lines=0 status "${BACKEND_SERVICE}" "${FRONTEND_SERVICE}"
else
systemctl --user --no-pager --lines=0 status "${BACKEND_SERVICE}" "${FRONTEND_SERVICE}"
fi
echo echo
echo "快速更新完成。" echo "快速更新完成。"