add --console program option to automatically spawn

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-22 21:21:44 +00:00
parent 2fb43dd38d
commit 263e338088
3 changed files with 30 additions and 4 deletions

View file

@ -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;
}
}