diff --git a/scripts/setup.sh b/scripts/setup.sh index ce783b6c..99913700 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -903,6 +903,43 @@ else fi fi +# ─── 19. start the services ────────────────────────────────────────────────── +echo "" +echo "── Services (pm2) ──" + +# Installing pm2 is not the same as running anything with it. Without this the setup finishes with +# every dependency in place and nothing actually listening — and the sidecars matter beyond the web +# app: /desktop returns 503 until officer-vnc is connected, and chat needs officer-claude. +if ! has pm2 || [ ! -f "$PROJECT_DIR/ecosystem.config.cjs" ]; then + warn "Skipping service start (pm2 or ecosystem.config.cjs missing)" +else + # startOrRestart also picks up apps added to the ecosystem since the last run. These are all + # fork-mode apps, so reload would buy nothing over restart. + echo " Starting Officer and its sidecars..." + if (cd "$PROJECT_DIR" && pm2 startOrRestart ecosystem.config.cjs); then + ok "services started" + else + fail "pm2 could not start the services — check 'pm2 logs'" + fi + + # Persist the process list so the boot unit has something to resurrect. + pm2 save >/dev/null 2>&1 && ok "process list saved" || warn "pm2 save failed" + + # Boot persistence. pm2 startup writes a systemd unit; it needs root, and re-running it when the + # unit already exists is harmless. + if systemctl list-unit-files 2>/dev/null | grep -q "^pm2-$(whoami)\.service"; then + skip "pm2 boot service (pm2-$(whoami).service)" + else + echo " Enabling start on boot..." + if sudo env PATH="$PATH" pm2 startup systemd -u "$(whoami)" --hp "$HOME" >/dev/null 2>&1; then + pm2 save >/dev/null 2>&1 + ok "services will start on boot" + else + warn "Could not enable boot startup — run: pm2 startup (and follow its instructions)" + fi + fi +fi + # ─── verification ───────────────────────────────────────────────────────────── echo "" echo "═══════════════════════════════════════════" @@ -973,6 +1010,20 @@ echo "" echo "═══════════════════════════════════════════" echo " Setup complete!" echo "═══════════════════════════════════════════" +# Services actually running is a better signal than the binaries being present. The list comes from +# ecosystem.config.cjs so it cannot drift as sidecars are added. +if has pm2 && [ -f "$PROJECT_DIR/ecosystem.config.cjs" ]; then + echo "" + echo "Services:" + for app in $(grep -oE "name: *'[^']+'" "$PROJECT_DIR/ecosystem.config.cjs" | sed "s/.*'\(.*\)'/\1/"); do + if pm2 pid "$app" >/dev/null 2>&1 && [ -n "$(pm2 pid "$app" 2>/dev/null | tr -d '[:space:]')" ]; then + ok "$app" + else + fail "$app — not running (pm2 logs $app)" + fi + done +fi + echo "" echo "Notes:" echo " • PulseAudio null sink starts automatically with the server"