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
parent 7658387a74
commit 5edd391e83
4 changed files with 62 additions and 6 deletions

View file

@ -2,10 +2,20 @@
use std::{env, os::unix::process::CommandExt, process::Command};
use conduit::{debug, info};
use conduit::{debug, info, utils};
pub(super) fn restart() -> ! {
let exe = env::current_exe().expect("program path must be identified and available");
// SAFETY: We have allowed an override for the case where the current_exe() has
// been replaced or removed. By default the server will fail to restart if the
// binary has been replaced (i.e. by cargo); this is for security purposes.
// Command::exec() used to panic in that case.
//
// We can (and do) prevent that panic by checking the result of current_exe()
// prior to committing to restart, returning an error to the user without any
// unexpected shutdown. In a nutshell that is the execuse for this unsafety.
// Nevertheless, we still want a way to override the restart preventation (i.e.
// admin server restart --force).
let exe = unsafe { utils::sys::current_exe().expect("program path must be available") };
let envs = env::vars();
let args = env::args().skip(1);
debug!(?exe, ?args, ?envs, "Restart");