support admin server restart --force

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-03 04:46:50 +00:00
commit 5edd391e83
4 changed files with 62 additions and 6 deletions
src/admin/server

View file

@ -1,4 +1,4 @@
use conduit::{warn, Result};
use conduit::{warn, Error, Result};
use ruma::events::room::message::RoomMessageEventContent;
use crate::services;
@ -102,7 +102,17 @@ pub(super) async fn reload(_body: Vec<&str>) -> Result<RoomMessageEventContent>
}
#[cfg(unix)]
pub(super) async fn restart(_body: Vec<&str>) -> Result<RoomMessageEventContent> {
pub(super) async fn restart(_body: Vec<&str>, force: bool) -> Result<RoomMessageEventContent> {
use conduit::utils::sys::current_exe_deleted;
if !force && current_exe_deleted() {
return Err(Error::Err(
"The server cannot be restarted because the executable was tampered with. If this is expected use --force \
to override."
.to_owned(),
));
}
services().server.restart()?;
Ok(RoomMessageEventContent::notice_plain("Restarting server..."))