#daemonize #fork #system #daemons #group #default #temporary

cf-daemonize

A (hopefully temporary) fork of the daemonize crate

1 unstable release

Uses old Rust 2015

0.3.0 Mar 26, 2019

#3 in #daemons

MIT/Apache

22KB
477 lines

cf-daemonize

This project contains a fork of the daemonize crate, for use in Cloudflare's boringtun. We'd prefer to upstream the changes, but the original project appears to be inactive at the moment.

Unless you depend on the specific additional features of this fork, we recommend that you use the original daemonize crate.


lib.rs:

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

The respository is located at https://github.com/knsd/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),
    }
}

Dependencies

~81KB