shut down on ctrl+c
All checks were successful
Build Multiarch Container Image / call-reusable-workflow (push) Successful in 36m34s

This commit is contained in:
Sebastian Hugentobler 2024-07-10 20:56:48 +02:00
parent f568c9695b
commit 402b8e3a57
Signed by: shu
GPG Key ID: BB32CF3CA052C2F0
5 changed files with 28 additions and 9 deletions

10
Cargo.lock generated
View File

@ -2684,6 +2684,15 @@ dependencies = [
"lazy_static", "lazy_static",
] ]
[[package]]
name = "signal-hook-registry"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "signature" name = "signature"
version = "2.2.0" version = "2.2.0"
@ -3164,6 +3173,7 @@ dependencies = [
"mio", "mio",
"num_cpus", "num_cpus",
"pin-project-lite", "pin-project-lite",
"signal-hook-registry",
"socket2 0.5.7", "socket2 0.5.7",
"tokio-macros", "tokio-macros",
"windows-sys 0.48.0", "windows-sys 0.48.0",

View File

@ -1,6 +1,6 @@
FROM docker.io/rust:1-alpine3.20 AS builder FROM docker.io/rust:1-alpine3.20 AS builder
RUN mkdir /tmp/tmp RUN mkdir /db
RUN echo "hesinde:x:2222:2222:Linux User,,,:/:/app" > /passwd RUN echo "hesinde:x:2222:2222:Linux User,,,:/:/app" > /passwd
RUN apk --no-cache add \ RUN apk --no-cache add \
@ -20,10 +20,10 @@ FROM scratch
COPY --from=builder /passwd /etc/passwd COPY --from=builder /passwd /etc/passwd
COPY --from=builder /app /app COPY --from=builder /app /app
COPY --from=builder --chown=2222: /tmp/tmp /tmp COPY --from=builder --chown=2222: /db /db
USER hesinde USER hesinde
CMD ["/app", "--address", "[::]:3000"] ENTRYPOINT ["/app", "--address", "[::]:3000"]
EXPOSE 3000 EXPOSE 3000
VOLUME ["/db"]

View File

@ -17,7 +17,7 @@ sea-orm = { workspace = true, features = ["with-time", "sqlx-sqlite", "sqlx-post
serde = { workspace = true, features = ["derive"] } serde = { workspace = true, features = ["derive"] }
thiserror = "1.0.61" thiserror = "1.0.61"
time = { workspace = true, features = ["macros", "serde", "formatting", "parsing" ] } time = { workspace = true, features = ["macros", "serde", "formatting", "parsing" ] }
tokio = { version = "1.38.0", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.38.0", features = ["macros", "rt-multi-thread", "signal"] }
tracing = "0.1.40" tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
uuid = { version = "1.10.0", features = ["v4", "fast-rng"] } uuid = { version = "1.10.0", features = ["v4", "fast-rng"] }

View File

@ -12,6 +12,8 @@ use poem::{
}; };
use poem_openapi::OpenApiService; use poem_openapi::OpenApiService;
use std::sync::Arc; use std::sync::Arc;
use tokio::signal;
use tracing::info;
pub mod api; pub mod api;
pub mod app_state; pub mod app_state;
@ -43,7 +45,13 @@ pub async fn run(args: &Config, db_url: &str) -> Result<()> {
.data(app_state) .data(app_state)
.with(Tracing); .with(Tracing);
Ok(poem::Server::new(TcpListener::bind(&args.address)) let server = poem::Server::new(TcpListener::bind(&args.address)).run(app);
.run(app)
.await?) tokio::select! {
_ = server => {},
_ = signal::ctrl_c() => {
info!("Received Ctrl+C, shutting down...");
},
}
Ok(())
} }

View File

@ -15,8 +15,9 @@ async fn main() -> Result<()> {
tracing_subscriber::fmt::init(); tracing_subscriber::fmt::init();
let args = Config::parse(); let args = Config::parse();
println!("{}", args.allow_registration); println!("{}", args.db_connection);
let db_url = read_db_url(&args.db_connection)?; let db_url = read_db_url(&args.db_connection)?;
println!("{db_url}");
hesinde_sync::run(&args, &db_url).await hesinde_sync::run(&args, &db_url).await
} }