1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
extern crate libsystemd;
use libsystemd::daemon::{self, NotifyState};
use std::thread;
/*
```
[Service]
WatchdogSec=1s
ExecStart=/home/user/libsystemd-rs/target/debug/examples/watchdog
```
cargo build --example watchdog ; systemctl start --wait --user watchdog; systemctl status --user watchdog
*/
fn main() {
if !daemon::booted() {
println!("Not running systemd, early exit.");
return;
};
let timeout = daemon::watchdog_enabled(true).expect("watchdog disabled");
for i in 0..20 {
let _sent = daemon::notify(false, &[NotifyState::Watchdog]).expect("notify failed");
println!("Notification #{} sent...", i);
thread::sleep(timeout / 2);
}
println!("Blocking forever!");
thread::park();
}
|