implem_command #9
3 changed files with 43 additions and 2 deletions
|
@ -23,6 +23,10 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
|
||||||
// case where command is run once.
|
// case where command is run once.
|
||||||
return misc::run_verbose(sv.sent_signal(b"o"), true, verbose, svwait_var, sv);
|
return misc::run_verbose(sv.sent_signal(b"o"), true, verbose, svwait_var, sv);
|
||||||
},
|
},
|
||||||
|
"p" => {
|
||||||
|
// case where it's the pause command which is entered.
|
||||||
|
return misc::pause_verbose(sv.sent_signal(b"p"), true, verbose, svwait_var, sv);
|
||||||
|
}
|
||||||
other => {
|
other => {
|
||||||
println!("Error, command {} not implemented.", other); // TODO : Put the real error
|
println!("Error, command {} not implemented.", other); // TODO : Put the real error
|
||||||
// message.
|
// message.
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub fn print_status(mut sv: status_obj::StatusObj) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn run_verbose(sent_signal: bool, state: bool, verbose: i8, svwait_var: i32, mut sv: status_obj::StatusObj) -> i32 {
|
pub fn run_verbose(sent_signal: bool, expected: bool, verbose: i8, svwait_var: i32, mut sv: status_obj::StatusObj) -> i32 {
|
||||||
// if the state is true, wait for the service to run.
|
// if the state is true, wait for the service to run.
|
||||||
// If the state is false, wait for the service to down.
|
// If the state is false, wait for the service to down.
|
||||||
if sent_signal && verbose == 1 {
|
if sent_signal && verbose == 1 {
|
||||||
|
@ -34,7 +34,36 @@ pub fn run_verbose(sent_signal: bool, state: bool, verbose: i8, svwait_var: i32,
|
||||||
if status == 1 {
|
if status == 1 {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if sv.is_up() == state {
|
if sv.is_up() == expected {
|
||||||
|
println!("ok: {}", sv.get_status_string());
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if time_wait >= svwait_var {
|
||||||
|
println!("timeout: {}", sv.get_status_string());
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
time_wait += 1;
|
||||||
|
sleep(Duration::from_secs(1));
|
||||||
|
}
|
||||||
|
} else if sent_signal && verbose == 0 {
|
||||||
|
return 0
|
||||||
|
} else {
|
||||||
|
// Case sent_signal != true.
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pause_verbose(sent_signal: bool, expected: bool, verbose: i8, svwait_var: i32, mut sv: status_obj::StatusObj) -> i32 {
|
||||||
|
// if the state is true, wait for the service to pause.
|
||||||
|
// if the state is false, wait for the service to continue.
|
||||||
|
if sent_signal && verbose == 1 {
|
||||||
|
let mut time_wait = 0;
|
||||||
|
loop {
|
||||||
|
let status = sv.update_status();
|
||||||
|
if status == 1 {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if sv.is_paused() == expected {
|
||||||
println!("ok: {}", sv.get_status_string());
|
println!("ok: {}", sv.get_status_string());
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -241,6 +241,14 @@ impl StatusObj {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_paused(&mut self) -> bool {
|
||||||
|
if self.pause_run == true {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_name(&mut self) -> String {
|
pub fn get_name(&mut self) -> String {
|
||||||
return self.svname.clone();
|
return self.svname.clone();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue