#daemon #unix #daemonize

parity-daemonize

更高级的守护进程化工具

4个版本 (2个破坏性更新)

0.3.0 2019年2月14日
0.2.1 2019年2月14日
0.2.0 2019年2月4日
0.1.1 2018年12月18日
0.1.0 2018年12月11日

#10 in #daemonize

Download history 114/week @ 2024-04-01 63/week @ 2024-04-08 84/week @ 2024-04-15 95/week @ 2024-04-22 73/week @ 2024-04-29 82/week @ 2024-05-06 83/week @ 2024-05-13 86/week @ 2024-05-20 73/week @ 2024-05-27 67/week @ 2024-06-03 46/week @ 2024-06-10 129/week @ 2024-06-17 64/week @ 2024-06-24 21/week @ 2024-07-01 38/week @ 2024-07-08 126/week @ 2024-07-15

每月264次下载

GPL-3.0 许可证

20KB
376 代码行

Daemonize-rs Crates.io 已发布API文档 构建状态 构建状态

示例

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);
        }
    }
}

许可证

本软件包根据GNU通用公共许可证版本3.0的条款进行分发。

有关详细信息,请参阅LICENSE

依赖项

~0.7–1MB
~16K SLoC