1daemonize [![Build Status](https://travis-ci.org/knsd/daemonize.svg?branch=master)](https://travis-ci.org/knsd/daemonize) [![Latest Version](https://img.shields.io/crates/v/daemonize.svg)](https://crates.io/crates/daemonize/) [![docs](https://docs.rs/daemonize/badge.svg)](https://docs.rs/daemonize)
2=========
3
4
5daemonize is a library for writing system daemons. Inspired by the Python library [thesharp/daemonize](https://github.com/thesharp/daemonize).
6
7Usage example:
8
9```rust
10extern crate daemonize;
11
12use std::fs::File;
13
14use daemonize::Daemonize;
15
16fn main() {
17    let stdout = File::create("/tmp/daemon.out").unwrap();
18    let stderr = File::create("/tmp/daemon.err").unwrap();
19
20    let daemonize = Daemonize::new()
21        .pid_file("/tmp/test.pid") // Every method except `new` and `start`
22        .chown_pid_file(true)      // is optional, see `Daemonize` documentation
23        .working_directory("/tmp") // for default behaviour.
24        .user("nobody")
25        .group("daemon") // Group name
26        .group(2)        // or group id.
27        .umask(0o777)    // Set umask, `0o027` by default.
28        .stdout(stdout)  // Redirect stdout to `/tmp/daemon.out`.
29        .stderr(stderr)  // Redirect stderr to `/tmp/daemon.err`.
30        .privileged_action(|| "Executed before drop privileges");
31
32    match daemonize.start() {
33        Ok(_) => println!("Success, daemonized"),
34        Err(e) => eprintln!("Error, {}", e),
35    }
36}
37```
38
39### License
40
41Licensed under either of
42 * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
43 * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
44at your option.
45
46### Contribution
47
48Unless you explicitly state otherwise, any contribution intentionally submitted
49for inclusion in the work by you shall be dual licensed as above, without any
50additional terms or conditions.
51