daemon: rename method, endless loop, bail on exec error

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2020-11-11 09:55:36 +01:00
parent d7c6ad60dd
commit 06c9059dac
1 changed files with 17 additions and 13 deletions

View File

@ -305,31 +305,35 @@ where
// FIXME: this is a hack, replace with sd_notify_barrier when available // FIXME: this is a hack, replace with sd_notify_barrier when available
if server::is_reload_request() { if server::is_reload_request() {
check_service_is_active(service_name).await?; wait_service_is_active(service_name).await?;
} }
log::info!("daemon shut down..."); log::info!("daemon shut down...");
Ok(()) Ok(())
} }
pub async fn check_service_is_active(service: &str) -> Result<(), Error> { // hack, do not use if unsure!
for _ in 0..5 { async fn wait_service_is_active(service: &str) -> Result<(), Error> {
tokio::time::delay_for(std::time::Duration::new(5, 0)).await; tokio::time::delay_for(std::time::Duration::new(1, 0)).await;
if let Ok(output) = tokio::process::Command::new("systemctl") loop {
let text = match tokio::process::Command::new("systemctl")
.args(&["is-active", service]) .args(&["is-active", service])
.output() .output()
.await .await
{ {
if let Ok(text) = String::from_utf8(output.stdout) { Ok(output) => match String::from_utf8(output.stdout) {
Ok(text) => text,
Err(err) => bail!("output of 'systemctl is-active' not valid UTF-8 - {}", err),
},
Err(err) => bail!("executing 'systemctl is-active' failed - {}", err),
};
if text.trim().trim_start() != "reloading" { if text.trim().trim_start() != "reloading" {
return Ok(()); return Ok(());
} }
tokio::time::delay_for(std::time::Duration::new(5, 0)).await;
} }
} }
}
Ok(())
}
#[link(name = "systemd")] #[link(name = "systemd")]
extern "C" { extern "C" {