Skip to main content

Module daemon_service

Module daemon_service 

Source
Expand description

lev daemon install / lev daemon uninstall - hand the daemon to the OS supervisor so it comes back by itself after a crash.

Without supervision, nothing restarts the daemon when it dies: a long-running agent simply stops, and the next lev run is the only thing that brings the daemon back. Registering a launchd agent (macOS) or a systemd user unit (Linux) with a restart policy closes that gap - and on the next start the daemon’s own recovery pass reloads every interrupted run.

This module is the tested core: rendering the unit file, resolving where it goes, writing/removing it, and building the activation command line. Running that command is real subprocess I/O and lives in the binary.

Platform differences are #[cfg]-gated rather than branched at runtime, so each target compiles exactly the code it uses (and covers all of it).

Structs§

ServiceUnit
A rendered service definition and where it belongs.

Constants§

SERVICE_LABEL
The reverse-DNS label both platforms key the service by.

Functions§

config_home
Where the unit file goes, relative to the user’s home directory.
format_supervision
The line lev daemon status adds about supervision.
install
Write unit to disk, creating its parent directory. Returns the path.
service_unit
Build the service definition for this platform (see the macOS variant for the argument contract; uid is unused here - systemd’s --user mode already addresses the calling user’s manager).
systemd_unit
A systemd user unit (no root needed) with the same restart policy.
uninstall
Remove the unit file. Returns whether there was one to remove.
unit_safe
Reject a value that cannot be safely interpolated into a systemd unit file.