Browse Source

added option to run it in background.

Signed-off-by: Karan Gauswami <[email protected]>
pull/30/head
Karan Gauswami 4 months ago
parent
commit
d01a49fff0
No known key found for this signature in database GPG Key ID: 4457EA801DBC82E6
  1. 10
      Cargo.lock
  2. 1
      Cargo.toml
  3. 13
      src/main.rs

10
Cargo.lock

@ -231,6 +231,15 @@ version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "daemonize"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab8bfdaacb3c887a54d41bdf48d3af8873b3f5566469f8ba21b92057509f116e"
dependencies = [
"libc",
]
[[package]]
name = "derive-try-from-primitive"
version = "1.0.0"
@ -1257,6 +1266,7 @@ dependencies = [
"bytes",
"clap",
"color-eyre",
"daemonize",
"http-body-util",
"hyper",
"hyper-util",

1
Cargo.toml

@ -22,6 +22,7 @@ tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
hyper-util = { version="0.1.5",features = ["tokio"] }
base64 = "0.22.1"
daemonize = "0.5.0"
[dev-dependencies]
socksprox = { version = "0.1" }

13
src/main.rs

@ -10,6 +10,7 @@ use std::net::{IpAddr, SocketAddr, ToSocketAddrs};
use base64::engine::general_purpose;
use base64::Engine;
use daemonize::Daemonize;
use hyper::header::HeaderValue;
use tokio::net::TcpListener;
@ -55,6 +56,10 @@ struct Cli {
/// HTTP Basic Auth credentials in the format "user:passwd"
#[arg(long)]
http_basic: Option<String>,
/// Run process in background
#[arg(short, long, default_value_t = false)]
detached: bool,
}
#[tokio::main]
@ -82,6 +87,14 @@ async fn main() -> Result<()> {
let http_basic = &*Box::leak(Box::new(http_basic));
let listener = TcpListener::bind(addr).await?;
let daemonize = Daemonize::new();
if args.detached {
if let Err(e) = daemonize.start() {
eprintln!("Error: {}", e);
}
}
info!("Listening on http://{}", addr);
loop {

Loading…
Cancel
Save