Expand description
systemd sd_notify integration (READY=1 / STOPPING=1 / etc.)
systemd sd_notify integration for the master process.
When sozu runs under a systemd unit declared Type=notify, the
master process tells systemd it is ready (READY=1) only AFTER the
initial workers have spawned and any saved state has been replayed
— without that handshake, Type=simple declares the unit ready as
soon as the binary forks, which is wrong for sozu’s master/worker
lifecycle (clients can hit a configured After=sozu.service peer
before sozu accepts traffic).
Implementation is std-only: read $NOTIFY_SOCKET, connect a
UnixDatagram, send the protocol-formatted state line. Closes
#228. Linux is the only target system where this matters in
practice; the helper is a no-op when $NOTIFY_SOCKET is unset
(e.g. when the operator runs sozu start from a shell without
systemd in the supervision chain), so non-Linux builds compile and
call into the helper without behavioural change.
Constants§
- STATE_
READY READY=1— master finished spawning workers and loading state.- STATE_
RELOADING RELOADING=1— hot reload begins (the same binary is reloading configuration; for binary upgrade seemain_pid).- STATE_
STOPPING STOPPING=1— graceful shutdown begins.- STATE_
WATCHDOG WATCHDOG=1— watchdog ping. Currently NOT wired into the master event loop — the bundledos-build/systemd/sozu.serviceandsozu@.serviceunits intentionally do NOT declareWatchdogSec=, so leaving this constant unused at link time is the documented state. Operators who addWatchdogSec=to a custom unit will see the unit get killed for missing pings until the periodic-timer follow-up lands.
Functions§
- main_
pid - Send
MAINPID=<pid>so systemd tracks the new master after a hot-upgrade re-exec hands the supervision off to a forked child.pidis unsigned becauseMAINPID=accepts unsigned decimal persd_notify(3); callers convert fromstd::process::id()directly. - notify
- Send a state message to systemd via
$NOTIFY_SOCKET. - status
- Send
STATUS=<text>for human-readable status (visible viasystemctl status sozu).