#[macro_use]
extern crate wei_log;
pub async fn start() -> Result<(), Box<dyn std::error::Error>> {
loop {
if wei_env::status() == "0" {
return Ok(());
}
let content = std::fs::read_to_string("./daemon.dat")?;
let map: serde_yaml::Value = serde_yaml::from_str(&content)?;
if let serde_yaml::Value::Mapping(m) = map.clone() {
for (k, _) in m {
let data = k.clone();
let name = data.as_str().expect("process is not string");
#[cfg(target_os = "windows")]
let name_exe = format!("{}.exe", name.clone());
#[cfg(target_os = "windows")]
let name_exe = name_exe.as_str();
if !std::path::Path::new(name_exe.clone()).exists() {
continue;
}
if !wei_run::is_process_running(name.clone()) {
info!("{} is not running", name);
wei_run::run_async(name, vec![])?;
}
}
}
tokio::time::sleep(tokio::time::Duration::from_secs(15)).await;
}
}