spark-supervisor
Process supervisor and health monitor for sovereign daemons
Brought by drakestapleton
spark-supervisor / tools / aien-supervise.service
| 1 | # The one systemd unit kept for the operator's own services ("I want that systemd replaced by omega"). |
| 2 | # It does two things only: start the Omega aien-supervise at boot, and |
| 3 | # hand it a delegated cgroup (cgroup v2 lets an unprivileged process manage only a subtree that root or |
| 4 | # the user manager chowned to it; cgroupfs is rebuilt every boot, so some boot-time root actor must do |
| 5 | # it, and on this machine that actor is systemd). Every service lives in ~/.config/aien-supervise/services. |
| 6 | # Source of truth: tools/aien-supervise.service in spark-supervisor (README "What still depends on systemd"). |
| 7 | # Undo: systemctl --user disable --now aien-supervise (services then need their old units back). |
| 8 | [Unit] |
| 9 | Description=Omega aien-supervise (runs the services in ~/.config/aien-supervise/services) |
| 10 | |
| 11 | [Service] |
| 12 | Type=simple |
| 13 | Slice=app.slice |
| 14 | Delegate=cpu memory pids |
| 15 | # The daemon's cgroup root is read from /proc/self/cgroup at start (the unit's own delegated cgroup), not typed. |
| 16 | ExecStart=/bin/sh -c 'exec /usr/bin/env -i HOME=%h AIEN_SUPERVISE_CGROUP=/sys/fs/cgroup$$(sed -n "s/^0:://p" /proc/self/cgroup) %h/.local/bin/aien-supervise run' |
| 17 | # Ordered stop: ask the daemon to stop its services (reverse order, each with its stoptime) and wait until it |
| 18 | # has exited; only then does systemd clean up whatever is left in the cgroup. Nothing to do if the daemon |
| 19 | # already exited by itself (systemd runs ExecStop then too). |
| 20 | ExecStop=/bin/sh -c '[ -n "$$MAINPID" ] || exit 0; /usr/bin/env -i HOME=%h %h/.local/bin/aien-supervise shutdown; while kill -0 "$$MAINPID" 2>/dev/null; do sleep 0.5; done' |
| 21 | KillMode=control-group |
| 22 | TimeoutStopSec=120 |
| 23 | # shutdown exits 0 and must stay down; exit 3 means another daemon is already running (do not loop on it). |
| 24 | Restart=on-failure |
| 25 | RestartPreventExitStatus=3 |
| 26 | RestartSec=5 |
| 27 | |
| 28 | [Install] |
| 29 | WantedBy=default.target |