Skip to main content

Module sd_notify

Module sd_notify 

Source
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 see main_pid).
STATE_STOPPING
STOPPING=1 — graceful shutdown begins.
STATE_WATCHDOG
WATCHDOG=1 — watchdog ping. Currently NOT wired into the master event loop — the bundled os-build/systemd/sozu.service and sozu@.service units intentionally do NOT declare WatchdogSec=, so leaving this constant unused at link time is the documented state. Operators who add WatchdogSec= 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. pid is unsigned because MAINPID= accepts unsigned decimal per sd_notify(3); callers convert from std::process::id() directly.
notify
Send a state message to systemd via $NOTIFY_SOCKET.
status
Send STATUS=<text> for human-readable status (visible via systemctl status sozu).