From 0e586416761ed61e8380125c3181be2effa7d50c Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 3 Nov 2023 16:11:21 -0700 Subject: [PATCH] start script for after the frontend starts --- web3_proxy/src/config.rs | 6 ++++++ web3_proxy_cli/src/sub_commands/proxyd.rs | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/web3_proxy/src/config.rs b/web3_proxy/src/config.rs index 89c1d3ec..adb3ad14 100644 --- a/web3_proxy/src/config.rs +++ b/web3_proxy/src/config.rs @@ -209,6 +209,12 @@ pub struct AppConfig { /// optional arguments for your shutdown script. pub shutdown_script_args: Vec, + /// optional script to run before shutting the frontend down. + /// this is useful for keeping load balancers happy. + pub start_script: Option, + /// optional arguments for your shutdown script. + pub start_script_args: Vec, + /// Optionally send errors to pub sentry_url: Option, diff --git a/web3_proxy_cli/src/sub_commands/proxyd.rs b/web3_proxy_cli/src/sub_commands/proxyd.rs index ab08b50f..8b0cb9fe 100644 --- a/web3_proxy_cli/src/sub_commands/proxyd.rs +++ b/web3_proxy_cli/src/sub_commands/proxyd.rs @@ -73,6 +73,8 @@ impl ProxydSubCommand { flush_stat_buffer_sender: mpsc::Sender>, flush_stat_buffer_receiver: mpsc::Receiver>, ) -> 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;