swarm-logs-auth, swarm-metrics-auth, swarm-authelia-bridge, swarm-controller: drain http on sigterm
This commit is contained in:
parent
39c29b64e3
commit
a089da25a5
2 changed files with 198 additions and 19 deletions
|
|
@ -19,6 +19,8 @@ serde.workspace = true
|
|||
serde_json.workspace = true
|
||||
serde_norway = "0.9.42"
|
||||
swarm-authelia-bridge-sock.workspace = true
|
||||
# `shutdown_signal`: the bridge drains its in-flight requests on SIGTERM.
|
||||
swarm-secret-client.workspace = true
|
||||
tokio.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ struct AppState {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let stop = swarm_secret_client::shutdown_signal();
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(
|
||||
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into()),
|
||||
|
|
@ -130,9 +131,22 @@ async fn main() -> Result<()> {
|
|||
|
||||
let listener = bind_socket(&socket)?;
|
||||
tracing::info!(socket = %socket.display(), "swarm-authelia-bridge listening");
|
||||
axum::serve(listener, app)
|
||||
serve(listener, app, stop).await
|
||||
}
|
||||
|
||||
/// Answers on `listener` until `stop` resolves, then lets the requests in hand
|
||||
/// finish, for at most the drain, and returns.
|
||||
async fn serve(
|
||||
listener: tokio::net::UnixListener,
|
||||
app: Router,
|
||||
stop: impl Future<Output = ()> + Clone + Send + 'static,
|
||||
) -> Result<()> {
|
||||
let serving = axum::serve(listener, app).with_graceful_shutdown(stop.clone());
|
||||
swarm_secret_client::serve_bounded(stop, serving.into_future())
|
||||
.await
|
||||
.context("serving swarm-authelia-bridge")
|
||||
.transpose()
|
||||
.context("serving swarm-authelia-bridge")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Bind the listening socket at `path`, replacing a stale one a crash left
|
||||
|
|
|
|||
Loading…
Reference in a new issue