Now you can run script on watchdog startup. File structure changed on *nix. Some changes in config file and scripts, please check on upgrade.

Now you can run script on watchdog startup. File structure changed on *nix. Some changes in config file and scripts, please check on upgrade.
This commit is contained in:
2022-10-29 16:57:57 +03:00
parent fa19c8327b
commit f1d16093b6
15 changed files with 362 additions and 216 deletions

View File

@@ -210,24 +210,12 @@ fn main() {
let mut just_started = true;
if check_process("svchost.exe".to_string()) {
println!("svchost is running");
} else {
println!("svchost is not running");
}
if check_process("httpd.exe".to_string()) {
println!("httpd is running");
} else {
println!("httpd is not running");
}
let cfg_file = if args.len() > 1 {
&args[1]
} else if cfg!(windows) {
"cai-watchdog.ini"
} else {
"/etc/cai-watchdog.conf"
"/etc/cai-watchdog/cai-watchdog.conf"
};
if !Path::new(cfg_file).exists() {
@@ -303,35 +291,16 @@ fn main() {
);
}
let start_notification = if cfg["notifications"].contains_key("service_start") {
cfg["notifications"]["service_start"].clone().unwrap().to_string() == "true".to_string()
} else {
true
};
let notification_email = if cfg["notifications"].contains_key("email") {
cfg["notifications"]["email"].clone().unwrap()
let on_start_command = if cfg["main"].contains_key("on_start_command") {
cfg["main"]["on_start_command"].clone().unwrap()
} else {
"".to_string()
};
let notification_command = if cfg["notifications"].contains_key("command") {
cfg["notifications"]["command"].clone().unwrap()
} else {
"".to_string()
};
debug_log("\u{2139} Service started".to_string());
if start_notification && notification_command.to_string() != "" {
debug_log("\u{2139} Service started".to_string());
let shell_cmd = notification_command.to_string()
.replace("<email>", &notification_email.to_string())
.replace("<subject>", "\"\u{2139} Watchdog service started\"")
.replace("<message>", "\"\u{2139} Watchdog service started\"");
debug_log(format!("execute {}", shell_cmd));
execute(shell_cmd);
if on_start_command.to_string() != "" {
execute(on_start_command);
}
loop {