Service/daemon wrapper. Supports Windows, Linux (systemd) and macOS.
Different Linux distributions place systemd unit files in different locations:
- Debian/Ubuntu and modern RHEL-based systems:
/usr/lib/systemd/system/ - Older systems and some distributions:
/lib/systemd/system/ - User-specific overrides:
/etc/systemd/system/
This library detects the correct systemd unit directory at runtime using the following strategy:
-
Environment variable override (
CEVICHE_SYSTEMD_UNITDIR): If set, this takes precedence over everything else. Use this when you need explicit control over where units are installed. -
pkg-config detection: We query
pkg-config --variable=systemdsystemunitdir systemdto get the distribution's preferred location. This works on most modern systems that have systemd development packages installed. -
Fallback probing: If pkg-config is unavailable or doesn't return a result, we probe common directories in order:
/usr/lib/systemd/system/lib/systemd/system
If you're creating distribution packages (.deb, .rpm, etc.), you should:
- For Debian/Ubuntu: Use
dh_installsystemdor manually install to${prefix}/lib/systemd/system/ - For RPM-based systems: Use
%{_unitdir}macro in your spec file - Let the distribution's packaging tools determine the correct location
This runtime detection is a pragmatic compromise for applications that need to self-register as services without relying on package manager scripts. It works well for:
- Development and testing
- Self-contained applications
- Situations where you can't use distribution-specific packaging
By default, ceviche will detect and use the system unit directory. To override:
# Specify a custom location
export CEVICHE_SYSTEMD_UNITDIR=/etc/systemd/system
./your-application service registerWe default to system units (/usr/lib/systemd/system/ or /lib/systemd/system/) rather than user units (/usr/lib/systemd/user/, ~/.config/systemd/user/, etc) because:
- Most services run system-wide
- System units are more common for daemon applications
- You can always override with
CEVICHE_SYSTEMD_UNITDIRif you need user units