add --console program option to automatically spawn
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
2fb43dd38d
commit
263e338088
3 changed files with 30 additions and 4 deletions
|
@ -330,6 +330,8 @@ pub struct Config {
|
|||
pub block_non_admin_invites: bool,
|
||||
#[serde(default = "true_fn")]
|
||||
pub admin_escape_commands: bool,
|
||||
#[serde(default)]
|
||||
pub admin_console_automatic: bool,
|
||||
|
||||
#[serde(default)]
|
||||
pub sentry: bool,
|
||||
|
@ -579,6 +581,10 @@ impl fmt::Display for Config {
|
|||
&self.block_non_admin_invites.to_string(),
|
||||
);
|
||||
line("Enable admin escape commands", &self.admin_escape_commands.to_string());
|
||||
line(
|
||||
"Activate admin console after startup",
|
||||
&self.admin_console_automatic.to_string(),
|
||||
);
|
||||
line("Allow outgoing federated typing", &self.allow_outgoing_typing.to_string());
|
||||
line("Allow incoming federated typing", &self.allow_incoming_typing.to_string());
|
||||
line(
|
||||
|
|
|
@ -12,6 +12,10 @@ pub(crate) struct Args {
|
|||
#[arg(short, long)]
|
||||
/// Optional argument to the path of a conduwuit config TOML file
|
||||
pub(crate) config: Option<PathBuf>,
|
||||
|
||||
/// Activate admin command console automatically after startup.
|
||||
#[arg(long, num_args(0))]
|
||||
pub(crate) console: bool,
|
||||
}
|
||||
|
||||
/// Parse commandline arguments into structured data
|
||||
|
@ -22,7 +26,7 @@ pub(super) fn parse() -> Args { Args::parse() }
|
|||
pub(crate) fn update(config: &mut Config, args: &Args) -> Result<()> {
|
||||
// Indicate the admin console should be spawned automatically if the
|
||||
// configuration file hasn't already.
|
||||
config.admin_console_automatic |= args.console.unwrap_or(false);
|
||||
config.admin_console_automatic |= args.console;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -82,6 +82,8 @@ impl crate::Service for Service {
|
|||
async fn worker(self: Arc<Self>) -> Result<()> {
|
||||
let receiver = self.receiver.lock().await;
|
||||
let mut signals = self.services.server.signal.subscribe();
|
||||
self.console_auto_start().await;
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
command = receiver.recv_async() => match command {
|
||||
|
@ -95,9 +97,7 @@ impl crate::Service for Service {
|
|||
}
|
||||
}
|
||||
|
||||
//TODO: not unwind safe
|
||||
#[cfg(feature = "console")]
|
||||
self.console.close().await;
|
||||
self.console_auto_stop().await; //TODO: not unwind safe
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -340,4 +340,20 @@ impl Service {
|
|||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Possibly spawn the terminal console at startup if configured.
|
||||
async fn console_auto_start(&self) {
|
||||
#[cfg(feature = "console")]
|
||||
if self.services.server.config.admin_console_automatic {
|
||||
// Allow more of the startup sequence to execute before spawning
|
||||
tokio::task::yield_now().await;
|
||||
self.console.start().await;
|
||||
}
|
||||
}
|
||||
|
||||
/// Shutdown the console when the admin worker terminates.
|
||||
async fn console_auto_stop(&self) {
|
||||
#[cfg(feature = "console")]
|
||||
self.console.close().await;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue