Compare commits
No commits in common. "92c5f4b3a11e90b72652c425c16e14a1306f36e5" and "d3fb3e8974cefb565f52ac9afc0699355aa6d90e" have entirely different histories.
92c5f4b3a1
...
d3fb3e8974
3 changed files with 20 additions and 41 deletions
|
@ -1,9 +1,8 @@
|
|||
[package]
|
||||
name = "sv"
|
||||
version = "0.2.0"
|
||||
edition = "2024"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.37.0", features = ["full"] }
|
||||
|
|
|
@ -8,6 +8,7 @@ use std::io::prelude::*;
|
|||
use std::time::SystemTime;
|
||||
|
||||
|
||||
|
||||
pub struct StatusObj {
|
||||
svname: String, // Service name
|
||||
svpath: String, // Service path
|
||||
|
@ -34,18 +35,24 @@ impl StatusObj {
|
|||
println!("fail: {}: unable to change to service directory: file does not exist", sv);
|
||||
return None
|
||||
}
|
||||
|
||||
// Check if supervise/control and supervise/ok exists, and if runsv running.
|
||||
let control_exists = misc::check_fifo(sv.clone(), "supervise/ok");
|
||||
if control_exists == false {
|
||||
return None;
|
||||
}
|
||||
let control_exists = misc::check_fifo(sv.clone(), "supervise/control");
|
||||
if control_exists == false {
|
||||
let ok_option = Path::new("supervise/ok");
|
||||
if ! ok_option.exists() {
|
||||
println!("warning: {}: unable to open supervise/ok: file does not exist", sv);
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
// TODO: check if there is a process reading the pipe.
|
||||
// piste : https://docs.rs/tokio/latest/tokio/net/unix/pipe/struct.OpenOptions.html
|
||||
//let mut control_option = fs::File::open("supervise/control");
|
||||
//let status_option = fs::OpenOptions::new().read(true).open("supervise/control");
|
||||
//match control_option {
|
||||
// Ok(_file) => {},
|
||||
// Err(ee) => {
|
||||
// println!("fail: {}: runsv not running {}", sv, ee);
|
||||
// return None;
|
||||
// },
|
||||
//};
|
||||
let status_option = fs::OpenOptions::new().read(true).open("supervise/status");
|
||||
let mut status = match status_option {
|
||||
Ok(file) => file,
|
||||
|
@ -66,6 +73,8 @@ impl StatusObj {
|
|||
};
|
||||
|
||||
if size != 20 {
|
||||
dbg!(size);
|
||||
dbg!(contents);
|
||||
println!("warning: {}: bad supervise/status format", sv);
|
||||
return None
|
||||
}
|
||||
|
@ -111,9 +120,7 @@ impl StatusObj {
|
|||
log: log_exists,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_status_string(&mut self) -> String {
|
||||
// return the status for this service in particular.
|
||||
|
||||
let status_sv;
|
||||
let pid_string: String;
|
||||
|
@ -182,3 +189,4 @@ impl StatusObj {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
|
||||
use std::io::ErrorKind;
|
||||
|
||||
use tokio::net::unix::pipe;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
pub fn make_pause_run(pr_int: u8) -> bool {
|
||||
if pr_int == 0 {
|
||||
return false // run
|
||||
|
@ -77,26 +72,3 @@ pub fn return_u8_in_u64(table: Vec<u8>) -> u64 {
|
|||
return r
|
||||
}
|
||||
|
||||
pub fn check_fifo(sv: String, path: &str) -> bool {
|
||||
// Check if fifo is available. If yes, return true.
|
||||
// If no, return false.
|
||||
let rt = Runtime::new().unwrap();
|
||||
let _guard = rt.enter();
|
||||
|
||||
let sender = pipe::OpenOptions::new().open_sender(path);
|
||||
match sender {
|
||||
Ok(..) => {},
|
||||
Err(e) => match e.kind() {
|
||||
ErrorKind::NotFound => {
|
||||
println!("warning: {sv}: unable to open {path}: file does not exist");
|
||||
return false;
|
||||
},
|
||||
_ => {
|
||||
println!("fail: {sv}: runsv not running");
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue