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::path::Path;
|
||||||
use std::env::set_current_dir;
|
use std::env::set_current_dir;
|
||||||
|
|
||||||
pub fn execute(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, services: Vec<String>){
|
fn sent_signal(exit_code: i32, svwait_var: i32, verbose: i8, command: &str, sv: String) -> i32 {
|
||||||
// TODO: Return the exec code.
|
|
||||||
|
// 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");
|
println!("execute in exec");
|
||||||
dbg!(svdir_var.clone());
|
dbg!(svdir_var.clone());
|
||||||
dbg!(svwait_var);
|
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);
|
let path_to_sv = Path::new(&path);
|
||||||
|
|
||||||
if set_current_dir(path_to_sv).is_ok() {
|
if set_current_dir(path_to_sv).is_ok() {
|
||||||
println!("Set path okay.");
|
// Call the change in the service.
|
||||||
// TODO: make a function which do what's next.
|
exit_code = sent_signal(exit_code, svwait_var, verbose, command, sv);
|
||||||
// It will be called, sent_signal, will return 0 if no error, and 1 if an error.
|
|
||||||
} else {
|
} else {
|
||||||
println!("fail: {}: unable to change to service directory: file does not exist", sv);
|
println!("fail: {}: unable to change to service directory: file does not exist", sv);
|
||||||
if exit_code < 99 {
|
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;
|
let mut verbose: i8 = 0;
|
||||||
|
|
||||||
//dbg!(svdir_var);
|
|
||||||
//dbg!(svwait_var);
|
|
||||||
|
|
||||||
|
|
||||||
// run the parser
|
// run the parser
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
|
@ -46,7 +42,6 @@ fn main() {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
if val == "-v" {
|
if val == "-v" {
|
||||||
verbose = 1;
|
verbose = 1;
|
||||||
//dbg!(verbose);
|
|
||||||
}
|
}
|
||||||
else if val == "-w" {
|
else if val == "-w" {
|
||||||
i = 3;
|
i = 3;
|
||||||
|
@ -70,25 +65,25 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if i == 1 {
|
else if i == 1 {
|
||||||
|
// Set the command as first arguments.
|
||||||
command = val;
|
command = val;
|
||||||
//dbg!(command);
|
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
else if i == 2 {
|
else if i == 2 {
|
||||||
// case services to control.
|
// add services to control.
|
||||||
//dbg!(val);
|
|
||||||
services.push(val.to_string());
|
services.push(val.to_string());
|
||||||
}
|
}
|
||||||
else if i == 3 {
|
else if i == 3 {
|
||||||
|
// change svwait after flag -w
|
||||||
svwait_var = match val.parse::<i32>() {
|
svwait_var = match val.parse::<i32>() {
|
||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
Err(..) => svwait_var,
|
Err(..) => svwait_var,
|
||||||
};
|
};
|
||||||
//dbg!(svwait_var);
|
|
||||||
i = 0;
|
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