diff --git a/Cargo.lock b/Cargo.lock index c47a65c..11b6a9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2526,7 +2526,7 @@ checksum = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57" [[package]] name = "xesite" -version = "2.2.1" +version = "2.3.0" dependencies = [ "cfcache", "chrono", @@ -2548,7 +2548,7 @@ dependencies = [ "pfacts", "pretty_env_logger", "prometheus", - "rand 0.8.3", + "rand 0.7.3", "reqwest", "ructe", "sdnotify", @@ -2559,6 +2559,7 @@ dependencies = [ "sitemap", "thiserror", "tokio", + "tokio-stream", "tracing", "tracing-futures", "tracing-subscriber", diff --git a/Cargo.toml b/Cargo.toml index 5b07752..1d6939e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "xesite" -version = "2.2.1" +version = "2.3.0" authors = ["Christine Dodrill "] edition = "2018" build = "src/build.rs" @@ -29,6 +29,7 @@ serde_yaml = "0.8" sitemap = "0.4" thiserror = "1" tokio = { version = "1", features = ["full"] } +tokio-stream = { version = "0.1", features = ["net"] } tracing = "0.1" tracing-futures = "0.2" tracing-subscriber = { version = "0.2", features = ["fmt"] } diff --git a/src/main.rs b/src/main.rs index 054e18d..cac19cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,8 @@ use prometheus::{Encoder, TextEncoder}; use std::net::IpAddr; use std::str::FromStr; use std::sync::Arc; +use tokio::net::UnixListener; +use tokio_stream::wrappers::UnixListenerStream; use warp::{path, Filter}; pub mod app; @@ -234,18 +236,30 @@ async fn main() -> Result<()> { } } - warp::serve(site) - .run(( - IpAddr::from_str(&std::env::var("HOST").unwrap_or("::".into())) - .expect("can't parse bindhost"), - std::env::var("PORT") - .unwrap_or("3030".into()) - .parse::() - .unwrap(), - )) - .await; + let server = warp::serve(site); - Ok(()) + match std::env::var("SOCKPATH") { + Ok(sockpath) => { + let _ = std::fs::remove_file(&sockpath); + let listener = UnixListener::bind(sockpath)?; + let incoming = UnixListenerStream::new(listener); + server.run_incoming(incoming).await; + + Ok(()) + } + Err(_) => { + server + .run(( + IpAddr::from_str(&std::env::var("HOST").unwrap_or("::".into()))?, + std::env::var("PORT") + .unwrap_or("3030".into()) + .parse::()?, + )) + .await; + + Ok(()) + } + } } include!(concat!(env!("OUT_DIR"), "/templates.rs"));