use std::{os::unix::process::CommandExt, process::Command};
use nix::unistd;
use tokio::signal::unix::{SignalKind, signal};
pub async fn wait_reload() {
let mut stream = signal(SignalKind::hangup()).expect("Failed to create SIGHUP signal stream");
stream.recv().await;
}
pub fn setup_process_detachment(command: &mut Command) {
unsafe {
command.pre_exec(|| {
unistd::setsid().map_err(std::io::Error::other)?;
#[cfg(target_os = "linux")]
{
use sd_notify::NotifyState;
let _ = sd_notify::notify(
false,
&[NotifyState::MainPid(std::process::id())],
);
}
Ok(())
});
}
}