fix: 修正 deploy:status 远程脚本执行并检查 runner

This commit is contained in:
que01 committed 2026-10-21 14:41:39 +08:00
1 parent a08a2f0f98
commit 121148f6cf
1 file changed
+24 -20
+24 -20
View File
@@ -15,26 +15,30 @@ function run(command, args) {
process.stdout.write(result.stdout); process.stdout.write(result.stdout);
} }
run("ssh", [ // ssh 会把多个参数用空格拼成一个字符串交给远端 shell,整段脚本必须先整体加引号,
target, // 否则 `bash -lc set -euo pipefail; ...` 只会执行 `set`,其余命令落到远端登录 shell。
"bash", function shellQuote(value) {
"-lc", return "'" + value.replace(/'/g, "'\\''") + "'";
[ }
"set -euo pipefail",
'source "$HOME/.nvm/nvm.sh"', const remoteScript = [
"export DEPLOY_ROOT=/home/ubuntu/persional-brand", "set -euo pipefail",
'printf "current=%s\\n" "$(readlink /home/ubuntu/persional-brand/current)"', 'source "$HOME/.nvm/nvm.sh"',
'printf "api="; test "$(pm2 pid personal-brand-api)" != "0"; echo online', "export DEPLOY_ROOT=/home/ubuntu/persional-brand",
'printf "pm2-autostart="; systemctl --user is-enabled personal-brand-pm2.service', 'printf "current=%s\\n" "$(readlink /home/ubuntu/persional-brand/current)"',
'printf "admin="; systemctl --user is-active personal-brand-admin-static.service', 'printf "api="; test "$(pm2 pid personal-brand-api)" != "0"; echo online',
'printf "database="; docker inspect -f "{{.State.Status}}" personal-brand-postgres-1', 'printf "pm2-autostart="; systemctl --user is-enabled personal-brand-pm2.service',
'printf "backups="; find /home/ubuntu/persional-brand/shared/backups -maxdepth 1 -name "*.dump" | wc -l', 'printf "admin="; systemctl --user is-active personal-brand-admin-static.service',
'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 "database="; docker inspect -f "{{.State.Status}}" personal-brand-postgres-1',
'printf "backup-temp-files="; find /home/ubuntu/persional-brand/shared/backups -maxdepth 1 -type f -name "*.tmp" | wc -l', 'printf "ci-runner="; systemctl --user is-active gitea-runner.service',
'printf "disk="; df -h / | awk "NR==2 {print \\$5 \" used, \" \\$4 \" free\"}"', 'printf "backups="; find /home/ubuntu/persional-brand/shared/backups -maxdepth 1 -name "*.dump" | wc -l',
'printf "release-count="; find /home/ubuntu/persional-brand/releases -mindepth 1 -maxdepth 1 -type d | 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',
].join("; "), '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 [ for (const route of [
"/admin/", "/admin/",