#daemon-process #unix #daemon #system #user-group #run #unix-like

daemonize

Library to enable your code run as a daemon process on Unix-like systems

14 releases

Uses old Rust 2015

0.5.0 Feb 25, 2023
0.4.1 Mar 27, 2019
0.3.0 Apr 7, 2018
0.2.3 Aug 29, 2016
0.1.0 Dec 25, 2015

#8 in Unix APIs

Download history 17156/week @ 2024-06-30 17883/week @ 2024-07-07 19655/week @ 2024-07-14 20549/week @ 2024-07-21 22755/week @ 2024-07-28 20278/week @ 2024-08-04 21174/week @ 2024-08-11 18846/week @ 2024-08-18 20055/week @ 2024-08-25 32536/week @ 2024-09-01 39647/week @ 2024-09-08 46810/week @ 2024-09-15 50407/week @ 2024-09-22 46161/week @ 2024-09-29 27807/week @ 2024-10-06 29488/week @ 2024-10-13

158,489 downloads per month
Used in 138 crates (108 directly)

MIT/Apache

27KB
600 lines

daemonize Build Status Latest Version docs

daemonize is a library for writing system daemons. Inspired by the Python library thesharp/daemonize.

Usage example:

extern crate daemonize;

use std::fs::File;

use daemonize::Daemonize;

fn main() {
    let stdout = File::create("/tmp/daemon.out").unwrap();
    let stderr = File::create("/tmp/daemon.err").unwrap();

    let daemonize = Daemonize::new()
        .pid_file("/tmp/test.pid") // Every method except `new` and `start`
        .chown_pid_file(true)      // is optional, see `Daemonize` documentation
        .working_directory("/tmp") // for default behaviour.
        .user("nobody")
        .group("daemon") // Group name
        .group(2)        // or group id.
        .umask(0o777)    // Set umask, `0o027` by default.
        .stdout(stdout)  // Redirect stdout to `/tmp/daemon.out`.
        .stderr(stderr)  // Redirect stderr to `/tmp/daemon.err`.
        .privileged_action(|| "Executed before drop privileges");

    match daemonize.start() {
        Ok(_) => println!("Success, daemonized"),
        Err(e) => eprintln!("Error, {}", e),
    }
}

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~44KB