Expand description
§(System[d)aemon]
(System[d)aemon] provides building blocks for composing daemonized applications. A daemon is a long-running background process that typically runs without direct user interaction.
This crate is designed for async. If you need a synchronous solution, this is not the right fit, though the source code may serve as inspiration.
Daemons are typically tightly coupled to the underlying operating system. This crate provides thin abstractions for the following tasks:
- Logging/Tracing setup with syslog integration
- Configuration management (with feature-gated file formats or custom formats)
- Graceful shutdown
- Daemon reloading
- Watchdog interval querying and watchdog triggering
- Daemon lifecycle notifications
- Behavioral policies on errors (daemon logic returns an error, config failed to load, etc.)
- Customizable system integrations
§Design
This crate is OS-agnostic in the sense that all system-interfacing functionality is abstracted into a few traits. Types implementing these traits are called integrations, and integrations offered by this crate are feature-gated. Users can implement custom integrations if daemons require specialized behavior.
This crate relies heavily on async. It offers a runtime-agnostic variant as well as a Tokio variant, both feature-gated. Due to how features work, both flavors are not mutually exclusive, but Tokio types take precedence over the runtime-agnostic types in case both are defined.
As of now, the only supported integration is for systemd since it is the de-facto standard on most linux systems nowadays.
§Features
This crate relies heavily on conditional compilation depending on the users needs. Users must select the features they actually need, therefore this crates default feature does not enable anything.
The following features are available:
- systemd: Enables “systemd” integration on unix platforms.
- toml: Enables “toml” as daemon configuration file format.
- yaml: Enables “yaml” as daemon configuration file format.
- json: Enables “json” as daemon configuration file format.
- agnostic: Uses runtime agnostic async crates.
- tokio: Uses tokio async crates. Takes precedence over agnostic
§LLM usage disclaimer
LLM usage is a controversial topic in the open source scene (for many good reasons). Neither the implementation nor tests were touched by an LLM because I as an author have the responsibility to understand how my published code works. The easiest way to ensure this is by writing it by hand.
Documentation however was streamlined using Claude Sonnet 4.6 via GitHub Copilot since I have a mild form of dyslexia and LLMs can be quite handy when it comes to improving/correcting plain text.
§Additional Notes
This crate started as a simple wrapper around systemd. That is the reason behind the funky name of this project.
Outside of the documentation its simply written as systemdaemon.
If you want to see more integrations for other init systems and/or operating systems, feel free to open a PR. Be aware that if such a PR gets merged, you are becoming effectively a maintainer of this crate and you are responsible for the PRs contents.
Structs§
- Daemon
- Daemon object encapsulating handler functions.
- Service
Config - Holds a service’s active configuration and distributes updates to all registered receivers.
Enums§
- Reload
Policy - Controls daemon behavior when configuration reloading fails.
- Restart
Policy - Controls when a service is restarted after its
Service::runmethod returns.
Traits§
- Config
Format - Defines configuration file formats.
- Logger
- Configures logging/tracing facilities of a system integration.
- Notify
- Sends daemon lifecycle notifications to the operating system.
- Reload
- Waits for a global reload signal.
- Service
- A long-running async task managed by the daemon.
- Shutdown
- Waits for a global shutdown signal.
- Watchdog
- Queries and triggers watchdog.