From 951542ccf26c1089c24100f0ff1208981979c841 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sat, 2 Jan 2021 18:11:18 -0500 Subject: systemdify this Signed-off-by: Christine Dodrill --- src/build.rs | 5 ++++- src/main.rs | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/build.rs b/src/build.rs index 3b73241..0d8d5a5 100644 --- a/src/build.rs +++ b/src/build.rs @@ -4,7 +4,10 @@ use std::process::Command; fn main() -> Result<()> { Ructe::from_env()?.compile_templates("templates")?; - let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().unwrap(); + let output = Command::new("git") + .args(&["rev-parse", "HEAD"]) + .output() + .unwrap(); let git_hash = String::from_utf8(output.stdout).unwrap(); println!("cargo:rustc-env=GITHUB_SHA={}", git_hash); Ok(()) diff --git a/src/main.rs b/src/main.rs index 0baaeef..0d3b1ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +#[macro_use] +extern crate tracing; + use color_eyre::eyre::Result; use hyper::{header::CONTENT_TYPE, Body, Response}; use prometheus::{Encoder, TextEncoder}; @@ -24,7 +27,7 @@ async fn main() -> Result<()> { color_eyre::install()?; let _ = kankyo::init(); tracing_subscriber::fmt::init(); - log::info!("starting up commit {}", env!("GITHUB_SHA")); + info!("starting up commit {}", env!("GITHUB_SHA")); let state = Arc::new( app::init( @@ -161,7 +164,21 @@ async fn main() -> Result<()> { .with(warp::log(APPLICATION_NAME)) .recover(handlers::rejection); - warp::serve(site).run(([0, 0, 0, 0], 3030)).await; + 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)); + } + + warp::serve(site) + .run(( + [0, 0, 0, 0], + std::env::var("PORT") + .unwrap_or("3030".into()) + .parse::() + .unwrap(), + )) + .await; Ok(()) } -- cgit v1.2.3