5 releases

0.1.5 Feb 22, 2022
0.1.4 Jan 3, 2022
0.1.3 Dec 28, 2021
0.1.1 Jul 25, 2021
0.1.0 Jul 25, 2021

#940 in Filesystem

Custom license

9KB
175 lines

Daemon Ctrl

  • auto restart
  • request restart by file system

Usage

main

use core::time::Duration;
use daemon_ctrl::{ctrl, WatchConfig};

const CTRL_FILE: &str = "a/a/a/a";

fn main() {
    let mut cfg = WatchConfig::new();
    cfg.auto_restart(true);
    cfg.set_ctrl_file(String::from(CTRL_FILE)).unwrap();

    if let Ok(is_parent) = ctrl(cfg) {
        if is_parent {
            println!("into daemon.");
            std::process::exit(0);
        }
    } else {
        println!("not support");
    }

    // your program
}

request restart by file system

use daemon_ctrl::Control;

const CTRL_FILE: &str = "a/a/a/a";

fn main() {
    let mut ctrl = Control::read(CTRL_FILE);
    println!("now: {:?}", ctrl);
    ctrl.reboot = true;
    ctrl.save(CTRL_FILE);
}

Dependencies

~0.8–1.8MB
~38K SLoC