mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-17 04:18:07 +00:00
simplify config update notification (#683)
This commit is contained in:
@ -154,18 +154,14 @@ impl Config {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update(&mut self) -> Result<bool> {
|
pub async fn update(&mut self) -> Result<()> {
|
||||||
if self.fetch().await? {
|
if self.fetch().await? {
|
||||||
info!("config updated");
|
info!("config updated");
|
||||||
self.save().await?;
|
self.save().await?;
|
||||||
|
proxy::update(&self.data).await?;
|
||||||
|
self.notify().await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let notified = if proxy::update(&self.data).await? {
|
Ok(())
|
||||||
self.notify().await?;
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
Ok(notified)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,9 +72,8 @@ async fn restart_systemd() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update(data: &ConfigData) -> Result<bool> {
|
pub async fn update(data: &ConfigData) -> Result<()> {
|
||||||
let configs = build(data);
|
let configs = build(data);
|
||||||
let mut changed = false;
|
|
||||||
|
|
||||||
let mut config_dir = tokio::fs::read_dir(SYSTEMD_CONFIG_DIR).await?;
|
let mut config_dir = tokio::fs::read_dir(SYSTEMD_CONFIG_DIR).await?;
|
||||||
while let Some(entry) = config_dir.next().await {
|
while let Some(entry) = config_dir.next().await {
|
||||||
@ -107,7 +106,6 @@ pub async fn update(data: &ConfigData) -> Result<bool> {
|
|||||||
|
|
||||||
tokio::fs::write(&path, configs[&file_name].clone()).await?;
|
tokio::fs::write(&path, configs[&file_name].clone()).await?;
|
||||||
start_service(&file_name).await?;
|
start_service(&file_name).await?;
|
||||||
changed = true;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
info!("stopping proxy {}", file_name);
|
info!("stopping proxy {}", file_name);
|
||||||
@ -115,7 +113,6 @@ pub async fn update(data: &ConfigData) -> Result<bool> {
|
|||||||
tokio::fs::remove_file(&path).await?;
|
tokio::fs::remove_file(&path).await?;
|
||||||
stop_service(&file_name).await?;
|
stop_service(&file_name).await?;
|
||||||
restart_systemd().await?;
|
restart_systemd().await?;
|
||||||
changed = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,9 +122,8 @@ pub async fn update(data: &ConfigData) -> Result<bool> {
|
|||||||
info!("adding service {}", file_name);
|
info!("adding service {}", file_name);
|
||||||
tokio::fs::write(&path, content).await?;
|
tokio::fs::write(&path, content).await?;
|
||||||
start_service(&file_name).await?;
|
start_service(&file_name).await?;
|
||||||
changed = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(changed)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user