code refactoring
code refactoring
This commit is contained in:
parent
b67f987031
commit
8244282fa4
30
src/main.rs
30
src/main.rs
@ -6,11 +6,9 @@ extern crate ini;
|
||||
extern crate exitcode;
|
||||
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::path::Path;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use sysinfo::System;
|
||||
|
||||
mod mods;
|
||||
|
||||
@ -43,34 +41,6 @@ async fn check(rule: &Rule) -> bool {
|
||||
};
|
||||
}
|
||||
|
||||
/// Check is process running
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `process_name` Process name to be checked
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// if check_process("httpd".to_string()).await {
|
||||
/// println!("ok");
|
||||
/// } else {
|
||||
/// println!("uh-oh... something wrong!");
|
||||
/// }
|
||||
/// ```
|
||||
fn check_process(process_name: String) -> bool {
|
||||
let mut sys = System::new_all();
|
||||
let mut result: bool = false;
|
||||
|
||||
sys.refresh_all();
|
||||
|
||||
for _process in sys.processes_by_exact_name(OsStr::new(&process_name)) {
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Checks web-service availability
|
||||
///
|
||||
/// # Arguments
|
||||
|
||||
@ -1,8 +1,38 @@
|
||||
use std::ffi::OsStr;
|
||||
use std::process::Command;
|
||||
use sysinfo::System;
|
||||
|
||||
use crate::mods::mod_debug::*;
|
||||
use crate::mods::mod_i18n::*;
|
||||
|
||||
/// Check is process running
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `process_name` Process name to be checked
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// if check_process("httpd".to_string()).await {
|
||||
/// println!("ok");
|
||||
/// } else {
|
||||
/// println!("uh-oh... something wrong!");
|
||||
/// }
|
||||
/// ```
|
||||
pub fn check_process(process_name: String) -> bool {
|
||||
let mut sys = System::new_all();
|
||||
let mut result: bool = false;
|
||||
|
||||
sys.refresh_all();
|
||||
|
||||
for _process in sys.processes_by_exact_name(OsStr::new(&process_name)) {
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Execute shell command
|
||||
///
|
||||
/// In linux sh command interpreter will be called.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user