receipt rework and discovery rework

This commit is contained in:
John Smith
2022-05-28 10:07:57 -04:00
parent d80a81e460
commit b6e568f664
23 changed files with 817 additions and 431 deletions
+20 -2
View File
@@ -6,6 +6,7 @@ use async_std::task;
use clap::ArgMatches;
use signal_hook::consts::signal::*;
use signal_hook_async_std::Signals;
use std::io::Read;
async fn handle_signals(mut signals: Signals) {
while let Some(signal) = signals.next().await {
@@ -26,8 +27,25 @@ pub fn run_daemon(settings: Settings, _matches: ArgMatches) -> Result<(), String
let daemon = {
let mut daemon = daemonize::Daemonize::new();
let s = settings.read();
if let Some(pid_file) = &s.daemon.pid_file {
daemon = daemon.pid_file(pid_file); //.chown_pid_file(true);
if let Some(pid_file) = s.daemon.pid_file.clone() {
daemon = daemon.pid_file(pid_file.clone()); //.chown_pid_file(true);
daemon = daemon.exit_action(move || {
// wait for pid file to exist before exiting parent
let pid_path = std::path::Path::new(&pid_file);
loop {
if let Ok(mut f) = std::fs::File::open(pid_path) {
let mut s = String::new();
if f.read_to_string(&mut s).is_ok()
&& !s.is_empty()
&& s.parse::<u32>().is_ok()
{
println!("pidfile found");
break;
}
}
std::thread::sleep(std::time::Duration::from_millis(100));
}
})
}
if let Some(chroot) = &s.daemon.chroot {
daemon = daemon.chroot(chroot);