From 79c9a91ae734ddd253d162a268de2a0365befcd7 Mon Sep 17 00:00:00 2001 From: Joep Meindertsma Date: Tue, 13 Feb 2024 14:49:35 +0100 Subject: [PATCH] Remove `process-management` feature #324 #334 --- CHANGELOG.md | 4 ++ Cargo.lock | 46 +------------------- server/Cargo.toml | 9 +--- server/src/appstate.rs | 9 ---- server/src/bin.rs | 2 - server/src/lib.rs | 2 - server/src/process.rs | 97 ------------------------------------------ server/src/serve.rs | 7 --- 8 files changed, 7 insertions(+), 169 deletions(-) delete mode 100644 server/src/process.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index c0c999c13..22a9869b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ By far most changes relate to `atomic-server`, so if not specified, assume the c **Changes to JS assets (including the front-end and JS libraries) are not shown here**, but in [`/browser/CHANGELOG`](/browser/CHANGELOG.md). See [STATUS.md](server/STATUS.md) to learn more about which features will remain stable. +## [UNRELEASED] + +- Remove `process-management` feature #324 #334 + ## [v0.37.0] - 2024-02-01 - Refactor `atomic_lib::Resource` propval methods (e.g. `set_propval` => `set`), make them chainable. #822 diff --git a/Cargo.lock b/Cargo.lock index c4c7d1857..d78ffc38d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -500,7 +500,6 @@ dependencies = [ "serde_with", "simple-server-timing-header", "static-files", - "sysinfo", "tantivy", "tokio", "tracing", @@ -1493,7 +1492,7 @@ dependencies = [ "libc", "log", "rustversion", - "windows 0.32.0", + "windows", ] [[package]] @@ -2237,15 +2236,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "ntapi" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" -dependencies = [ - "winapi", -] - [[package]] name = "ntest" version = "0.9.0" @@ -3624,21 +3614,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sysinfo" -version = "0.30.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb4f3438c8f6389c864e61221cbc97e9bca98b4daf39a5beb7bea660f528bb2" -dependencies = [ - "cfg-if", - "core-foundation-sys", - "libc", - "ntapi", - "once_cell", - "rayon", - "windows 0.52.0", -] - [[package]] name = "tantivy" version = "0.21.1" @@ -4483,25 +4458,6 @@ dependencies = [ "windows_x86_64_msvc 0.32.0", ] -[[package]] -name = "windows" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" -dependencies = [ - "windows-core", - "windows-targets 0.52.0", -] - -[[package]] -name = "windows-core" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" -dependencies = [ - "windows-targets 0.52.0", -] - [[package]] name = "windows-sys" version = "0.36.1" diff --git a/server/Cargo.toml b/server/Cargo.toml index 42121e0a4..ddd63d798 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -4,21 +4,21 @@ default-run = "atomic-server" description = "Create, share and model Atomic Data with this graph database server. Run atomic-server without any arguments to start the server. Use --help to learn about the options." edition = "2021" homepage = "https://atomicserver.eu/" +include = ["src/**/*", "Cargo.toml", "assets_tmp", "build.rs"] license = "MIT" name = "atomic-server" readme = "./README.md" repository = "https://github.com/atomicdata-dev/atomic-server" version = "0.37.0" -include = ["src/**/*", "Cargo.toml", "assets_tmp", "build.rs"] [[bin]] name = "atomic-server" path = "src/bin.rs" [build-dependencies] +dircpy = "0.3.15" static-files = "0.2" walkdir = "2" -dircpy = "0.3.15" [dependencies] actix = ">= 0.12, < 0.14" @@ -74,10 +74,6 @@ version = "0.21.0" optional = true version = "0.20.0" -[dependencies.sysinfo] -optional = true -version = "0.30" - [dependencies.actix-web] features = ["rustls"] version = "4.4" @@ -120,7 +116,6 @@ assert_cmd = "2" [features] default = ["https", "telemetry"] https = ["rustls", "instant-acme", "rcgen", "rustls-pemfile"] -process-management = ["sysinfo"] telemetry = ["tracing-opentelemetry", "opentelemetry", "opentelemetry-jaeger"] [lib] diff --git a/server/src/appstate.rs b/server/src/appstate.rs index b48853ce5..945c833ad 100644 --- a/server/src/appstate.rs +++ b/server/src/appstate.rs @@ -39,15 +39,6 @@ pub fn init(config: Config) -> AtomicServerResult { tracing::warn!("Development mode is enabled. This will use staging environments for services like LetsEncrypt."); } - // 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. - 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 should_init = !&config.store_path.exists() || config.initialize; let mut 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 3af289f38..30cc513b7 100644 --- a/server/src/bin.rs +++ b/server/src/bin.rs @@ -13,8 +13,6 @@ mod helpers; #[cfg(feature = "https")] mod https; mod jsonerrors; -#[cfg(feature = "process-management")] -mod process; mod routes; pub mod serve; // #[cfg(feature = "search")] diff --git a/server/src/lib.rs b/server/src/lib.rs index 5acf81c78..9110712de 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -14,8 +14,6 @@ mod helpers; #[cfg(feature = "https")] mod https; mod jsonerrors; -#[cfg(feature = "process-management")] -mod process; mod routes; pub mod serve; // #[cfg(feature = "search")] diff --git a/server/src/process.rs b/server/src/process.rs deleted file mode 100644 index 1044b4fb2..000000000 --- a/server/src/process.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! Checks if the process is running, kills a running process if it is. - -use crate::{config::Config, errors::AtomicServerResult}; - -/// Checks if the server is running. If it is, kill that process. Also creates creates a new PID. -pub fn terminate_existing_processes(config: &Config) -> AtomicServerResult<()> { - let pid_maybe = match std::fs::read_to_string(pid_path(config)) { - Ok(content) => str::parse::(&content).ok(), - Err(_e) => None, - }; - if let Some(pid_int) = pid_maybe { - let pid = pid_int.into(); - use sysinfo::{ProcessExt, SystemExt}; - let mut s = sysinfo::System::new_all(); - let retry_secs = 1; - let mut tries_left = 30; - // either friendly (Terminate) or not friendly (Kill) - let mut signal = sysinfo::Signal::Term; - if let Some(process) = s.process(pid) { - tracing::warn!( - "Terminating existing running instance of atomic-server (process ID: {})...", - process.pid() - ); - process.kill(); - tracing::info!("Checking if other server has successfully terminated...",); - loop { - s.refresh_processes(); - if let Some(_process) = s.process(pid) { - if tries_left > 1 { - tries_left -= 1; - tracing::info!( - "Other instance is still running, checking again in {} seconds, for {} more times ", - retry_secs, - tries_left - ); - std::thread::sleep(std::time::Duration::from_secs(retry_secs)); - } else { - if signal == sysinfo::Signal::Kill { - tracing::error!("Could not terminate other atomic-server, exiting..."); - std::process::exit(1); - } - tracing::warn!( - "Terminate signal did not work, let's try again with Kill...", - ); - _process.kill(); - tries_left = 15; - signal = sysinfo::Signal::Kill; - } - continue; - }; - tracing::info!("No other atomic-server is running, continuing start-up",); - break; - } - } - } - create_pid(config) -} - -/// Removes the process id file in the config directory meant for signaling this instance is running. -pub fn remove_pid(config: &Config) -> AtomicServerResult<()> { - if std::fs::remove_file(pid_path(config)).is_err() { - tracing::warn!( - "Could not remove process file at {}", - pid_path(config).to_str().unwrap() - ) - } else { - tracing::info!( - "Removed process file at {}", - pid_path(config).to_str().unwrap() - ); - } - Ok(()) -} - -const PID_NAME: &str = "atomic_server_process_id"; - -fn pid_path(config: &Config) -> std::path::PathBuf { - std::path::Path::join(&config.config_dir, PID_NAME) -} - -/// Writes a `pid` file in the config directory to signal which instance is running. -fn create_pid(config: &Config) -> AtomicServerResult<()> { - use std::io::Write; - let pid = sysinfo::get_current_pid() - .map_err(|_| "Failed to get process info required to create process ID")?; - let mut pid_file = std::fs::File::create(pid_path(config)).map_err(|e| { - format!( - "Could not create process file at {}. {}", - pid_path(config).to_str().unwrap(), - e - ) - })?; - pid_file - .write_all(pid.to_string().as_bytes()) - .map_err(|e| format!("failed to write process file. {}", e))?; - Ok(()) -} diff --git a/server/src/serve.rs b/server/src/serve.rs index 3da674f85..253be727c 100644 --- a/server/src/serve.rs +++ b/server/src/serve.rs @@ -111,13 +111,6 @@ pub async fn serve(config: crate::config::Config) -> AtomicServerResult<()> { guard.flush() } - if cfg!(feature = "process-management") { - #[cfg(feature = "process-management")] - { - crate::process::remove_pid(&config)?; - } - } - tracing::info!("Server stopped"); Ok(()) }