dmon

Crates.iodmon
lib.rsdmon
version0.2.1
created_at2025-07-26 07:37:31.133951+00
updated_at2025-07-27 05:03:59.778171+00
descriptionA library for building daemon processes.
homepage
repositoryhttps://github.com/genekoval/dmon-rs
max_upload_size
id1768889
size50,573
Gene Koval (genekoval)

documentation

README

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();
}
Commit count: 0

cargo fmt