From fe530a619de970c7a013744f0d1e441bc02c2c0a Mon Sep 17 00:00:00 2001 From: dekun Date: Sun, 11 Oct 2026 00:41:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=92=8C=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E6=94=B9=E4=B8=BA=E7=94=B1=20root=20?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- deploy/manage.sh | 16 +++++++++++++--- 部署.md | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/deploy/manage.sh b/deploy/manage.sh index ec31f2b..1074df5 100644 --- a/deploy/manage.sh +++ b/deploy/manage.sh @@ -16,7 +16,7 @@ INSTALL_ROOT="${INSTALL_ROOT:-/opt/hypernode}" DATA_DIR="${DATA_DIR:-/var/lib/hypernode}" GIT_URL="${GIT_URL:-https://git.bz121.com/dekun/HyperNode-AI.git}" GIT_BRANCH="${GIT_BRANCH:-main}" -APP_USER="hypernode" +APP_USER="root" SERVICE_NAME="hypernode" BIND_HOST="0.0.0.0" BIND_PORT="33333" @@ -108,6 +108,9 @@ install_packages() { } ensure_user() { + if [[ "${APP_USER}" == "root" ]]; then + return 0 + fi if ! id -u "${APP_USER}" >/dev/null 2>&1; then useradd --system --home-dir "${INSTALL_ROOT}" --shell /usr/sbin/nologin "${APP_USER}" fi @@ -223,7 +226,11 @@ wait_until_ready() { verify_app() { log "检查程序能否启动" - if ! /usr/sbin/runuser -u "${APP_USER}" -- bash -c "cd '${INSTALL_ROOT}' && exec '${INSTALL_ROOT}/.venv/bin/python' -c 'import app.main'"; then + local runner=(bash -c "cd '${INSTALL_ROOT}' && exec '${INSTALL_ROOT}/.venv/bin/python' -c 'import app.main'") + if [[ "${APP_USER}" != "root" ]]; then + runner=(/usr/sbin/runuser -u "${APP_USER}" -- "${runner[@]}") + fi + if ! "${runner[@]}"; then echo "程序导入失败,没有重启服务。请把上面的报错发出来。" >&2 return 1 fi @@ -307,9 +314,12 @@ cmd_uninstall() { echo "数据库已保留在 ${DATA_DIR}" fi - if id -u "${APP_USER}" >/dev/null 2>&1; then + if [[ "${APP_USER}" != "root" ]] && id -u "${APP_USER}" >/dev/null 2>&1; then userdel "${APP_USER}" || echo "系统用户 ${APP_USER} 未删除,可稍后执行 userdel ${APP_USER}" fi + if id -u hypernode >/dev/null 2>&1; then + userdel hypernode >/dev/null 2>&1 || true + fi log "卸载完成" } diff --git a/部署.md b/部署.md index e879830..07607e5 100644 --- a/部署.md +++ b/部署.md @@ -67,7 +67,7 @@ curl http://127.0.0.1:33333/health 手动补跑某一天的清算: ```bash -sudo -u hypernode /opt/hypernode/.venv/bin/python -m app.settle --date 2026-10-09 +/opt/hypernode/.venv/bin/python -m app.settle --date 2026-10-09 ``` 不带日期时,结算上一个已经结束的 UTC 账本日。服务正常运行时,北京时间每天 00:05 会自动执行。