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
+17
View File
@@ -259,3 +259,20 @@ EOF
[ "$(host_from_url "$(env_value "$TMP/.env" FRONTEND_URL)")" = events.hopefamily.co.za ]
[ "$(host_from_url http://localhost:3000/x)" = localhost ]
}
# ── install undo ────────────────────────────────────────────────────────────────────────────
@test "a failed install shows each PM2 app's last log lines before removing it" {
# shellcheck source=../lib/install.sh
source "$BATS_TEST_DIRNAME/../lib/install.sh"
run_as() { shift 2; case "$2" in logs) printf 'Error: %s crashed\n' "$3" ;; esac; echo "$*" >> "$TMP/pm2"; }
INSTALL_UNDO="$TMP/undo"
undo_add pm2 cc-hope "hope-events-backend hope-events-frontend"
run install_undo
[ "$status" -eq 0 ]
[[ "$output" == *"last log lines of hope-events-backend"* ]]
[[ "$output" == *" Error: hope-events-backend crashed"* ]]
[[ "$output" == *" Error: hope-events-frontend crashed"* ]]
# The logs are read before the apps are deleted.
[ "$(grep -n 'logs hope-events-backend' "$TMP/pm2" | cut -d: -f1)" -lt "$(grep -n '^pm2 delete' "$TMP/pm2" | cut -d: -f1)" ]
}