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]]
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",

View File

@ -1,6 +1,6 @@
[package]
name = "xesite"
version = "2.2.1"
version = "2.3.0"
authors = ["Christine Dodrill <me@christine.website>"]
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"] }

View File

@ -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)
let server = warp::serve(site);
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()))
.expect("can't parse bindhost"),
IpAddr::from_str(&std::env::var("HOST").unwrap_or("::".into()))?,
std::env::var("PORT")
.unwrap_or("3030".into())
.parse::<u16>()
.unwrap(),
.parse::<u16>()?,
))
.await;
Ok(())
}
}
}
include!(concat!(env!("OUT_DIR"), "/templates.rs"));