From 7114f429d776c06b253fe2618e6a9b2642c62673 Mon Sep 17 00:00:00 2001 From: Joep Meindertsma Date: Sat, 9 Apr 2022 20:16:27 +0200 Subject: [PATCH] #324 #334 optional process management --- CHANGELOG.md | 1 + server/Cargo.toml | 6 +++++- server/src/appstate.rs | 12 +++++++++--- server/src/bin.rs | 1 + server/src/lib.rs | 1 + server/src/serve.rs | 9 ++++++++- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e7dfe6eb..7b9c4224b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ By far most changes relate to `atomic-server`, so if not specified, assume the c - Added `data-dir` flag - Replaced `awc` with `ureq` #374 - Get rid of `.unwrap` calls in `commit_monitor` #345 +- Make process management optional #324 #334 ## [v0.31.1] - 2022-03-29 diff --git a/server/Cargo.toml b/server/Cargo.toml index 9ca5ccd23..6a0495b43 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -33,7 +33,6 @@ rustls-pemfile = "0.2" sanitize-filename = "0.3" serde_json = "1" static-files = "0.2" -sysinfo = "0.23" tantivy = "0.17" tracing = "0.1" tracing-actix-web = "0.5" @@ -46,6 +45,10 @@ urlencoding = "2" optional = true version = "0.8" +[dependencies.sysinfo] +optional = true +sysinfo = "0.23" + [dependencies.actix-web] features = ["rustls"] version = "4.0" @@ -84,6 +87,7 @@ actix-rt = "2" [features] default = ["https"] https = ["acme-lib", "rustls"] +process-management = ["sysinfo"] [lib] name = "atomic_server_lib" diff --git a/server/src/appstate.rs b/server/src/appstate.rs index be9954c85..4128e630b 100644 --- a/server/src/appstate.rs +++ b/server/src/appstate.rs @@ -24,12 +24,18 @@ pub struct AppState { /// Creates the AppState (the server's context available in Handlers). /// Initializes or opens a store on disk. -/// Creates a new agent, if neccessary. +/// Creates a new agent, if necessary. pub fn init(config: Config) -> AtomicServerResult { tracing::info!("Initializing AppState"); + // Check if atomic-server is already running somewhere, and try to stop it. It's not a problem if things go wrong here, so errors are simply logged. - let _ = crate::process::terminate_existing_processes(&config) - .map_err(|e| tracing::error!("Could not check for running instance: {}", e)); + if cfg!(feature = "process-management") { + #[cfg(feature = "process-management")] + { + let _ = crate::process::terminate_existing_processes(&config) + .map_err(|e| tracing::error!("Could not check for running instance: {}", e)); + } + } tracing::info!("Opening database at {:?}", &config.store_path); let store = atomic_lib::Db::init(&config.store_path, config.server_url.clone())?; diff --git a/server/src/bin.rs b/server/src/bin.rs index b1cddcb75..4ecac641b 100644 --- a/server/src/bin.rs +++ b/server/src/bin.rs @@ -12,6 +12,7 @@ mod helpers; #[cfg(feature = "https")] mod https; mod jsonerrors; +#[cfg(feature = "process-management")] mod process; mod routes; pub mod serve; diff --git a/server/src/lib.rs b/server/src/lib.rs index 981540b97..0e5cf7a3a 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -14,6 +14,7 @@ mod helpers; #[cfg(feature = "https")] mod https; mod jsonerrors; +#[cfg(feature = "process-management")] mod process; mod routes; pub mod serve; diff --git a/server/src/serve.rs b/server/src/serve.rs index e1895ddbb..b2e7f4fca 100644 --- a/server/src/serve.rs +++ b/server/src/serve.rs @@ -103,7 +103,14 @@ pub async fn serve(config: crate::config::Config) -> AtomicServerResult<()> { // Cleanup, runs when server is stopped tracing_chrome_flush_guard.flush(); - crate::process::remove_pid(&config)?; + + if cfg!(feature = "process-management") { + #[cfg(feature = "process-management")] + { + crate::process::remove_pid(&config)?; + } + } + tracing::info!("Server stopped"); Ok(()) }