daemon_ctrl

Crates.iodaemon_ctrl
lib.rsdaemon_ctrl
version0.1.5
sourcesrc
created_at2021-07-25 04:31:37.864517
updated_at2022-02-22 01:47:16.891301
descriptiondaemon program by sub-process
homepage
repositoryhttps://github.com/rise0chen/daemon_ctrl.git
max_upload_size
id426973
size24,160
Rise Chen (rise0chen)

documentation

README

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);
}
Commit count: 6

cargo fmt