diff --git a/CHANGELOG.md b/CHANGELOG.md index e05fa21fa9..073ada57f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### Added -- The `add` command has new `--max-log-files` and `--max-archived-log-files` arguments to support capping node log output +- The `add` command has new `--max-log-files` and `--max-archived-log-files` arguments to support + capping node log output #### Fixed @@ -30,7 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Increased logging related to app configuration. This could help solving issues on launchpad start up. +- Increased logging related to app configuration. This could help solving issues on launchpad start + up. ## 2024-10-03 diff --git a/Cargo.lock b/Cargo.lock index 512762be18..f3f9078e20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8384,7 +8384,7 @@ dependencies = [ [[package]] name = "sn_auditor" -version = "0.3.3" +version = "0.3.4" dependencies = [ "blsttc", "clap", diff --git a/sn_auditor/Cargo.toml b/sn_auditor/Cargo.toml index 8546339cfd..e133358779 100644 --- a/sn_auditor/Cargo.toml +++ b/sn_auditor/Cargo.toml @@ -2,7 +2,7 @@ authors = ["MaidSafe Developers "] description = "Safe Network Auditor" name = "sn_auditor" -version = "0.3.3" +version = "0.3.4" edition = "2021" homepage = "https://maidsafe.net" repository = "https://github.com/maidsafe/safe_network" diff --git a/sn_auditor/src/main.rs b/sn_auditor/src/main.rs index 1cbdaf2f58..ffb5b34d71 100644 --- a/sn_auditor/src/main.rs +++ b/sn_auditor/src/main.rs @@ -308,43 +308,59 @@ async fn initialize_background_spend_dag_collection( } async fn start_server(dag: SpendDagDb) -> Result<()> { - let server = Server::http("0.0.0.0:4242").expect("Failed to start server"); - info!("Starting dag-query server listening on port 4242..."); - for request in server.incoming_requests() { - info!( - "Received request! method: {:?}, url: {:?}", - request.method(), - request.url(), - ); - - // Dispatch the request to the appropriate handler - let response = match request.url() { - "/" => routes::spend_dag_svg(&dag), - s if s.starts_with("/spend/") => routes::spend(&dag, &request).await, - s if s.starts_with("/add-participant/") => { - routes::add_participant(&dag, &request).await - } - "/beta-rewards" => routes::beta_rewards(&dag).await, - _ => routes::not_found(), - }; + loop { + let server = Server::http("0.0.0.0:4242").expect("Failed to start server"); + info!("Starting dag-query server listening on port 4242..."); + for request in server.incoming_requests() { + info!( + "Received request! method: {:?}, url: {:?}", + request.method(), + request.url(), + ); - // Send a response to the client - match response { - Ok(res) => { - let _ = request - .respond(res) - .map_err(|err| eprintln!("Failed to send response: {err}")); - } - Err(e) => { - eprint!("Sending error to client: {e}"); - let res = Response::from_string(format!("Error: {e}")).with_status_code(500); - let _ = request - .respond(res) - .map_err(|err| eprintln!("Failed to send error response: {err}")); + // Dispatch the request to the appropriate handler + let response = match request.url() { + "/" => routes::spend_dag_svg(&dag), + s if s.starts_with("/spend/") => routes::spend(&dag, &request).await, + s if s.starts_with("/add-participant/") => { + routes::add_participant(&dag, &request).await + } + "/beta-rewards" => routes::beta_rewards(&dag).await, + "/restart" => { + info!("Restart auditor web service as to client's request"); + break; + } + "/terminate" => { + info!("Terminate auditor web service as to client's request"); + return Ok(()); + } + _ => routes::not_found(), + }; + + // Send a response to the client + match response { + Ok(res) => { + info!("Sending response to client"); + let _ = request.respond(res).map_err(|err| { + warn!("Failed to send response: {err}"); + eprintln!("Failed to send response: {err}") + }); + } + Err(e) => { + eprint!("Sending error to client: {e}"); + let res = Response::from_string(format!("Error: {e}")).with_status_code(500); + let _ = request.respond(res).map_err(|err| { + warn!("Failed to send error response: {err}"); + eprintln!("Failed to send error response: {err}") + }); + } } } + // Reaching this point indicates a restarting of auditor web service + // Sleep for a while to allowing OS cleanup and settlement. + drop(server); + std::thread::sleep(std::time::Duration::from_secs(10)); } - Ok(()) } // get the data dir path for auditor