Compare commits
2 Commits
29d517e66e
...
3d73dba912
| Author | SHA1 | Date |
|---|---|---|
|
|
3d73dba912 | |
|
|
0ab30aaee3 |
|
|
@ -1,3 +1,4 @@
|
||||||
/target
|
/target
|
||||||
.idea
|
.idea
|
||||||
Dockerfile
|
Dockerfile
|
||||||
|
Cargo.lock
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"dateOfCreation": "1721381809101",
|
"dateOfCreation": "1721381809103",
|
||||||
"processes": [
|
"processes": [
|
||||||
{
|
{
|
||||||
"name": "web-server",
|
"name": "web-server",
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
"triggers": {
|
"triggers": {
|
||||||
"wait": 6,
|
"wait": 6,
|
||||||
"delay": 1,
|
"delay": 1,
|
||||||
"onLost": "stop"
|
"onLost": "hold"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -46,7 +46,7 @@
|
||||||
"src": "/home/vladislav/web/",
|
"src": "/home/vladislav/web/",
|
||||||
"triggers": {
|
"triggers": {
|
||||||
"onDelete": "hold",
|
"onDelete": "hold",
|
||||||
"onChange": "restart"
|
"onChange": "stay"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
@ -66,7 +66,7 @@
|
||||||
"triggers": {
|
"triggers": {
|
||||||
"wait": 6,
|
"wait": 6,
|
||||||
"delay": 2,
|
"delay": 2,
|
||||||
"onLost": "hold"
|
"onLost": "stop"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,14 @@ pub async fn service_handler(
|
||||||
&serv.hostname, &serv.port, &name
|
&serv.hostname, &serv.port, &name
|
||||||
);
|
);
|
||||||
match serv.triggers.on_lost.as_str() {
|
match serv.triggers.on_lost.as_str() {
|
||||||
"stay" => {}
|
"stay" => {
|
||||||
|
tx.send(4).await.unwrap();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
"stop" => {
|
"stop" => {
|
||||||
if looped_service_connecting(name, serv).await.is_err() {
|
if looped_service_connecting(name, serv).await.is_err() {
|
||||||
tx.send(5).await.unwrap();
|
tx.send(5).await.unwrap();
|
||||||
tokio::time::sleep(Duration::from_millis(400)).await;
|
tokio::task::yield_now().await;
|
||||||
return Err(CustomError::Fatal);
|
return Err(CustomError::Fatal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -36,7 +39,7 @@ pub async fn service_handler(
|
||||||
// }
|
// }
|
||||||
if looped_service_connecting(name, serv).await.is_err() {
|
if looped_service_connecting(name, serv).await.is_err() {
|
||||||
tx.send(6).await.unwrap();
|
tx.send(6).await.unwrap();
|
||||||
tokio::time::sleep(Duration::from_millis(400)).await;
|
tokio::task::yield_now().await;
|
||||||
return Err(CustomError::Fatal);
|
return Err(CustomError::Fatal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -48,12 +51,10 @@ pub async fn service_handler(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
tokio::task::yield_now().await;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn looped_service_connecting(name: &str, serv: &Services) -> Result<(), CustomError> {
|
async fn looped_service_connecting(name: &str, serv: &Services) -> Result<(), CustomError> {
|
||||||
let mut counter = 0;
|
|
||||||
if serv.triggers.wait == 0 {
|
if serv.triggers.wait == 0 {
|
||||||
loop {
|
loop {
|
||||||
tokio::time::sleep(Duration::from_secs(serv.triggers.delay.into())).await;
|
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();
|
let start = Instant::now();
|
||||||
while start.elapsed().as_secs() < serv.triggers.wait.into() {
|
while start.elapsed().as_secs() < serv.triggers.wait.into() {
|
||||||
tokio::time::sleep(Duration::from_secs(serv.triggers.delay.into())).await;
|
tokio::time::sleep(Duration::from_secs(serv.triggers.delay.into())).await;
|
||||||
counter += 1;
|
|
||||||
warn!(
|
warn!(
|
||||||
"{counter} Attempting to connect from {} process to {}:{}",
|
"Attempting to connect from {} process to {}:{}",
|
||||||
&name, &serv.hostname, &serv.port
|
&name, &serv.hostname, &serv.port
|
||||||
);
|
);
|
||||||
match check_service(&serv.hostname, &serv.port).await {
|
match check_service(&serv.hostname, &serv.port).await {
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ impl SigPostProcessing for Sig {
|
||||||
if let Some(_) = self.signal.recv().await {
|
if let Some(_) = self.signal.recv().await {
|
||||||
log::info!("Got {} signal", self.sig_type);
|
log::info!("Got {} signal", self.sig_type);
|
||||||
for prc in self.senders.clone().iter() {
|
for prc in self.senders.clone().iter() {
|
||||||
prc.send(111).await.unwrap();
|
let _ = prc.send(111).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
42
src/utils.rs
42
src/utils.rs
|
|
@ -42,16 +42,16 @@ pub async fn run_daemons(
|
||||||
// 1 - File-dependency handling error -> terminating (after waiting)
|
// 1 - File-dependency handling error -> terminating (after waiting)
|
||||||
1 => {
|
1 => {
|
||||||
if is_active(&proc.name).await {
|
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;
|
terminate_process(&proc.name).await;
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
}
|
}
|
||||||
// break;
|
return;
|
||||||
},
|
},
|
||||||
// 2 - File-dependency handling error -> holding (after waiting)
|
// 2 - File-dependency handling error -> holding (after waiting)
|
||||||
2 => {
|
2 => {
|
||||||
if !is_frozen(&proc.name).await {
|
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;
|
freeze_process(&proc.name).await;
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
}
|
}
|
||||||
|
|
@ -59,26 +59,28 @@ pub async fn run_daemons(
|
||||||
// 3 - Running process error
|
// 3 - Running process error
|
||||||
3 => {
|
3 => {
|
||||||
error!("Error due to starting {} process", &proc.name);
|
error!("Error due to starting {} process", &proc.name);
|
||||||
|
break;
|
||||||
},
|
},
|
||||||
// 4 - Timeout of waiting service-dependency -> staying (after waiting)
|
// 4 - Timeout of waiting service-dependency -> staying (after waiting)
|
||||||
4 => {
|
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 - Timeout of waiting service-dependency -> terminating (after waiting)
|
||||||
5 => {
|
5 => {
|
||||||
if is_active(&proc.name).await {
|
if is_active(&proc.name).await {
|
||||||
error!("Timeout of waiting service-dependency: Terminating {} process ..." , &proc.name);
|
error!("Timeout of waiting service-dependency: Terminating {} process ..." , &proc.name);
|
||||||
terminate_process(&proc.name).await;
|
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 - Timeout of waiting service-dependency -> holding (after waiting)
|
||||||
6 => {
|
6 => {
|
||||||
|
// println!("holding {}-{}", proc.name, is_active(&proc.name).await);
|
||||||
if !is_frozen(&proc.name).await {
|
if !is_frozen(&proc.name).await {
|
||||||
error!("Timeout of waiting service-dependency: Freezing {} process ..." , &proc.name);
|
error!("Timeout of waiting service-dependency: Freezing {} process ..." , &proc.name);
|
||||||
freeze_process(&proc.name).await;
|
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)
|
// // 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);
|
error!("File-dependency warning (file changed). Terminating {} process...", &proc.name);
|
||||||
terminate_process(&proc.name).await;
|
terminate_process(&proc.name).await;
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
|
return;
|
||||||
},
|
},
|
||||||
// // 8 - File-dependency change -> restarting (after check)
|
// // 8 - File-dependency change -> restarting (after check)
|
||||||
8 => {
|
8 => {
|
||||||
|
|
@ -95,26 +98,30 @@ pub async fn run_daemons(
|
||||||
},
|
},
|
||||||
// // 9 - File-dependency change -> staying (after check)
|
// // 9 - File-dependency change -> staying (after check)
|
||||||
9 => {
|
9 => {
|
||||||
|
// no need to trash logs
|
||||||
warn!("File-dependency warning (file changed). Ignoring event on {} process...", &proc.name);
|
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 - Process unfreaze call via file handler (or service handler)
|
||||||
10 => {
|
10 | 11 => {
|
||||||
if is_frozen(&proc.name).await {
|
if is_frozen(&proc.name).await {
|
||||||
warn!("Unfreezing process {} call...", &proc.name);
|
warn!("Unfreezing process {} call...", &proc.name);
|
||||||
unfreeze_process(&proc.name).await;
|
unfreeze_process(&proc.name).await;
|
||||||
}
|
}
|
||||||
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
},
|
},
|
||||||
// 11 - Process unfreaze call via service handler
|
// 11 - Process unfreaze call via service handler
|
||||||
11 => {
|
// 11 => {
|
||||||
if is_frozen(&proc.name).await {
|
// if is_frozen(&proc.name).await {
|
||||||
warn!("Unfreezing process {} call...", &proc.name);
|
// warn!("Unfreezing process {} call...", &proc.name);
|
||||||
unfreeze_process(&proc.name).await;
|
// unfreeze_process(&proc.name).await;
|
||||||
}
|
// }
|
||||||
},
|
// tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
|
// },
|
||||||
// 101 - Impermissible trigger values in JSON
|
// 101 - Impermissible trigger values in JSON
|
||||||
101 => {
|
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 {
|
if is_active(&proc.name).await {
|
||||||
terminate_process(&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
|
// check process status daemon
|
||||||
pub async fn running_handler(
|
pub async fn running_handler(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue