enable unix socket powers

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-04-01 19:51:28 -04:00
parent adb0ebccf1
commit a6063676d3
3 changed files with 30 additions and 14 deletions

5
Cargo.lock generated
View File

@ -2526,7 +2526,7 @@ checksum = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57"
[[package]] [[package]]
name = "xesite" name = "xesite"
version = "2.2.1" version = "2.3.0"
dependencies = [ dependencies = [
"cfcache", "cfcache",
"chrono", "chrono",
@ -2548,7 +2548,7 @@ dependencies = [
"pfacts", "pfacts",
"pretty_env_logger", "pretty_env_logger",
"prometheus", "prometheus",
"rand 0.8.3", "rand 0.7.3",
"reqwest", "reqwest",
"ructe", "ructe",
"sdnotify", "sdnotify",
@ -2559,6 +2559,7 @@ dependencies = [
"sitemap", "sitemap",
"thiserror", "thiserror",
"tokio", "tokio",
"tokio-stream",
"tracing", "tracing",
"tracing-futures", "tracing-futures",
"tracing-subscriber", "tracing-subscriber",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "xesite" name = "xesite"
version = "2.2.1" version = "2.3.0"
authors = ["Christine Dodrill <me@christine.website>"] authors = ["Christine Dodrill <me@christine.website>"]
edition = "2018" edition = "2018"
build = "src/build.rs" build = "src/build.rs"
@ -29,6 +29,7 @@ serde_yaml = "0.8"
sitemap = "0.4" sitemap = "0.4"
thiserror = "1" thiserror = "1"
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
tokio-stream = { version = "0.1", features = ["net"] }
tracing = "0.1" tracing = "0.1"
tracing-futures = "0.2" tracing-futures = "0.2"
tracing-subscriber = { version = "0.2", features = ["fmt"] } tracing-subscriber = { version = "0.2", features = ["fmt"] }

View File

@ -7,6 +7,8 @@ use prometheus::{Encoder, TextEncoder};
use std::net::IpAddr; use std::net::IpAddr;
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
use tokio::net::UnixListener;
use tokio_stream::wrappers::UnixListenerStream;
use warp::{path, Filter}; use warp::{path, Filter};
pub mod app; pub mod app;
@ -234,18 +236,30 @@ async fn main() -> Result<()> {
} }
} }
warp::serve(site) let server = 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::<u16>()
.unwrap(),
))
.await;
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::<u16>()?,
))
.await;
Ok(())
}
}
} }
include!(concat!(env!("OUT_DIR"), "/templates.rs")); include!(concat!(env!("OUT_DIR"), "/templates.rs"));