Skip to content

Commit

Permalink
Add graceful shutdown on SIGTERM (#1014)
Browse files Browse the repository at this point in the history
* Add graceful shutdown on SIGTERM

* Fix linter
  • Loading branch information
InCogNiTo124 committed May 30, 2023
1 parent 9e3fa8b commit 5dc189c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions atuin-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use eyre::{Context, Result};

use crate::settings::Settings;

use tokio::signal;

pub mod auth;
pub mod calendar;
pub mod database;
Expand All @@ -17,6 +19,20 @@ pub mod router;
pub mod settings;
pub mod utils;

async fn shutdown_signal() {
let terminate = async {
signal::unix::signal(signal::unix::SignalKind::terminate())
.expect("failed to register signal handler")
.recv()
.await;
};

tokio::select! {
_ = terminate => (),
}
eprintln!("Shutting down gracefully...");
}

pub async fn launch(settings: Settings, host: String, port: u16) -> Result<()> {
let host = host.parse::<IpAddr>()?;

Expand All @@ -28,6 +44,7 @@ pub async fn launch(settings: Settings, host: String, port: u16) -> Result<()> {

Server::bind(&SocketAddr::new(host, port))
.serve(r.into_make_service())
.with_graceful_shutdown(shutdown_signal())
.await?;

Ok(())
Expand Down

1 comment on commit 5dc189c

@vercel
Copy link

@vercel vercel bot commented on 5dc189c May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

atuin – ./

atuin-git-main-ellieh.vercel.app
atuin-ellieh.vercel.app
atuin.sh

Please sign in to comment.