Files
orangecat/scripts/systemd/orangecat-app.service
CatoandClaude Opus 5.5 ad37b55679 fix(ops): orangecat-app restarts after a SIGTERM nobody asked for (#1155)
2026-09-26 01:53:42 UTC a SIGTERM hit every *-app unit on the box at once.
About 20 units restarted in 3s; orangecat stayed down for 3h45m (502 on the
whole site) and nothing paged.

Cause: this unit alone sets SuccessExitStatus=143 SIGTERM (so deploys don't
log as crashes). With Restart=on-failure, that makes any SIGTERM a "success",
so there's no restart and no OnFailure alert. Its comment assumed SIGTERM is
always a requested stop; it isn't.

Restart=always keeps the clean deploy journal (systemd never restarts after an
explicit stop/restart) and restarts after anything else. Already applied on
the box and proven: kill -TERM <main pid> → new PID, NRestarts=1, health 200.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 23:04:45 -07:00

54 lines
2.4 KiB
Desktop File

# OrangeCat app — systemd unit (SSOT).
#
# This is the live unit from the box (/etc/systemd/system/orangecat-app.service),
# vendored here so it's version-controlled instead of existing only on bitbaum.
# Install on a fresh box with:
# sudo install -m 644 scripts/systemd/orangecat-app.service /etc/systemd/system/
# sudo systemctl daemon-reload && sudo systemctl enable --now orangecat-app
# See docs/operations/RESILIENCE.md for full box bring-up.
[Unit]
Description=orangecat Next.js application server
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/opt/orangecat/app
EnvironmentFile=/opt/orangecat/app/.env
ExecStart=/opt/orangecat/app/launch.sh
# `always`, not `on-failure`, because of SuccessExitStatus below: with
# on-failure, a SIGTERM that nobody asked for is a "success", so the app just
# stays down — no restart and no OnFailure page. 2026-09-26 01:53:42 a stray
# SIGTERM hit every app on the box at once; the other ~20 units restarted in
# 3s, orangecat sat dead for 3h45m and nothing alerted. `always` still never
# restarts after an explicit `systemctl stop`/`restart` (a deploy), so the
# journal stays clean.
Restart=always
RestartSec=3
# A deploy stops this unit with SIGTERM, and Next exits 143. Without this,
# systemd records every ordinary deploy as
# orangecat-app.service: Failed with result 'exit-code'
# and fires OnFailure= (the notify-failure@ drop-in on the box).
#
# That is not a paging bug — notify-failure.sh is recovery-aware: it waits 8s,
# sees the unit active again, and logs "failed but recovered (restart/transient)
# — not paging". 38 such suppressions in the last 7 days across the box.
#
# It IS a diagnosis bug. Reading this unit's journal, a routine deploy is
# indistinguishable from a crash: three "Failed with result 'exit-code'" lines
# in one afternoon read as a crash loop, and cost real time to rule out
# (2026-09-07, while chasing an unrelated report). Telling systemd that a
# requested stop is a success makes the journal mean what it says, and stops
# spawning a notifier per deploy to conclude nothing happened.
#
# OOM kills with SIGKILL (9), which still counts as a failure and still pages.
# SIGTERM is NOT always a requested stop (see Restart= above) — which is why
# this line is only safe paired with Restart=always.
SuccessExitStatus=143 SIGTERM
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target