diff --git a/src/admin/mod.rs b/src/admin/mod.rs index 1832cc9b..33158b5c 100644 --- a/src/admin/mod.rs +++ b/src/admin/mod.rs @@ -1,3 +1,5 @@ +#![allow(clippy::wildcard_imports)] + pub(crate) mod appservice; pub(crate) mod debug; pub(crate) mod federation; diff --git a/src/admin/server/mod.rs b/src/admin/server/mod.rs index e591f7c5..254735a3 100644 --- a/src/admin/server/mod.rs +++ b/src/admin/server/mod.rs @@ -3,10 +3,7 @@ pub(crate) mod server_commands; use clap::Subcommand; use ruma::events::room::message::RoomMessageEventContent; -use self::server_commands::{ - backup_database, clear_database_caches, clear_service_caches, list_backups, list_database_files, memory_usage, - show_config, uptime, -}; +use self::server_commands::*; use crate::Result; #[cfg_attr(test, derive(Debug))] @@ -42,6 +39,13 @@ pub(crate) enum ServerCommand { /// - List database files ListDatabaseFiles, + + #[cfg(conduit_mods)] + /// - Hot-reload the server + Reload, + + /// - Shutdown the server + Shutdown, } pub(crate) async fn process(command: ServerCommand, body: Vec<&str>) -> Result { @@ -58,5 +62,8 @@ pub(crate) async fn process(command: ServerCommand, body: Vec<&str>) -> Result list_backups(body).await?, ServerCommand::BackupDatabase => backup_database(body).await?, ServerCommand::ListDatabaseFiles => list_database_files(body).await?, + #[cfg(conduit_mods)] + ServerCommand::Reload => reload(body).await?, + ServerCommand::Shutdown => shutdown(body).await?, }) } diff --git a/src/admin/server/server_commands.rs b/src/admin/server/server_commands.rs index d80cc3d7..c9daedc4 100644 --- a/src/admin/server/server_commands.rs +++ b/src/admin/server/server_commands.rs @@ -1,3 +1,4 @@ +use conduit::warn; use ruma::events::room::message::RoomMessageEventContent; use crate::{services, Result}; @@ -96,3 +97,17 @@ pub(crate) async fn list_database_files(_body: Vec<&str>) -> Result) -> Result { + services().server.reload()?; + + Ok(RoomMessageEventContent::notice_plain(String::new())) +} + +pub(crate) async fn shutdown(_body: Vec<&str>) -> Result { + warn!("shutdown command"); + services().server.shutdown()?; + + Ok(RoomMessageEventContent::notice_plain(String::new())) +} diff --git a/src/service/admin/console.rs b/src/service/admin/console.rs index 66faf2c1..13cfdb27 100644 --- a/src/service/admin/console.rs +++ b/src/service/admin/console.rs @@ -73,7 +73,7 @@ impl Console { #[tracing::instrument(skip_all, name = "console")] async fn worker(self: Arc) { - loop { + while services().server.running() { let mut input = self.input.lock().await; let suppression = log::Suppress::new(&services().server);