| Crates.io | dmon |
| lib.rs | dmon |
| version | 0.2.1 |
| created_at | 2025-07-26 07:37:31.133951+00 |
| updated_at | 2025-07-27 05:03:59.778171+00 |
| description | A library for building daemon processes. |
| homepage | |
| repository | https://github.com/genekoval/dmon-rs |
| max_upload_size | |
| id | 1768889 |
| size | 50,573 |
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.
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();
}