daemon: rename method, endless loop, bail on exec error
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
d7c6ad60dd
commit
06c9059dac
|
@ -305,30 +305,34 @@ 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) {
|
||||||
if text.trim().trim_start() != "reloading" {
|
Ok(text) => text,
|
||||||
return Ok(());
|
Err(err) => bail!("output of 'systemctl is-active' not valid UTF-8 - {}", err),
|
||||||
}
|
},
|
||||||
}
|
Err(err) => bail!("executing 'systemctl is-active' failed - {}", err),
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
if text.trim().trim_start() != "reloading" {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
tokio::time::delay_for(std::time::Duration::new(5, 0)).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[link(name = "systemd")]
|
#[link(name = "systemd")]
|
||||||
|
|
Loading…
Reference in New Issue