add execution of the check script when it is, and some code optimisations.
This commit is contained in:
parent
cb8768b6f5
commit
486820f096
3 changed files with 44 additions and 7 deletions
|
@ -31,7 +31,7 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
if time_wait >= svwait_var {
|
if time_wait >= svwait_var {
|
||||||
println!("fail: {}: timeout", sv.get_name());
|
println!("timeout: {}", sv.get_status_string());
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
if time_wait >= svwait_var {
|
if time_wait >= svwait_var {
|
||||||
println!("fail: {}: timeout", sv.get_name());
|
println!("timeout: {}", sv.get_status_string());
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,11 +75,8 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
// sent the proper signal to supervise/control
|
|
||||||
//
|
|
||||||
// if verbose = 1, wait for the service to reach the proper state or timeout.
|
|
||||||
println!("Error, command not implemented.");
|
println!("Error, command not implemented.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ use std::io::prelude::*;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct StatusObj {
|
pub struct StatusObj {
|
||||||
svname: String, // Service name
|
svname: String, // Service name
|
||||||
|
@ -230,6 +231,13 @@ impl StatusObj {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_up(&mut self) -> bool {
|
pub fn is_up(&mut self) -> bool {
|
||||||
|
let check = fs::File::open("check");
|
||||||
|
match check {
|
||||||
|
Ok(file) => {
|
||||||
|
return misc::test_check(file, self.run_finish)
|
||||||
|
},
|
||||||
|
Err(..) => {},
|
||||||
|
};
|
||||||
return self.run_finish;
|
return self.run_finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,10 @@ use tokio::net::unix::pipe;
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
|
|
||||||
|
use std::fs::File;
|
||||||
|
use std::process::Command;
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
|
||||||
pub fn make_pause_run(pr_int: u8) -> bool {
|
pub fn make_pause_run(pr_int: u8) -> bool {
|
||||||
if pr_int == 0 {
|
if pr_int == 0 {
|
||||||
return false // run
|
return false // run
|
||||||
|
@ -131,3 +135,31 @@ pub fn sent_signal(signal: &[u8]) -> bool {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn test_check(file: File, run_finish: bool) -> bool {
|
||||||
|
// Check the permission, and return the result of check
|
||||||
|
let meta = file.metadata();
|
||||||
|
match meta {
|
||||||
|
Ok(m) => {
|
||||||
|
let permissions = m.permissions();
|
||||||
|
//println!("permissions: {:o}", permissions.mode() & 0o100700);
|
||||||
|
if permissions.mode() & 0o100700 == 0o100700 {
|
||||||
|
// Execute script
|
||||||
|
let mut command = Command::new("sh");
|
||||||
|
let status = command.arg("check").status();
|
||||||
|
match status {
|
||||||
|
Ok(s) => {
|
||||||
|
if s.success() {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(..) => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(..) => {},
|
||||||
|
};
|
||||||
|
return run_finish;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue