Thanks to visit codestin.com
Credit goes to lib.rs

18 releases

0.7.0 Oct 31, 2025
0.6.1 Sep 13, 2024
0.6.0 Mar 14, 2024
0.5.2 Apr 13, 2022
0.2.0 Sep 10, 2018

#304 in Unix APIs

Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

359 downloads per month

MIT/Apache

55KB
1.5K SLoC

ceviche-rs

Cargo Documentation Build

Service/daemon wrapper. Supports Windows, Linux (systemd) and macOS.

Where we install systemd units and why

The Challenge

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/

Our Approach

This library detects the correct systemd unit directory at runtime using the following strategy:

  1. 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.

  2. pkg-config detection: We query pkg-config --variable=systemdsystemunitdir systemd to get the distribution's preferred location. This works on most modern systems that have systemd development packages installed.

  3. 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

Caveats and Best Practices

⚠️ This isn't the ideal approach for packaged software.

If you're creating distribution packages (.deb, .rpm, etc.), you should:

  • For Debian/Ubuntu: Use dh_installsystemd or 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

Usage

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 register

Why Default to System Units?

We 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_UNITDIR if you need user units

Dependencies

~2–12MB
~102K SLoC