From 572fbcd3eb7cca1981e821ea32e0874063284bed Mon Sep 17 00:00:00 2001 From: prplV Date: Wed, 30 Oct 2024 12:47:21 +0300 Subject: [PATCH] bugfix --- .gitignore | 3 ++- settings.json | 60 ++++++------------------------------------- src/options/config.rs | 7 +++-- src/utils/prcs.rs | 8 +++--- tests/examples/run.sh | 2 +- 5 files changed, 20 insertions(+), 60 deletions(-) diff --git a/.gitignore b/.gitignore index 56f7567..b83910d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /target .idea Dockerfile -Cargo.lock \ No newline at end of file +Cargo.lock +settings.json diff --git a/settings.json b/settings.json index 4280a0b..ff72861 100644 --- a/settings.json +++ b/settings.json @@ -3,24 +3,16 @@ "configServer" : "localhost", "processes": [ { - "name": "web-server", - "path": "/home/vladislav/web/web-server/run.sh", + "name": "temp-process", + "path": "/home/user/monitor/runner-rs/temp-process", "dependencies": { "files": [ { - "filename": "control-file", - "src": "/home/vladislav/web/", + "filename": "dep-file", + "src": "/home/user/monitor/runner-rs/tests/examples/", "triggers": { "onDelete": "stop", - "onChange": "stop" - } - }, - { - "filename": "config-file", - "src": "/home/vladislav/web/", - "triggers": { - "onDelete": "stop", - "onChange": "restart" + "onChange": "stay" } } ], @@ -29,49 +21,13 @@ "hostname": "ya.ru", "port": 443, "triggers": { - "wait": 6, - "delay": 1, - "onLost": "hold" - } - } - ] - } - }, - { - "name": "temp-process", - "path": "/home/vladislav/web/temp-process/run.sh", - "dependencies": { - "files": [ - { - "filename": "control-file", - "src": "/home/vladislav/web/", - "triggers": { - "onDelete": "hold", - "onChange": "stop" - } - } - ], - "services": [ - { - "hostname": "google.com", - "port": 443, - "triggers": { - "wait": 5, - "delay": 1, - "onLost": "stop" - } - }, - { - "hostname": "localhost", - "port": 8080, - "triggers": { - "wait": 6, + "wait": 10, "delay": 2, - "onLost": "stop" + "onLost": "hold" } } ] } } ] -} \ No newline at end of file +} diff --git a/src/options/config.rs b/src/options/config.rs index faa25c2..fc4f301 100644 --- a/src/options/config.rs +++ b/src/options/config.rs @@ -182,8 +182,11 @@ fn invalid_config_watcher(conn: &mut Connection) -> Processes { fn get_remote_config(conn: &mut Connection) -> Option { let res: Res = conn.xrevrange_count("config_stream", "+", "-", 1); - if res.is_ok() { - let config = &res.unwrap()[0]; + if let Ok(result) = res { + if result.is_empty() { + return None; + } + let config = &result[0]; if !config.is_empty() { return parse_extern_config(&config[0].1[0].1); } diff --git a/src/utils/prcs.rs b/src/utils/prcs.rs index 6d0d85a..0218deb 100644 --- a/src/utils/prcs.rs +++ b/src/utils/prcs.rs @@ -94,15 +94,15 @@ pub async fn restart_process(name: &str, path: &str) -> Result<(), CustomError> } pub async fn start_process(name: &str, path: &str) -> Result<(), CustomError> { - // let runsh = format!("{}{}", path, "/run.sh"); - let mut command = Command::new("bash"); - command.arg(path); + // let runsh = format!("{} {}", "exec", path); + let mut command = Command::new(path); + // command.arg(path); match command.spawn() { Ok(_) => { warn!("Process {} is running now!", name); Ok(()) } - Err(_) => Err(CustomError::Fatal), + Err(er) => {println!("{:?}", er); Err(CustomError::Fatal)}, } } diff --git a/tests/examples/run.sh b/tests/examples/run.sh index c46f992..29e3b48 100644 --- a/tests/examples/run.sh +++ b/tests/examples/run.sh @@ -1 +1 @@ -./$(pwd)/temp-process \ No newline at end of file +/home/user/monitor/runner-rs/temp-process \ No newline at end of file