Compare commits
No commits in common. "3d73dba912ecb92550121c2d3d6b8f770ae422a9" and "29d517e66e8958561291286e75d2067848765228" have entirely different histories.
3d73dba912
...
29d517e66e
|
|
@ -1,4 +1,3 @@
|
|||
/target
|
||||
.idea
|
||||
Dockerfile
|
||||
Cargo.lock
|
||||
Dockerfile
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"dateOfCreation": "1721381809103",
|
||||
"dateOfCreation": "1721381809101",
|
||||
"processes": [
|
||||
{
|
||||
"name": "web-server",
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
"triggers": {
|
||||
"wait": 6,
|
||||
"delay": 1,
|
||||
"onLost": "hold"
|
||||
"onLost": "stop"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
"src": "/home/vladislav/web/",
|
||||
"triggers": {
|
||||
"onDelete": "hold",
|
||||
"onChange": "stay"
|
||||
"onChange": "restart"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
|
@ -66,7 +66,7 @@
|
|||
"triggers": {
|
||||
"wait": 6,
|
||||
"delay": 2,
|
||||
"onLost": "stop"
|
||||
"onLost": "hold"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -22,14 +22,11 @@ pub async fn service_handler(
|
|||
&serv.hostname, &serv.port, &name
|
||||
);
|
||||
match serv.triggers.on_lost.as_str() {
|
||||
"stay" => {
|
||||
tx.send(4).await.unwrap();
|
||||
continue;
|
||||
}
|
||||
"stay" => {}
|
||||
"stop" => {
|
||||
if looped_service_connecting(name, serv).await.is_err() {
|
||||
tx.send(5).await.unwrap();
|
||||
tokio::task::yield_now().await;
|
||||
tokio::time::sleep(Duration::from_millis(400)).await;
|
||||
return Err(CustomError::Fatal);
|
||||
}
|
||||
}
|
||||
|
|
@ -39,7 +36,7 @@ pub async fn service_handler(
|
|||
// }
|
||||
if looped_service_connecting(name, serv).await.is_err() {
|
||||
tx.send(6).await.unwrap();
|
||||
tokio::task::yield_now().await;
|
||||
tokio::time::sleep(Duration::from_millis(400)).await;
|
||||
return Err(CustomError::Fatal);
|
||||
}
|
||||
}
|
||||
|
|
@ -51,10 +48,12 @@ 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;
|
||||
|
|
@ -81,8 +80,9 @@ 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!(
|
||||
"Attempting to connect from {} process to {}:{}",
|
||||
"{counter} Attempting to connect from {} process to {}:{}",
|
||||
&name, &serv.hostname, &serv.port
|
||||
);
|
||||
match check_service(&serv.hostname, &serv.port).await {
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
let _ = prc.send(111).await;
|
||||
prc.send(111).await.unwrap();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
44
src/utils.rs
44
src/utils.rs
|
|
@ -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!("File-dependency handling error: Terminating {} process ..." , &proc.name);
|
||||
error!("Dependency handling error: Terminating {} process ..." , &proc.name);
|
||||
terminate_process(&proc.name).await;
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
return;
|
||||
// break;
|
||||
},
|
||||
// 2 - File-dependency handling error -> holding (after waiting)
|
||||
2 => {
|
||||
if !is_frozen(&proc.name).await {
|
||||
error!("File-dependency handling error: Freezing {} process ..." , &proc.name);
|
||||
error!("Dependency handling error: Freezing {} process ..." , &proc.name);
|
||||
freeze_process(&proc.name).await;
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
|
|
@ -59,28 +59,26 @@ 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);
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
warn!("Timeout of waiting service-dependency: Ignoring on {} process ..." , &proc.name);
|
||||
},
|
||||
// 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(1000)).await;
|
||||
tokio::time::sleep(Duration::from_millis(100)).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_secs(1)).await;
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
},
|
||||
// // 7 - File-dependency change -> terminating (after check)
|
||||
|
|
@ -88,7 +86,6 @@ 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 => {
|
||||
|
|
@ -98,30 +95,26 @@ 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 (or service handler)
|
||||
10 | 11 => {
|
||||
// 10 - Process unfreaze call via file handler
|
||||
10 => {
|
||||
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;
|
||||
// }
|
||||
// tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
// },
|
||||
11 => {
|
||||
if is_frozen(&proc.name).await {
|
||||
warn!("Unfreezing process {} call...", &proc.name);
|
||||
unfreeze_process(&proc.name).await;
|
||||
}
|
||||
},
|
||||
// 101 - Impermissible trigger values in JSON
|
||||
101 => {
|
||||
error!("Impermissible trigger values in JSON in {}'s block. Killing thread...", proc.name);
|
||||
error!("Impermissible trigger values in JSON");
|
||||
if is_active(&proc.name).await {
|
||||
terminate_process(&proc.name).await;
|
||||
}
|
||||
|
|
@ -145,9 +138,8 @@ 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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue