Skip to content

Commit

Permalink
#324 #334 optional process management
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Apr 9, 2022
1 parent ba3ade9 commit 7114f42
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -84,6 +87,7 @@ actix-rt = "2"
[features]
default = ["https"]
https = ["acme-lib", "rustls"]
process-management = ["sysinfo"]

[lib]
name = "atomic_server_lib"
Expand Down
12 changes: 9 additions & 3 deletions server/src/appstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppState> {
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())?;
Expand Down
1 change: 1 addition & 0 deletions server/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod helpers;
#[cfg(feature = "https")]
mod https;
mod jsonerrors;
#[cfg(feature = "process-management")]
mod process;
mod routes;
pub mod serve;
Expand Down
1 change: 1 addition & 0 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod helpers;
#[cfg(feature = "https")]
mod https;
mod jsonerrors;
#[cfg(feature = "process-management")]
mod process;
mod routes;
pub mod serve;
Expand Down
9 changes: 8 additions & 1 deletion server/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit 7114f42

Please sign in to comment.