allow fast update to restart system services
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
set -euo pipefail
|
||||
|
||||
# 快速更新脚本:适合已经完成首次部署后的日常代码更新。
|
||||
# 只做 git 更新、前端 build、重启用户级服务;不检查/安装系统依赖。
|
||||
# 只做 git 更新、前端 build、重启 systemd 服务;不检查/安装系统依赖。
|
||||
# 如果 pyproject.toml 在本次更新中变化,会额外同步一次 Python 依赖。
|
||||
# 如果本次改动包含依赖、systemd 模板或部署脚本变化,请使用 scripts/deploy-ubuntu.sh。
|
||||
|
||||
@@ -73,6 +73,18 @@ sync_python_dependencies_if_needed() {
|
||||
"${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}"
|
||||
[[ -d .git ]] || fail "${ROOT_DIR} 不是 git 仓库。"
|
||||
|
||||
@@ -111,19 +123,11 @@ export PATH="$(dirname "${npm_bin}"):${PATH}"
|
||||
"${npm_bin}" run build
|
||||
|
||||
log "重启 ${SERVICE_SCOPE} 服务"
|
||||
if [[ "${SERVICE_SCOPE}" == "system" ]]; then
|
||||
systemctl restart "${BACKEND_SERVICE}" "${FRONTEND_SERVICE}"
|
||||
else
|
||||
systemctl --user restart "${BACKEND_SERVICE}" "${FRONTEND_SERVICE}"
|
||||
fi
|
||||
systemctl_for_scope restart "${BACKEND_SERVICE}" "${FRONTEND_SERVICE}"
|
||||
|
||||
log "健康检查"
|
||||
sleep 1
|
||||
if [[ "${SERVICE_SCOPE}" == "system" ]]; then
|
||||
systemctl --no-pager --lines=0 status "${BACKEND_SERVICE}" "${FRONTEND_SERVICE}"
|
||||
else
|
||||
systemctl --user --no-pager --lines=0 status "${BACKEND_SERVICE}" "${FRONTEND_SERVICE}"
|
||||
fi
|
||||
systemctl_for_scope --no-pager --lines=0 status "${BACKEND_SERVICE}" "${FRONTEND_SERVICE}"
|
||||
|
||||
echo
|
||||
echo "快速更新完成。"
|
||||
|
||||
Reference in New Issue
Block a user