diff --git a/backend/Cargo.lock b/backend/Cargo.lock index c4ae0bb..8965b5c 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -1240,6 +1240,7 @@ dependencies = [ "rocket_prometheus", "rusty_ulid", "scraper", + "sdnotify", "serde", "serde_json", "thiserror", @@ -2266,6 +2267,12 @@ dependencies = [ "untrusted", ] +[[package]] +name = "sdnotify" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71ce7eac2075a4562fbcbad544cd55d72ebc760e0a5594a7c8829cf2b4b42a7a" + [[package]] name = "selectors" version = "0.22.0" diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 443d1bf..8ec21aa 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -25,6 +25,7 @@ rocket_cors = "0.5" rocket_prometheus = "0.7.0" rusty_ulid = "0.10" scraper = "0.12.0" +sdnotify = { version = "0.1", default-features = false } serde_json = "^1" serde = { version = "1", features = ["derive"] } thiserror = "1" diff --git a/backend/src/main.rs b/backend/src/main.rs index 4e64350..9a65a7c 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -6,7 +6,7 @@ extern crate rocket; extern crate tracing; use color_eyre::eyre::Result; -use rocket::http::Method; +use rocket::{fairing::AdHoc, http::Method}; use rocket_contrib::helmet::SpaceHelmet; use rocket_cors::{AllowedHeaders, AllowedOrigins}; use rocket_prometheus::PrometheusMetrics; @@ -58,6 +58,13 @@ fn main() -> Result<()> { .attach(PluralKit::fairing()) .attach(SwitchCounter::fairing()) .attach(Twitter::fairing()) + .attach(AdHoc::on_launch("systemd readiness", |_| { + if let Ok(ref mut n) = sdnotify::SdNotify::from_env() { + let _ = n + .notify_ready() + .map_err(|why| error!("can't signal readiness to systemd: {}", why)); + } + })) .mount("/metrics", prometheus) .mount("/", routes![botinfo]) .mount( diff --git a/default.nix b/default.nix index 5d9d07a..b83983b 100644 --- a/default.nix +++ b/default.nix @@ -37,6 +37,7 @@ let export DATABASE_URL=./mi.db export ROCKET_DATABASES='{ main_data = { url = "./mi.db" } }'; ${composite}/bin/migrate_database + ${composite}/bin/bridgy_migrate export ROCKET_ASSET_PATH=${composite}/public exec ${composite}/bin/mi '';