admin commands for shutdown/reload

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-06-16 01:44:41 +00:00
parent 08f2b8579c
commit 3d3d63fdf4
4 changed files with 29 additions and 5 deletions

View file

@ -1,3 +1,5 @@
#![allow(clippy::wildcard_imports)]
pub(crate) mod appservice;
pub(crate) mod debug;
pub(crate) mod federation;

View file

@ -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<RoomMessageEventContent> {
@ -58,5 +62,8 @@ pub(crate) async fn process(command: ServerCommand, body: Vec<&str>) -> Result<R
ServerCommand::ListBackups => 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?,
})
}

View file

@ -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<RoomMessageE
let result = services().globals.db.file_list()?;
Ok(RoomMessageEventContent::notice_html(String::new(), result))
}
#[cfg(conduit_mods)]
pub(crate) async fn reload(_body: Vec<&str>) -> Result<RoomMessageEventContent> {
services().server.reload()?;
Ok(RoomMessageEventContent::notice_plain(String::new()))
}
pub(crate) async fn shutdown(_body: Vec<&str>) -> Result<RoomMessageEventContent> {
warn!("shutdown command");
services().server.shutdown()?;
Ok(RoomMessageEventContent::notice_plain(String::new()))
}

View file

@ -73,7 +73,7 @@ impl Console {
#[tracing::instrument(skip_all, name = "console")]
async fn worker(self: Arc<Self>) {
loop {
while services().server.running() {
let mut input = self.input.lock().await;
let suppression = log::Suppress::new(&services().server);