|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
use std::fs::{self, Permissions}; |
|
|
|
|
use std::os::unix::prelude::PermissionsExt; |
|
|
|
|
//use std::fs::{self, Permissions};
|
|
|
|
|
//use std::os::unix::prelude::PermissionsExt;
|
|
|
|
|
use std::{convert::Infallible, sync::Arc}; |
|
|
|
|
|
|
|
|
|
use futures::future::Future; |
|
|
|
@ -11,9 +11,9 @@ use hyper::{ |
|
|
|
|
Body, Method, Request, Response, Server, StatusCode, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
use hyperlocal::UnixServerExt; |
|
|
|
|
//use hyperlocal::UnixServerExt;
|
|
|
|
|
|
|
|
|
|
use tokio::net::UnixStream; |
|
|
|
|
//use tokio::net::UnixStream;
|
|
|
|
|
|
|
|
|
|
use opentelemetry::{ |
|
|
|
|
global, |
|
|
|
@ -100,18 +100,18 @@ impl WebServer { |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
let unix_service = make_service_fn(|_: &UnixStream| { |
|
|
|
|
let web_server = web_server.clone(); |
|
|
|
|
//let unix_service = make_service_fn(|_: &UnixStream| {
|
|
|
|
|
// let web_server = web_server.clone();
|
|
|
|
|
|
|
|
|
|
let path = addr.to_string(); |
|
|
|
|
async move { |
|
|
|
|
Ok::<_, Error>(service_fn(move |req: Request<Body>| { |
|
|
|
|
let web_server = web_server.clone(); |
|
|
|
|
|
|
|
|
|
web_server.handle_request(req, path.clone()) |
|
|
|
|
})) |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
// let path = addr.to_string();
|
|
|
|
|
// async move {
|
|
|
|
|
// remove_unix_socket_if_present(&path).await.expect("could not remove existing unix socket");
|
|
|
|
|
// Ok::<_, Error>(service_fn(move |req: Request<Body>| {
|
|
|
|
|
// let web_server = web_server.clone();
|
|
|
|
|
// web_server.handle_request(req, path.clone())
|
|
|
|
|
// }))
|
|
|
|
|
// }
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
info!("Web server listening on {}", addr); |
|
|
|
|
|
|
|
|
@ -122,20 +122,22 @@ impl WebServer { |
|
|
|
|
.with_graceful_shutdown(shutdown_signal) |
|
|
|
|
.await? |
|
|
|
|
} |
|
|
|
|
UnixOrTCPSocketAddress::UnixSocket(ref path) => { |
|
|
|
|
if path.exists() { |
|
|
|
|
fs::remove_file(path)? |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let bound = Server::bind_unix(path)?; |
|
|
|
|
|
|
|
|
|
fs::set_permissions(path, Permissions::from_mode(0o222))?; |
|
|
|
|
|
|
|
|
|
bound |
|
|
|
|
.serve(unix_service) |
|
|
|
|
.with_graceful_shutdown(shutdown_signal) |
|
|
|
|
.await?; |
|
|
|
|
} |
|
|
|
|
UnixOrTCPSocketAddress::UnixSocket(_path) => { |
|
|
|
|
panic!("Unix sockets are not supported in this fork") // TODO(mediocregopher)
|
|
|
|
|
} //UnixOrTCPSocketAddress::UnixSocket(ref path) => {
|
|
|
|
|
// if path.exists() {
|
|
|
|
|
// fs::remove_file(path)?
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// let bound = Server::bind_unix(path)?;
|
|
|
|
|
|
|
|
|
|
// fs::set_permissions(path, Permissions::from_mode(0o222))?;
|
|
|
|
|
|
|
|
|
|
// bound
|
|
|
|
|
// .serve(unix_service)
|
|
|
|
|
// .with_graceful_shutdown(shutdown_signal)
|
|
|
|
|
// .await?;
|
|
|
|
|
//}
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|