aboutsummaryrefslogtreecommitdiff
path: root/src/garage/server.rs
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2022-09-08 15:45:09 +0200
committerAlex <alex@adnab.me>2022-09-08 15:45:09 +0200
commit03c40a0b24dd5bd2a51d3cd3df0ca1a42fb2d328 (patch)
treecf55d93dc4d95bc3eacb756f853ffe63e2dafc44 /src/garage/server.rs
parent9f5433db821612fc462800c7532418522d6dbe2a (diff)
parentceb1f0229a9c8b9f8255b4a4c70272627f0c34d7 (diff)
downloadgarage-03c40a0b24dd5bd2a51d3cd3df0ca1a42fb2d328.tar.gz
garage-03c40a0b24dd5bd2a51d3cd3df0ca1a42fb2d328.zip
Merge pull request 'Reorganize dependencies' (#373) from improve-deps into main
This PR includes work from @jirutka : - [x] Allow linking against system-provided libraries (libsodium, libsqlite, libzstd) #370 - [x] Make OTLP exporter optional and allow building without Prometheus exporter (/metrics) #372 And also: - [x] Update `.nix` files - [x] Remove heed default-features - [x] Bump versions of all Garage crates to 0.8.0 - [x] Make db engines (lmdb, sled, sqlite) optionnal - [x] Add documentation for available features - [x] Directly include code of previous versions used for migration in order to reduce dependencies - [x] Read variable `GIT_VERSION` from garage main instead of in crate garage_util to make builds faster - [x] Report features used in the build somewhere? (in `garage --version` or something) - [x] Check we `warn!` correctly if we try to use deactivated feature - [x] Allow not to launch S3 endpoint if not in config Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/373
Diffstat (limited to 'src/garage/server.rs')
-rw-r--r--src/garage/server.rs125
1 files changed, 79 insertions, 46 deletions
diff --git a/src/garage/server.rs b/src/garage/server.rs
index 6321357a..aeef02a2 100644
--- a/src/garage/server.rs
+++ b/src/garage/server.rs
@@ -9,12 +9,13 @@ use garage_util::error::Error;
use garage_api::admin::api_server::AdminApiServer;
use garage_api::s3::api_server::S3ApiServer;
use garage_model::garage::Garage;
-use garage_web::run_web_server;
+use garage_web::WebServer;
#[cfg(feature = "k2v")]
use garage_api::k2v::api_server::K2VApiServer;
use crate::admin::*;
+#[cfg(feature = "telemetry-otlp")]
use crate::tracing_setup::*;
async fn wait_from(mut chan: watch::Receiver<bool>) {
@@ -29,6 +30,8 @@ pub async fn run_server(config_file: PathBuf) -> Result<(), Error> {
info!("Loading configuration...");
let config = read_config(config_file)?;
+ // ---- Initialize Garage internals ----
+
info!("Initializing background runner...");
let watch_cancel = netapp::util::watch_ctrl_c();
let (background, await_background_done) = BackgroundRunner::new(16, watch_cancel.clone());
@@ -36,9 +39,14 @@ pub async fn run_server(config_file: PathBuf) -> Result<(), Error> {
info!("Initializing Garage main data store...");
let garage = Garage::new(config.clone(), background)?;
- info!("Initialize tracing...");
- if let Some(export_to) = config.admin.trace_sink {
- init_tracing(&export_to, garage.system.id)?;
+ if config.admin.trace_sink.is_some() {
+ info!("Initialize tracing...");
+
+ #[cfg(feature = "telemetry-otlp")]
+ init_tracing(config.admin.trace_sink.as_ref().unwrap(), garage.system.id)?;
+
+ #[cfg(not(feature = "telemetry-otlp"))]
+ error!("Garage was built without OTLP exporter, admin.trace_sink is ignored.");
}
info!("Initialize Admin API server and metrics collector...");
@@ -50,53 +58,78 @@ pub async fn run_server(config_file: PathBuf) -> Result<(), Error> {
info!("Create admin RPC handler...");
AdminRpcHandler::new(garage.clone());
- info!("Initializing S3 API server...");
- let s3_api_server = tokio::spawn(S3ApiServer::run(
- garage.clone(),
- wait_from(watch_cancel.clone()),
- ));
-
- #[cfg(feature = "k2v")]
- let k2v_api_server = {
- info!("Initializing K2V API server...");
- tokio::spawn(K2VApiServer::run(
- garage.clone(),
- wait_from(watch_cancel.clone()),
- ))
- };
-
- info!("Initializing web server...");
- let web_server = tokio::spawn(run_web_server(
- garage.clone(),
- wait_from(watch_cancel.clone()),
- ));
-
- info!("Launching Admin API server...");
- let admin_server = tokio::spawn(admin_server.run(wait_from(watch_cancel.clone())));
+ // ---- Launch public-facing API servers ----
+
+ let mut servers = vec![];
+
+ if let Some(s3_bind_addr) = &config.s3_api.api_bind_addr {
+ info!("Initializing S3 API server...");
+ servers.push((
+ "S3 API",
+ tokio::spawn(S3ApiServer::run(
+ garage.clone(),
+ *s3_bind_addr,
+ config.s3_api.s3_region.clone(),
+ wait_from(watch_cancel.clone()),
+ )),
+ ));
+ }
- // Stuff runs
+ if config.k2v_api.is_some() {
+ #[cfg(feature = "k2v")]
+ {
+ info!("Initializing K2V API server...");
+ servers.push((
+ "K2V API",
+ tokio::spawn(K2VApiServer::run(
+ garage.clone(),
+ config.k2v_api.as_ref().unwrap().api_bind_addr,
+ config.s3_api.s3_region.clone(),
+ wait_from(watch_cancel.clone()),
+ )),
+ ));
+ }
+ #[cfg(not(feature = "k2v"))]
+ error!("K2V is not enabled in this build, cannot start K2V API server");
+ }
- // When a cancel signal is sent, stuff stops
- if let Err(e) = s3_api_server.await? {
- warn!("S3 API server exited with error: {}", e);
- } else {
- info!("S3 API server exited without error.");
+ if let Some(web_config) = &config.s3_web {
+ info!("Initializing web server...");
+ servers.push((
+ "Web",
+ tokio::spawn(WebServer::run(
+ garage.clone(),
+ web_config.bind_addr,
+ web_config.root_domain.clone(),
+ wait_from(watch_cancel.clone()),
+ )),
+ ));
}
- #[cfg(feature = "k2v")]
- if let Err(e) = k2v_api_server.await? {
- warn!("K2V API server exited with error: {}", e);
- } else {
- info!("K2V API server exited without error.");
+
+ if let Some(admin_bind_addr) = &config.admin.api_bind_addr {
+ info!("Launching Admin API server...");
+ servers.push((
+ "Admin",
+ tokio::spawn(admin_server.run(*admin_bind_addr, wait_from(watch_cancel.clone()))),
+ ));
}
- if let Err(e) = web_server.await? {
- warn!("Web server exited with error: {}", e);
- } else {
- info!("Web server exited without error.");
+
+ #[cfg(not(feature = "metrics"))]
+ if config.admin.metrics_token.is_some() {
+ warn!("This Garage version is built without the metrics feature");
}
- if let Err(e) = admin_server.await? {
- warn!("Admin web server exited with error: {}", e);
- } else {
- info!("Admin API server exited without error.");
+
+ // Stuff runs
+
+ // When a cancel signal is sent, stuff stops
+
+ // Collect stuff
+ for (desc, join_handle) in servers {
+ if let Err(e) = join_handle.await? {
+ error!("{} server exited with error: {}", desc, e);
+ } else {
+ info!("{} server exited without error.", desc);
+ }
}
// Remove RPC handlers for system to break reference cycles