fixed dead prc service checking bug

pull/9/head
prplV 2024-09-23 14:14:26 +03:00
parent 0ab30aaee3
commit 3d73dba912
4 changed files with 15 additions and 13 deletions

View File

@ -46,7 +46,7 @@
"src": "/home/vladislav/web/",
"triggers": {
"onDelete": "hold",
"onChange": "stop"
"onChange": "stay"
}
}
],
@ -57,7 +57,7 @@
"triggers": {
"wait": 5,
"delay": 1,
"onLost": "hold"
"onLost": "stop"
}
},
{

View File

@ -38,7 +38,6 @@ pub async fn file_handler(
}
"stop" => {
if is_active(name).await {
// todo: new signal and full termination
tx.send(1).await.unwrap();
}
return Err(CustomError::Fatal);

View File

@ -16,15 +16,16 @@ pub async fn service_handler(
if check_service(&serv.hostname, &serv.port).await.is_err() {
if !is_active(name).await || is_frozen(name).await {
return Err(CustomError::Fatal);
} else {
println!("{} is active and non-frozen", name);
}
error!(
"Service {}:{} is unreachable for process {}",
&serv.hostname, &serv.port, &name
);
match serv.triggers.on_lost.as_str() {
"stay" => {}
"stay" => {
tx.send(4).await.unwrap();
continue;
}
"stop" => {
if looped_service_connecting(name, serv).await.is_err() {
tx.send(5).await.unwrap();

View File

@ -32,6 +32,7 @@ pub async fn run_daemons(
}
let watchers_clone: Arc<tokio::sync::Mutex<Vec<Inotify>>> =
Arc::new(tokio::sync::Mutex::new(watchers));
loop {
let run_hand = running_handler(proc.clone(), tx.clone(), watchers_clone.clone());
tokio::select! {
@ -41,7 +42,7 @@ pub async fn run_daemons(
// 1 - File-dependency handling error -> terminating (after waiting)
1 => {
if is_active(&proc.name).await {
error!("Dependency handling error: Terminating {} process ..." , &proc.name);
error!("File-dependency handling error: Terminating {} process ..." , &proc.name);
terminate_process(&proc.name).await;
tokio::time::sleep(Duration::from_millis(100)).await;
}
@ -50,7 +51,7 @@ pub async fn run_daemons(
// 2 - File-dependency handling error -> holding (after waiting)
2 => {
if !is_frozen(&proc.name).await {
error!("Dependency handling error: Freezing {} process ..." , &proc.name);
error!("File-dependency handling error: Freezing {} process ..." , &proc.name);
freeze_process(&proc.name).await;
tokio::time::sleep(Duration::from_millis(100)).await;
}
@ -62,7 +63,7 @@ pub async fn run_daemons(
},
// 4 - Timeout of waiting service-dependency -> staying (after waiting)
4 => {
warn!("Timeout of waiting service-dependency: Ignoring on {} process ..." , &proc.name);
// warn!("Timeout of waiting service-dependency: Ignoring on {} process ..." , &proc.name);
tokio::time::sleep(Duration::from_millis(100)).await;
},
// 5 - Timeout of waiting service-dependency -> terminating (after waiting)
@ -70,16 +71,16 @@ pub async fn run_daemons(
if is_active(&proc.name).await {
error!("Timeout of waiting service-dependency: Terminating {} process ..." , &proc.name);
terminate_process(&proc.name).await;
tokio::time::sleep(Duration::from_millis(100)).await;
tokio::time::sleep(Duration::from_millis(1000)).await;
}
// break;
},
// 6 - Timeout of waiting service-dependency -> holding (after waiting)
6 => {
// println!("holding {}-{}", proc.name, is_active(&proc.name).await);
if !is_frozen(&proc.name).await {
error!("Timeout of waiting service-dependency: Freezing {} process ..." , &proc.name);
freeze_process(&proc.name).await;
tokio::time::sleep(Duration::from_millis(100)).await;
tokio::time::sleep(Duration::from_secs(1)).await;
}
},
// // 7 - File-dependency change -> terminating (after check)
@ -97,6 +98,7 @@ pub async fn run_daemons(
},
// // 9 - File-dependency change -> staying (after check)
9 => {
// no need to trash logs
warn!("File-dependency warning (file changed). Ignoring event on {} process...", &proc.name);
tokio::time::sleep(Duration::from_millis(100)).await;
},
@ -119,7 +121,7 @@ pub async fn run_daemons(
// },
// 101 - Impermissible trigger values in JSON
101 => {
error!("Impermissible trigger values in JSON");
error!("Impermissible trigger values in JSON in {}'s block. Killing thread...", proc.name);
if is_active(&proc.name).await {
terminate_process(&proc.name).await;
}