parity-daemonize

Crates.ioparity-daemonize
lib.rsparity-daemonize
version0.3.0
sourcesrc
created_at2018-12-11 11:18:35.438688
updated_at2019-02-14 20:03:56.591129
descriptionA more advanced daemonizer
homepage
repositoryhttps://github.com/paritytech/parity-daemonize
max_upload_size
id101420
size56,971
Web3 Philosopher (seunlanlege)

documentation

https://docs.rs/parity-daemonize

README

Daemonize-rs Crates.io Released API docs Build Status Build Status

Example

extern crate parity_daemonize;

use parity_daemonize::daemonize;
use std::{thread, time, process, io};
use io::Write;

fn main() {
    match daemonize("pid_file.txt") {
        // we are now in the daemon, use this handle to detach from the parent process
        Ok(handle) => {
            let mut count = 0;
            loop {
                // the daemon's output is piped to the parent process' stdout
                println!("Count: {}", count);
                if count == 5 {
                    handle.detach_with_msg("count has reached 5, continuing in background");
                }
                thread::sleep(time::Duration::from_secs(1));
                count += 1;
            }
        }
        // the daemon or the parent process may receive this error,
        // just print it and exit
        Err(e) => {
            // if this is the daemon, this is piped to the parent's stderr
            eprintln!("{}", e);
            // don't forget to flush
            io::stderr().flush();
            process::exit(1);
        }
    }
}

License

This crate is distributed under the terms of GNU GENERAL PUBLIC LICENSE version 3.0.

See LICENSE for details.

Commit count: 32

cargo fmt