Scripts: a failed install shows its PM2 apps' last log lines

Before removing what a failed install made, print each PM2 app's last
30 log lines, so the Hub's job log says why the backend didn't start
instead of only "/health didn't report 2.3.1 within 90s".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 08:44:38 +02:00
co-authored by Claude Opus 5.5
parent 06222fd94a
commit 6988b5ce7c
3 changed files with 39 additions and 1 deletions
+15 -1
View File
@@ -58,12 +58,26 @@ random_secret() { openssl rand -base64 64 | tr -d '/+=\n' | head -c "${1:-48}";
INSTALL_UNDO=""
undo_add() { [ -z "$INSTALL_UNDO" ] || printf '%s\n' "$*" >> "$INSTALL_UNDO"; }
# pm2_last_logs <user> <name…>: each PM2 app's last 30 log lines (output and errors), indented.
pm2_last_logs() {
local user="$1" name
shift
for name in "$@"; do
info "PM2: last log lines of $name"
run_as "$user" / pm2 logs "$name" --lines 30 --nostream --raw </dev/null 2>&1 | tail -n 60 | sed 's/^/ /' || true
done
}
install_undo() {
local kind a b
step "Removing what this install made"
tac "$INSTALL_UNDO" | while read -r kind a b; do
case "$kind" in
pm2) # shellcheck disable=SC2086 # b is a space-separated list of PM2 names
pm2)
# Their logs go with them, so show why they didn't start first (the Hub gets the log).
# shellcheck disable=SC2086 # b is a space-separated list of PM2 names
pm2_last_logs "$a" $b
# shellcheck disable=SC2086
run_as "$a" / pm2 delete $b >/dev/null 2>&1 || true
run_as "$a" / pm2 save --force >/dev/null 2>&1 || true
info "PM2: $b removed" ;;