admin commands for shutdown/reload
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
08f2b8579c
commit
3d3d63fdf4
4 changed files with 29 additions and 5 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
#![allow(clippy::wildcard_imports)]
|
||||||
|
|
||||||
pub(crate) mod appservice;
|
pub(crate) mod appservice;
|
||||||
pub(crate) mod debug;
|
pub(crate) mod debug;
|
||||||
pub(crate) mod federation;
|
pub(crate) mod federation;
|
||||||
|
|
|
@ -3,10 +3,7 @@ pub(crate) mod server_commands;
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use ruma::events::room::message::RoomMessageEventContent;
|
use ruma::events::room::message::RoomMessageEventContent;
|
||||||
|
|
||||||
use self::server_commands::{
|
use self::server_commands::*;
|
||||||
backup_database, clear_database_caches, clear_service_caches, list_backups, list_database_files, memory_usage,
|
|
||||||
show_config, uptime,
|
|
||||||
};
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
|
||||||
#[cfg_attr(test, derive(Debug))]
|
#[cfg_attr(test, derive(Debug))]
|
||||||
|
@ -42,6 +39,13 @@ pub(crate) enum ServerCommand {
|
||||||
|
|
||||||
/// - List database files
|
/// - List database files
|
||||||
ListDatabaseFiles,
|
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> {
|
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::ListBackups => list_backups(body).await?,
|
||||||
ServerCommand::BackupDatabase => backup_database(body).await?,
|
ServerCommand::BackupDatabase => backup_database(body).await?,
|
||||||
ServerCommand::ListDatabaseFiles => list_database_files(body).await?,
|
ServerCommand::ListDatabaseFiles => list_database_files(body).await?,
|
||||||
|
#[cfg(conduit_mods)]
|
||||||
|
ServerCommand::Reload => reload(body).await?,
|
||||||
|
ServerCommand::Shutdown => shutdown(body).await?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use conduit::warn;
|
||||||
use ruma::events::room::message::RoomMessageEventContent;
|
use ruma::events::room::message::RoomMessageEventContent;
|
||||||
|
|
||||||
use crate::{services, Result};
|
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()?;
|
let result = services().globals.db.file_list()?;
|
||||||
Ok(RoomMessageEventContent::notice_html(String::new(), result))
|
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()))
|
||||||
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ impl Console {
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, name = "console")]
|
#[tracing::instrument(skip_all, name = "console")]
|
||||||
async fn worker(self: Arc<Self>) {
|
async fn worker(self: Arc<Self>) {
|
||||||
loop {
|
while services().server.running() {
|
||||||
let mut input = self.input.lock().await;
|
let mut input = self.input.lock().await;
|
||||||
|
|
||||||
let suppression = log::Suppress::new(&services().server);
|
let suppression = log::Suppress::new(&services().server);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue