Compare commits

..

2 Commits

Author SHA1 Message Date
prplV 3d73dba912 fixed dead prc service checking bug 2024-09-23 14:14:26 +03:00
prplV 0ab30aaee3 sending signal to dead reader fixed 2024-09-23 11:06:53 +03:00
5 changed files with 40 additions and 31 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
/target
.idea
Dockerfile
Dockerfile
Cargo.lock

View File

@ -1,5 +1,5 @@
{
"dateOfCreation": "1721381809101",
"dateOfCreation": "1721381809103",
"processes": [
{
"name": "web-server",
@ -30,7 +30,7 @@
"triggers": {
"wait": 6,
"delay": 1,
"onLost": "stop"
"onLost": "hold"
}
}
]
@ -46,7 +46,7 @@
"src": "/home/vladislav/web/",
"triggers": {
"onDelete": "hold",
"onChange": "restart"
"onChange": "stay"
}
}
],
@ -66,7 +66,7 @@
"triggers": {
"wait": 6,
"delay": 2,
"onLost": "hold"
"onLost": "stop"
}
}
]

View File

@ -22,11 +22,14 @@ pub async fn service_handler(
&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();
tokio::time::sleep(Duration::from_millis(400)).await;
tokio::task::yield_now().await;
return Err(CustomError::Fatal);
}
}
@ -36,7 +39,7 @@ pub async fn service_handler(
// }
if looped_service_connecting(name, serv).await.is_err() {
tx.send(6).await.unwrap();
tokio::time::sleep(Duration::from_millis(400)).await;
tokio::task::yield_now().await;
return Err(CustomError::Fatal);
}
}
@ -48,12 +51,10 @@ pub async fn service_handler(
}
}
tokio::time::sleep(Duration::from_millis(100)).await;
tokio::task::yield_now().await;
Ok(())
}
async fn looped_service_connecting(name: &str, serv: &Services) -> Result<(), CustomError> {
let mut counter = 0;
if serv.triggers.wait == 0 {
loop {
tokio::time::sleep(Duration::from_secs(serv.triggers.delay.into())).await;
@ -80,9 +81,8 @@ async fn looped_service_connecting(name: &str, serv: &Services) -> Result<(), Cu
let start = Instant::now();
while start.elapsed().as_secs() < serv.triggers.wait.into() {
tokio::time::sleep(Duration::from_secs(serv.triggers.delay.into())).await;
counter += 1;
warn!(
"{counter} Attempting to connect from {} process to {}:{}",
"Attempting to connect from {} process to {}:{}",
&name, &serv.hostname, &serv.port
);
match check_service(&serv.hostname, &serv.port).await {

View File

@ -69,7 +69,7 @@ impl SigPostProcessing for Sig {
if let Some(_) = self.signal.recv().await {
log::info!("Got {} signal", self.sig_type);
for prc in self.senders.clone().iter() {
prc.send(111).await.unwrap();
let _ = prc.send(111).await;
}
}
Ok(())

View File

@ -32,7 +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! {
@ -42,16 +42,16 @@ 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;
}
// break;
return;
},
// 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;
}
@ -59,26 +59,28 @@ pub async fn run_daemons(
// 3 - Running process error
3 => {
error!("Error due to starting {} process", &proc.name);
break;
},
// 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)
5 => {
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)
@ -86,6 +88,7 @@ pub async fn run_daemons(
error!("File-dependency warning (file changed). Terminating {} process...", &proc.name);
terminate_process(&proc.name).await;
tokio::time::sleep(Duration::from_millis(100)).await;
return;
},
// // 8 - File-dependency change -> restarting (after check)
8 => {
@ -95,26 +98,30 @@ 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;
},
// 10 - Process unfreaze call via file handler
10 => {
// 10 - Process unfreaze call via file handler (or service handler)
10 | 11 => {
if is_frozen(&proc.name).await {
warn!("Unfreezing process {} call...", &proc.name);
unfreeze_process(&proc.name).await;
}
tokio::time::sleep(Duration::from_millis(100)).await;
},
// 11 - Process unfreaze call via service handler
11 => {
if is_frozen(&proc.name).await {
warn!("Unfreezing process {} call...", &proc.name);
unfreeze_process(&proc.name).await;
}
},
// 11 => {
// if is_frozen(&proc.name).await {
// warn!("Unfreezing process {} call...", &proc.name);
// unfreeze_process(&proc.name).await;
// }
// tokio::time::sleep(Duration::from_millis(100)).await;
// },
// 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;
}
@ -138,8 +145,9 @@ pub async fn run_daemons(
}
},
}
// tokio::task::yield_now().await;
tokio::task::yield_now().await;
}
tokio::task::yield_now().await;
}
// check process status daemon
pub async fn running_handler(