From 49e6eace8e10456d12a48bcddc15e99dfeb17aab Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sun, 28 Apr 2024 17:31:04 -0400 Subject: [PATCH] add IPC directory to rpm and deb packaging add config verify step after all command line options have been processed closes #366 --- package/debian/veilid-server/DEBIAN/postinst | 2 ++ package/rpm/veilid-server/veilid-server.spec | 4 +++ veilid-server/src/main.rs | 3 ++ veilid-server/src/settings.rs | 36 ++++++++++++++------ 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/package/debian/veilid-server/DEBIAN/postinst b/package/debian/veilid-server/DEBIAN/postinst index 41253ed6..929f0953 100755 --- a/package/debian/veilid-server/DEBIAN/postinst +++ b/package/debian/veilid-server/DEBIAN/postinst @@ -9,12 +9,14 @@ adduser --system --group veilid &>/dev/null || true mkdir -p /var/db/veilid-server/protected_store mkdir -p /var/db/veilid-server/table_store mkdir -p /var/db/veilid-server/block_store +mkdir -p /var/db/veilid-server/ipc # Set permissions chown -R veilid:veilid /var/db/veilid-server chmod 0750 /var/db/veilid-server/protected_store chmod 0750 /var/db/veilid-server/table_store chmod 0750 /var/db/veilid-server/block_store +chmod 0750 /var/db/veilid-server/ipc chmod 0750 /var/db/veilid-server chmod 755 /usr/bin/veilid-server diff --git a/package/rpm/veilid-server/veilid-server.spec b/package/rpm/veilid-server/veilid-server.spec index a9b51b92..9d3d50d1 100644 --- a/package/rpm/veilid-server/veilid-server.spec +++ b/package/rpm/veilid-server/veilid-server.spec @@ -33,10 +33,12 @@ adduser --system -U veilid &>/dev/null || true mkdir -p /var/db/veilid-server/protected_store mkdir -p /var/db/veilid-server/table_store mkdir -p /var/db/veilid-server/block_store +mkdir -p /var/db/veilid-server/ipc chown -R veilid:veilid /var/db/veilid-server chmod 0750 /var/db/veilid-server/protected_store chmod 0750 /var/db/veilid-server/table_store chmod 0750 /var/db/veilid-server/block_store +chmod 0750 /var/db/veilid-server/ipc chmod 0750 /var/db/veilid-server chmod 755 /usr/bin/veilid-server @@ -57,3 +59,5 @@ fi %changelog * Sun Jul 2 2023 TC - experimental RPM building +* Sun Apr 28 2024 Christien Rioux +- add ipc directory to installation diff --git a/veilid-server/src/main.rs b/veilid-server/src/main.rs index bfb42791..7ebab500 100644 --- a/veilid-server/src/main.rs +++ b/veilid-server/src/main.rs @@ -290,6 +290,9 @@ fn main() -> EyreResult<()> { .apply_subnode_index() .wrap_err("failed to apply subnode index")?; + // --- Verify Config --- + settings.verify()?; + // --- Dump Config --- if args.dump_config { return serde_yaml::to_writer(std::io::stdout(), &*settings.read()) diff --git a/veilid-server/src/settings.rs b/veilid-server/src/settings.rs index 9cbdce0c..d28b7b6e 100644 --- a/veilid-server/src/settings.rs +++ b/veilid-server/src/settings.rs @@ -736,6 +736,25 @@ impl Settings { inner: Arc::new(RwLock::new(inner)), }) } + + pub fn verify(&self) -> EyreResult<()> { + let inner = self.inner.read(); + + cfg_if! { + if #[cfg(windows)] { + // no ipc setup for windows + } else { + if inner.client_api.ipc_enabled + && !Self::get_or_create_private_directory(&inner.client_api.ipc_directory, true) + { + bail!("unable to create default IPC directory"); + } + } + } + + Ok(()) + } + pub fn read(&self) -> RwLockReadGuard { self.inner.read() } @@ -849,13 +868,13 @@ impl Settings { } #[allow(dead_code)] - fn get_or_create_default_directory(subpath: &str) -> PathBuf { + fn get_default_directory(subpath: &str) -> PathBuf { #[cfg(unix)] { - let globalpath = PathBuf::from("/var/db/veilid-server").join(subpath); + let globalpath = PathBuf::from("/var/db/veilid-server"); - if Self::get_or_create_private_directory(&globalpath, true) { - return globalpath; + if globalpath.exists() { + return globalpath.join(subpath); } } @@ -865,12 +884,7 @@ impl Settings { PathBuf::from("./") }; ts_path.push(subpath); - - if Self::get_or_create_private_directory(&ts_path, true) { - return ts_path; - } - - panic!("Failed to create private directory for '{}'", subpath); + ts_path } pub fn get_default_ipc_directory() -> PathBuf { @@ -878,7 +892,7 @@ impl Settings { if #[cfg(windows)] { PathBuf::from(r"\\.\PIPE\veilid-server") } else { - Self::get_or_create_default_directory("ipc") + Self::get_default_directory("ipc") } } }