From 01f00447f6018d9aeb2f2ba34b8395e18862b877 Mon Sep 17 00:00:00 2001 From: kulukami Date: Fri, 23 Feb 2024 17:13:14 +0800 Subject: [PATCH] opt: config add cronjob --- plugins/scanner/settings.toml | 1 + plugins/scanner/src/bin/scanner_plugin.rs | 12 +++++++----- plugins/scanner/src/config.rs | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/scanner/settings.toml b/plugins/scanner/settings.toml index 77429559d..4d3d846c9 100644 --- a/plugins/scanner/settings.toml +++ b/plugins/scanner/settings.toml @@ -14,6 +14,7 @@ log_level = "info" log_path = "./" remote_log_level = "error" max_backups = 10 +enable_cronjob = 0 [engine] clamav_max_filesize = 18874368 diff --git a/plugins/scanner/src/bin/scanner_plugin.rs b/plugins/scanner/src/bin/scanner_plugin.rs index ffebafe7d..52eabe061 100644 --- a/plugins/scanner/src/bin/scanner_plugin.rs +++ b/plugins/scanner/src/bin/scanner_plugin.rs @@ -10,7 +10,7 @@ use scanner::{ ARCHIVE_DB_HASH, ARCHIVE_DB_PWD, ARCHIVE_DB_VERSION, DB_DEFAULT, DB_URLS, SERVICE_DEFAULT_CG_CPU, SERVICE_DEFAULT_CG_MEM, SERVICE_DEFAULT_LOG_LEVEL, SERVICE_DEFAULT_LOG_MAX_BAK, SERVICE_DEFAULT_LOG_PATH, SERVICE_DEFAULT_LOG_RLEVEL, - SERVICE_PID_LOCK_PATH, + SERVICE_ENABLE_CRONJOB, SERVICE_PID_LOCK_PATH, }, detector::Detector, model::engine::clamav::{self, updater}, @@ -153,10 +153,12 @@ fn main() { }); // cronjob scan dir and proc - let s_cron_worker = s.clone(); - let s_cron_lock = s_lock.clone(); - let _cronjob_t = Cronjob::new(s_cron_worker, s_cron_lock, WAIT_INTERVAL_DAILY); - + let mut _cronjob_t = None; + if *SERVICE_ENABLE_CRONJOB != 0{ + let s_cron_worker = s.clone(); + let s_cron_lock = s_lock.clone(); + _cronjob_t = Some(Cronjob::new(s_cron_worker, s_cron_lock, WAIT_INTERVAL_DAILY)); + } // wait childs let _: () = r_lock.recv().unwrap(); diff --git a/plugins/scanner/src/config.rs b/plugins/scanner/src/config.rs index 5a79ffad0..b6d83a42c 100644 --- a/plugins/scanner/src/config.rs +++ b/plugins/scanner/src/config.rs @@ -17,6 +17,7 @@ lazy_static::lazy_static!( pub static ref SERVICE_DEFAULT_LOG_PATH: String = settings_string("service","log_path").unwrap().to_string(); pub static ref SERVICE_DEFAULT_LOG_RLEVEL: String = settings_string("service","remote_log_level").unwrap().to_string(); pub static ref SERVICE_DEFAULT_LOG_MAX_BAK: i64 = settings_int("service","max_backups").unwrap() as _; + pub static ref SERVICE_ENABLE_CRONJOB: i64 = settings_int("service","enable_cronjob").unwrap() as _; pub static ref SCAN_DIR_CONFIG: Vec = gen_scan_dir().unwrap(); pub static ref SCAN_DIR_FILTER: Vec = settings_vec_string("scan","filter").unwrap();