start script for after the frontend starts

This commit is contained in:
Bryan Stitt 2023-11-03 16:11:21 -07:00
parent 77253ba231
commit 0e58641676
2 changed files with 23 additions and 1 deletions

@ -209,6 +209,12 @@ pub struct AppConfig {
/// optional arguments for your shutdown script.
pub shutdown_script_args: Vec<String>,
/// optional script to run before shutting the frontend down.
/// this is useful for keeping load balancers happy.
pub start_script: Option<String>,
/// optional arguments for your shutdown script.
pub start_script_args: Vec<String>,
/// Optionally send errors to <https://sentry.io>
pub sentry_url: Option<Dsn>,

@ -73,6 +73,8 @@ impl ProxydSubCommand {
flush_stat_buffer_sender: mpsc::Sender<oneshot::Sender<FlushedStats>>,
flush_stat_buffer_receiver: mpsc::Receiver<oneshot::Sender<FlushedStats>>,
) -> anyhow::Result<()> {
let mut terminate_stream = signal::unix::signal(SignalKind::terminate())?;
// tokio has code for catching ctrl+c so we use that to shut down in most cases
// frontend_shutdown_sender is currently only used in tests, but we might make a /shutdown endpoint or something
// we do not need this receiver. new receivers are made by `shutdown_sender.subscribe()`
@ -192,7 +194,21 @@ impl ProxydSubCommand {
frontend_shutdown_complete_sender,
));
let mut terminate_stream = signal::unix::signal(SignalKind::terminate())?;
if let Some(start_script) = spawned_app.app.config.start_script.as_ref() {
let start_script = Command::new(start_script)
.args(&app.config.start_script_args)
.spawn()
.expect("failed to execute script");
match start_script.wait_with_output().await {
Ok(x) => {
info!(?x, "start script finished");
}
Err(err) => {
error!(?err, "start script failed");
}
};
}
// if everything is working, these should all run forever
let mut exited_with_err = false;