signal systemd readiness

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2020-12-02 14:19:28 -05:00
parent 580bca120a
commit b0a15936a9
4 changed files with 17 additions and 1 deletions

7
backend/Cargo.lock generated
View File

@ -1240,6 +1240,7 @@ dependencies = [
"rocket_prometheus", "rocket_prometheus",
"rusty_ulid", "rusty_ulid",
"scraper", "scraper",
"sdnotify",
"serde", "serde",
"serde_json", "serde_json",
"thiserror", "thiserror",
@ -2266,6 +2267,12 @@ dependencies = [
"untrusted", "untrusted",
] ]
[[package]]
name = "sdnotify"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71ce7eac2075a4562fbcbad544cd55d72ebc760e0a5594a7c8829cf2b4b42a7a"
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.22.0" version = "0.22.0"

View File

@ -25,6 +25,7 @@ rocket_cors = "0.5"
rocket_prometheus = "0.7.0" rocket_prometheus = "0.7.0"
rusty_ulid = "0.10" rusty_ulid = "0.10"
scraper = "0.12.0" scraper = "0.12.0"
sdnotify = { version = "0.1", default-features = false }
serde_json = "^1" serde_json = "^1"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
thiserror = "1" thiserror = "1"

View File

@ -6,7 +6,7 @@ extern crate rocket;
extern crate tracing; extern crate tracing;
use color_eyre::eyre::Result; use color_eyre::eyre::Result;
use rocket::http::Method; use rocket::{fairing::AdHoc, http::Method};
use rocket_contrib::helmet::SpaceHelmet; use rocket_contrib::helmet::SpaceHelmet;
use rocket_cors::{AllowedHeaders, AllowedOrigins}; use rocket_cors::{AllowedHeaders, AllowedOrigins};
use rocket_prometheus::PrometheusMetrics; use rocket_prometheus::PrometheusMetrics;
@ -58,6 +58,13 @@ fn main() -> Result<()> {
.attach(PluralKit::fairing()) .attach(PluralKit::fairing())
.attach(SwitchCounter::fairing()) .attach(SwitchCounter::fairing())
.attach(Twitter::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("/metrics", prometheus)
.mount("/", routes![botinfo]) .mount("/", routes![botinfo])
.mount( .mount(

View File

@ -37,6 +37,7 @@ let
export DATABASE_URL=./mi.db export DATABASE_URL=./mi.db
export ROCKET_DATABASES='{ main_data = { url = "./mi.db" } }'; export ROCKET_DATABASES='{ main_data = { url = "./mi.db" } }';
${composite}/bin/migrate_database ${composite}/bin/migrate_database
${composite}/bin/bridgy_migrate
export ROCKET_ASSET_PATH=${composite}/public export ROCKET_ASSET_PATH=${composite}/public
exec ${composite}/bin/mi exec ${composite}/bin/mi
''; '';