From d923df7c5052e017feb7798f59e13f775749e63c Mon Sep 17 00:00:00 2001 From: renoseven Date: Fri, 22 Dec 2023 17:13:33 +0800 Subject: [PATCH] upatchd: create config dir at startup 1. rename arg '--config-file' to '--config-dir' 2. try to create config directory at startup Signed-off-by: renoseven --- upatch/upatch-daemon/src/args.rs | 10 +++++----- upatch/upatch-daemon/src/main.rs | 6 +++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/upatch/upatch-daemon/src/args.rs b/upatch/upatch-daemon/src/args.rs index 48f3ed26..476afdeb 100644 --- a/upatch/upatch-daemon/src/args.rs +++ b/upatch/upatch-daemon/src/args.rs @@ -8,8 +8,8 @@ use syscare_common::util::fs; use super::{DAEMON_ABOUT, DAEMON_NAME, DAEMON_VERSION}; -const DEFAULT_CONFIG_FILE: &str = "/etc/syscare/upatchd.yaml"; const DEFAULT_WORK_DIR: &str = "/var/run/syscare"; +const DEFAULT_CONFIG_DIR: &str = "/etc/syscare"; const DEFAULT_LOG_DIR: &str = "/var/log/syscare"; const DEFAULT_LOG_LEVEL: &str = "info"; @@ -28,9 +28,9 @@ pub struct Arguments { #[clap(short, long)] pub daemon: bool, - /// Path for daemon config file - #[clap(long, default_value=DEFAULT_CONFIG_FILE)] - pub config_file: PathBuf, + /// Daemon config directory + #[clap(long, default_value=DEFAULT_CONFIG_DIR)] + pub config_dir: PathBuf, /// Daemon working directory #[clap(long, default_value=DEFAULT_WORK_DIR)] @@ -51,7 +51,7 @@ impl Arguments { } fn normalize_path(mut self) -> Result { - self.config_file = fs::normalize(&self.config_file)?; + self.config_dir = fs::normalize(&self.config_dir)?; self.work_dir = fs::normalize(self.work_dir)?; self.log_dir = fs::normalize(&self.log_dir)?; diff --git a/upatch/upatch-daemon/src/main.rs b/upatch/upatch-daemon/src/main.rs index 1a94a367..61f8b66e 100644 --- a/upatch/upatch-daemon/src/main.rs +++ b/upatch/upatch-daemon/src/main.rs @@ -35,6 +35,7 @@ const DAEMON_ABOUT: &str = env!("CARGO_PKG_DESCRIPTION"); const DAEMON_UMASK: u32 = 0o077; const DAEMON_PARK_TIME: u64 = 100; +const CONFIG_FILE_NAME: &str = "upatchd.yaml"; const PID_FILE_NAME: &str = "upatchd.pid"; const SOCKET_FILE_NAME: &str = "upatchd.sock"; @@ -76,6 +77,8 @@ impl Daemon { } fn prepare_environment(&self) -> Result<()> { + self.prepare_directory(&self.args.config_dir)?; + self.prepare_directory(&self.args.work_dir)?; fs::set_permissions( &self.args.work_dir, @@ -115,7 +118,8 @@ impl Daemon { fn initialize_skeleton(&self) -> Result { let mut io_handler = IoHandler::new(); - io_handler.extend_with(SkeletonImpl::new(&self.args.config_file)?.to_delegate()); + let config_file = self.args.config_dir.join(CONFIG_FILE_NAME); + io_handler.extend_with(SkeletonImpl::new(config_file)?.to_delegate()); Ok(io_handler) } -- Gitee