dmon 0.2.0

A library for building daemon processes.
Documentation
  • Coverage
  • 88.89%
    16 out of 18 items documented8 out of 14 items with examples
  • Size
  • Source code size: 44.34 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.94 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 20s Average build duration of successful builds.
  • all releases: 19s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • genekoval/dmon-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • genekoval

dmon

A library for building daemon processes.

In addition to forking the process, dmon allows for configuring common aspects of daemons, such as dropping privileges and redirecting standard streams.

Example

use dmon::user::Privileges
use std::path::PathBuf;

#[derive(Default)]
struct Config {
    daemon: bool,
    user: Option<Privileges>,
    pidfile: Option<PathBuf>,
}

impl Config {
    fn parse() -> Self {
        // Read command-line arguments or a config file...
        Default::default()
    }
}

fn main() {
    let config = Config::parse();

    let mut parent = if config.daemon {
        dmon::options()
            .user(config.user)
            .pidfile(config.pidfile)
            .working_directory(Some(
                format!("/var/lib/{}", env!("CARGO_PKG_NAME"))
            ))
            .stdout(Some("stdout.log"))
            .stderr(Some("stderr.log"))
            .daemonize();
    } else {
        Default::default()
    };

    // Perform additional setup such as starting an async runtime,
    // listening on a port, or creating some files.

    // Tell the original process and the user that the daemon
    // started successfully.
    parent.success().unwrap();
}