PM2 runs under its own systemd unit, never as a child of the agent

Found in the VM test: a site's PM2 daemon started from the agent's install
job belonged to the agent's service, so stopping or updating the agent took
down every site it had installed. Before any PM2 command as a site user,
the scripts now make sure that user's daemon runs under pm2-<user> (moving
one that runs elsewhere, keeping its process list). The agent's stats no
longer start an empty daemon by asking one that isn't running. Uninstall
stops the unit before removing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 16:40:12 +02:00
co-authored by Claude Opus 5.5
parent 19709c2c75
commit 570f2dda5a
4 changed files with 44 additions and 2 deletions
+1
View File
@@ -170,6 +170,7 @@ cmd_uninstall() {
rm -rf -- "$(church_dir "$church")"
# The app user goes too when crosscode made it for this church (cc-<church>).
if [ "$user" = "cc-$church" ] && id "$user" >/dev/null 2>&1; then
systemctl stop "pm2-$user" >/dev/null 2>&1 || true
pm2 unstartup systemd -u "$user" >/dev/null 2>&1 || true
pkill -u "$user" 2>/dev/null || true
userdel -r "$user" >/dev/null 2>&1 || warn "The user $user couldn't be removed (userdel -r $user)."