little chngs + loop not to hide prcs

pull/9/head
prplV 2024-07-04 06:07:26 -04:00
parent 26f5a1f543
commit 38b9d77391
2 changed files with 39 additions and 36 deletions

View File

@ -17,8 +17,8 @@
"hostname" : "ya.ru",
"port" : 443,
"triggers" : {
"wait" : 12,
"delay" : 3
"wait" : 6,
"delay" : 1
}
}]
}
@ -33,10 +33,10 @@
"src" : "/home/vladislav/web/"
}],
"services" : [{
"hostname" : "localhost",
"port" : 8080,
"hostname" : "ya.ru",
"port" : 443,
"triggers" : {
"wait" : 21,
"wait" : 14,
"delay" : 1
}
}]

View File

@ -56,7 +56,7 @@ struct ServiceTriggers {
#[tokio::main]
async fn main() {
let processes = load_processes("settings.json");
let mut error_counter = 0;
// let mut error_counter = 0;
if processes.processes.len() == 0 {
eprintln!("Error: Processes list is null, runner-rs initialization is stopped");
@ -109,8 +109,9 @@ async fn run_daemons(
proc: &TrackingProcess,
tx: mpsc::Sender<u8>,
rx: &mut mpsc::Receiver<u8>
) {
)
{
loop {
let run_hand = running_handler(&proc.name, &proc.path, tx.clone());
let file_hand = file_handler(&proc.name,&proc.dependencies.files, tx.clone());
let serv_hand = service_handler(&proc.name, &proc.dependencies.services, tx.clone());
@ -122,15 +123,15 @@ async fn run_daemons(
_val = rx.recv() => {
match _val.unwrap() {
1 => {
terminate_process(&proc.name).await;
println!("Dependency handling error: Terminating {} process ..." , &proc.name);
terminate_process(&proc.name).await;
},
2 => {
println!("Error due to starting {} process", &proc.name);
},
3 => {
terminate_process(&proc.name).await;
println!("Timeout of waiting service-dependency: Terminating {} process ..." , &proc.name);
terminate_process(&proc.name).await;
},
_ => {},
}
@ -138,6 +139,8 @@ async fn run_daemons(
}
}
}
fn load_processes(json_filename: &str) -> Processes{
let read = fs::read_to_string(json_filename).expect(format!("Missing '{}' file. Cannot start runner", json_filename).as_str());
serde_json::from_str::<Processes>(&read).expect(format!("Parsing error in '{}' file. Cannot start runner", json_filename).as_str())
@ -174,7 +177,7 @@ async fn start_process(name: &str, path: &str, tx: mpsc::Sender<u8>) -> Result<(
// check process status daemon
async fn running_handler(name: &str, path: &str, tx: mpsc::Sender<u8>){
loop {
// println!("running daemon on {}", name);
println!("running daemon on {}", name);
let _ = Command::new("pidof")
.arg(name)
.output()
@ -194,7 +197,7 @@ async fn running_handler(name: &str, path: &str, tx: mpsc::Sender<u8>){
async fn file_handler(name: &str, files: &Vec<Files>, tx: mpsc::Sender<u8>) {
loop {
// println!("file daemon on {}", name);
println!("file daemon on {}", name);
if is_active(name) {
for file in files {
match check_file(&file.filename, &file.src) {
@ -220,8 +223,8 @@ fn check_file(filename: &str, path: &str) -> Result<(), CustomError> {
// ??
async fn service_handler(name: &str, services: &Vec<Services>, tx: mpsc::Sender<u8>) {
'main_loop: loop {
// println!("service daemon on {}", name);
loop {
println!("service daemon on {}", name);
if is_active(name) {
for serv in services {
match check_service(&serv.hostname, &serv.port) {