Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Add graceful shutdown handler (#27)
Browse files Browse the repository at this point in the history
I rolled out the new image, saw the old took ages to kill, and realised
we hadn't setup a SIGTERM handler. Add it!
  • Loading branch information
Ellie Huxtable authored Sep 14, 2023
1 parent 1474f99 commit af529b1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions capture-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ use std::env;
use std::net::SocketAddr;

use capture::{router, sink, time};
use tokio::signal;

async fn shutdown() {
let mut term = signal::unix::signal(signal::unix::SignalKind::terminate())
.expect("failed to register SIGTERM handler");

let mut interrupt = signal::unix::signal(signal::unix::SignalKind::interrupt())
.expect("failed to register SIGINT handler");

tokio::select! {
_ = term.recv() => {},
_ = interrupt.recv() => {},
};

tracing::info!("Shutting down gracefully...");
}

#[tokio::main]
async fn main() {
Expand Down Expand Up @@ -29,6 +45,7 @@ async fn main() {

axum::Server::bind(&address.parse().unwrap())
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
.with_graceful_shutdown(shutdown())
.await
.unwrap();
}

0 comments on commit af529b1

Please sign in to comment.