diff --git a/src/cli/serve.rs b/src/cli/serve.rs
index ab65396b..79a55482 100644
--- a/src/cli/serve.rs
+++ b/src/cli/serve.rs
@@ -47,7 +47,7 @@ use crate::{
self,
error::{Error, Result},
},
- Services, SERVICES,
+ Services,
};
pub(crate) async fn run(args: ServeArgs) -> Result<(), error::ServeCommand> {
@@ -78,11 +78,9 @@ pub(crate) async fn run(args: ServeArgs) -> Result<(), error::ServeCommand> {
.map_err(Error::DatabaseError)?,
));
- // This is the first and only time we initialize the SERVICE static
- *SERVICES.write().unwrap() = Some(Box::leak(Box::new(
- Services::build(db, config, reload_handles)
- .map_err(Error::InitializeServices)?,
- )));
+ Services::build(db, config, reload_handles)
+ .map_err(Error::InitializeServices)?
+ .install();
services().globals.err_if_server_name_changed()?;
diff --git a/src/main.rs b/src/main.rs
index 080b9714..903906a6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,7 +2,7 @@
// work anyway
#![cfg_attr(not(any(feature = "sqlite", feature = "rocksdb")), allow(unused))]
-use std::{process::ExitCode, sync::RwLock};
+use std::process::ExitCode;
use clap::Parser;
use tracing::error;
@@ -18,7 +18,7 @@ mod utils;
pub(crate) use api::ruma_wrapper::{Ar, Ra};
pub(crate) use config::Config;
-pub(crate) use service::{pdu::PduEvent, Services};
+pub(crate) use service::{pdu::PduEvent, services, Services};
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
use tikv_jemallocator::Jemalloc;
pub(crate) use utils::error::{Error, Result};
@@ -27,17 +27,6 @@ pub(crate) use utils::error::{Error, Result};
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
-pub(crate) static SERVICES: RwLock