add supervise/ok check, and correct return exit_code.
This commit is contained in:
parent
61ccac3415
commit
591afb7f7b
2 changed files with 30 additions and 25 deletions
|
@ -4,8 +4,26 @@ use std::fs;
|
|||
use std::path::Path;
|
||||
use std::env::set_current_dir;
|
||||
|
||||
pub fn execute(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, services: Vec<String>){
|
||||
// TODO: Return the exec code.
|
||||
fn sent_signal(exit_code: i32, svwait_var: i32, verbose: i8, command: &str, sv: String) -> i32 {
|
||||
|
||||
// Check if supervise/ok exist.
|
||||
let supervise_ok = Path::new("supervise/ok");
|
||||
if ! supervise_ok.exists() {
|
||||
println!("warning: {}: unable to open supervise/ok: file does not exist", sv.clone());
|
||||
if exit_code < 99 {
|
||||
return exit_code + 1;
|
||||
} else {
|
||||
return exit_code;
|
||||
}
|
||||
}
|
||||
// TODO
|
||||
// sent the proper signal to supervise/control
|
||||
//
|
||||
// if verbose = 1, wait for the service to reach the proper state or timeout.
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
pub fn execute(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, services: Vec<String>) -> i32{
|
||||
println!("execute in exec");
|
||||
dbg!(svdir_var.clone());
|
||||
dbg!(svwait_var);
|
||||
|
@ -35,9 +53,8 @@ pub fn execute(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, s
|
|||
let path_to_sv = Path::new(&path);
|
||||
|
||||
if set_current_dir(path_to_sv).is_ok() {
|
||||
println!("Set path okay.");
|
||||
// TODO: make a function which do what's next.
|
||||
// It will be called, sent_signal, will return 0 if no error, and 1 if an error.
|
||||
// Call the change in the service.
|
||||
exit_code = sent_signal(exit_code, svwait_var, verbose, command, sv);
|
||||
} else {
|
||||
println!("fail: {}: unable to change to service directory: file does not exist", sv);
|
||||
if exit_code < 99 {
|
||||
|
@ -45,15 +62,8 @@ pub fn execute(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, s
|
|||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
// 2. Check if supervise/ok exist
|
||||
//
|
||||
// if not, error => increase by one the exit code and print a beatifull message in Err
|
||||
// standard.
|
||||
//
|
||||
// if yes, sent the proper signal to supervise/control
|
||||
//
|
||||
// if verbose = 1, wait for the service to reach the proper state or timeout.
|
||||
}
|
||||
|
||||
return exit_code
|
||||
|
||||
}
|
||||
|
|
|
@ -26,10 +26,6 @@ fn main() {
|
|||
|
||||
let mut verbose: i8 = 0;
|
||||
|
||||
//dbg!(svdir_var);
|
||||
//dbg!(svwait_var);
|
||||
|
||||
|
||||
// run the parser
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
|
@ -46,7 +42,6 @@ fn main() {
|
|||
if i == 0 {
|
||||
if val == "-v" {
|
||||
verbose = 1;
|
||||
//dbg!(verbose);
|
||||
}
|
||||
else if val == "-w" {
|
||||
i = 3;
|
||||
|
@ -70,25 +65,25 @@ fn main() {
|
|||
}
|
||||
}
|
||||
else if i == 1 {
|
||||
// Set the command as first arguments.
|
||||
command = val;
|
||||
//dbg!(command);
|
||||
i += 1;
|
||||
}
|
||||
else if i == 2 {
|
||||
// case services to control.
|
||||
//dbg!(val);
|
||||
// add services to control.
|
||||
services.push(val.to_string());
|
||||
}
|
||||
else if i == 3 {
|
||||
// change svwait after flag -w
|
||||
svwait_var = match val.parse::<i32>() {
|
||||
Ok(val) => val,
|
||||
Err(..) => svwait_var,
|
||||
};
|
||||
//dbg!(svwait_var);
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
executor::execute(svdir_var, svwait_var, verbose, command, services);
|
||||
// Exit after all services are correctly executed.
|
||||
exit(executor::execute(svdir_var, svwait_var, verbose, command, services));
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue