From 121148f6cfc4aa7bef5d2b393f885c71b55a32d9 Mon Sep 17 00:00:00 2001 From: que01 Date: Wed, 21 Oct 2026 14:41:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=20deploy:status=20?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E8=84=9A=E6=9C=AC=E6=89=A7=E8=A1=8C=E5=B9=B6?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=20runner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy/status.mjs | 44 +++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/scripts/deploy/status.mjs b/scripts/deploy/status.mjs index dbea70c..5761d8a 100644 --- a/scripts/deploy/status.mjs +++ b/scripts/deploy/status.mjs @@ -15,26 +15,30 @@ function run(command, args) { process.stdout.write(result.stdout); } -run("ssh", [ - target, - "bash", - "-lc", - [ - "set -euo pipefail", - 'source "$HOME/.nvm/nvm.sh"', - "export DEPLOY_ROOT=/home/ubuntu/persional-brand", - 'printf "current=%s\\n" "$(readlink /home/ubuntu/persional-brand/current)"', - 'printf "api="; test "$(pm2 pid personal-brand-api)" != "0"; echo online', - 'printf "pm2-autostart="; systemctl --user is-enabled personal-brand-pm2.service', - 'printf "admin="; systemctl --user is-active personal-brand-admin-static.service', - 'printf "database="; docker inspect -f "{{.State.Status}}" personal-brand-postgres-1', - 'printf "backups="; find /home/ubuntu/persional-brand/shared/backups -maxdepth 1 -name "*.dump" | wc -l', - 'printf "latest-backup="; newest=$(find /home/ubuntu/persional-brand/shared/backups -maxdepth 1 -type f -name "*.dump" -printf "%T@ %p\\n" | sort -nr | head -1 | cut -d" " -f2-); test -n "$newest"; stat -c "%y %s bytes" "$newest"; docker exec -i personal-brand-postgres-1 pg_restore -l < "$newest" >/dev/null; echo readable', - 'printf "backup-temp-files="; find /home/ubuntu/persional-brand/shared/backups -maxdepth 1 -type f -name "*.tmp" | wc -l', - 'printf "disk="; df -h / | awk "NR==2 {print \\$5 \" used, \" \\$4 \" free\"}"', - 'printf "release-count="; find /home/ubuntu/persional-brand/releases -mindepth 1 -maxdepth 1 -type d | wc -l', - ].join("; "), -]); +// ssh 会把多个参数用空格拼成一个字符串交给远端 shell,整段脚本必须先整体加引号, +// 否则 `bash -lc set -euo pipefail; ...` 只会执行 `set`,其余命令落到远端登录 shell。 +function shellQuote(value) { + return "'" + value.replace(/'/g, "'\\''") + "'"; +} + +const remoteScript = [ + "set -euo pipefail", + 'source "$HOME/.nvm/nvm.sh"', + "export DEPLOY_ROOT=/home/ubuntu/persional-brand", + 'printf "current=%s\\n" "$(readlink /home/ubuntu/persional-brand/current)"', + 'printf "api="; test "$(pm2 pid personal-brand-api)" != "0"; echo online', + 'printf "pm2-autostart="; systemctl --user is-enabled personal-brand-pm2.service', + 'printf "admin="; systemctl --user is-active personal-brand-admin-static.service', + 'printf "database="; docker inspect -f "{{.State.Status}}" personal-brand-postgres-1', + 'printf "ci-runner="; systemctl --user is-active gitea-runner.service', + 'printf "backups="; find /home/ubuntu/persional-brand/shared/backups -maxdepth 1 -name "*.dump" | wc -l', + 'printf "latest-backup="; newest=$(find /home/ubuntu/persional-brand/shared/backups -maxdepth 1 -type f -name "*.dump" -printf "%T@ %p\\n" | sort -nr | head -1 | cut -d" " -f2-); test -n "$newest"; stat -c "%y %s bytes" "$newest"; docker exec -i personal-brand-postgres-1 pg_restore -l < "$newest" >/dev/null; echo readable', + 'printf "backup-temp-files="; find /home/ubuntu/persional-brand/shared/backups -maxdepth 1 -type f -name "*.tmp" | wc -l', + 'printf "disk="; df -h / | awk \'NR==2 {print $5 " used, " $4 " free"}\'', + 'printf "release-count="; find /home/ubuntu/persional-brand/releases -mindepth 1 -maxdepth 1 -type d | wc -l', +].join("; "); + +run("ssh", [target, "bash -lc " + shellQuote(remoteScript)]); for (const route of [ "/admin/",