blob: aa2250d3585fe484245cd56e12abf73643539097 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#![forbid(unsafe_code)]
use std::net::{IpAddr, SocketAddr};
use atuin_server_database::Database;
use axum::Server;
use eyre::{Context, Result};
mod handlers;
mod router;
mod settings;
mod utils;
pub use settings::Settings;
use tokio::signal;
async fn shutdown_signal() {
signal::unix::signal(signal::unix::SignalKind::terminate())
.expect("failed to register signal handler")
.recv()
.await;
eprintln!("Shutting down gracefully...");
}
pub async fn launch<Db: Database>(
settings: Settings<Db::Settings>,
host: String,
port: u16,
) -> Result<()> {
let host = host.parse::<IpAddr>()?;
let db = Db::new(&settings.db_settings)
.await
.wrap_err_with(|| format!("failed to connect to db: {:?}", settings.db_settings))?;
let r = router::router(db, settings);
Server::bind(&SocketAddr::new(host, port))
.serve(r.into_make_service())
.with_graceful_shutdown(shutdown_signal())
.await?;
Ok(())
}
|