Stop cleanly on SIGTERM and keep the app out of the image build
In a container the server is process 1, which gets no default signal handling, so podman stop waited 10 s and killed it. The android folder no longer goes into the build context. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mcrates/server/src/main.rs
@@ -453,10 +453,21 @@ async fn serve(cli: Cli, db: Connection) {
listener,
app.into_make_service_with_connect_info::<std::net::SocketAddr>(),
)
.with_graceful_shutdown(shutdown())
.await
.expect("serve");
}
/// In a container the server is process 1, which gets no default signal handling. Without this, `podman stop` waits 10 s and kills it.
async fn shutdown() {
let mut term = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
.expect("SIGTERM handler");
tokio::select! {
_ = term.recv() => {}
_ = tokio::signal::ctrl_c() => {}
}
}
/// The days of points to keep for a user, or None for forever.
pub fn effective_retention(user_days: Option<i64>, max_days: i64) -> Option<i64> {
match (user_days, max_days) {