diff --git a/Cargo.lock b/Cargo.lock index 6653a6e..ae472fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,6 +47,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" +[[package]] +name = "cc" +version = "1.0.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" + [[package]] name = "cfg-if" version = "1.0.0" @@ -81,6 +87,16 @@ dependencies = [ "vec_map", ] +[[package]] +name = "ctrlc" +version = "3.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "232295399409a8b7ae41276757b5a1cc21032848d42bff2352261f958b3ca29a" +dependencies = [ + "nix", + "winapi", +] + [[package]] name = "dynfmt" version = "0.1.5" @@ -344,6 +360,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "nix" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", +] + [[package]] name = "ntapi" version = "0.3.6" @@ -394,6 +422,7 @@ version = "0.1.0" dependencies = [ "chrono", "clap", + "ctrlc", "dynfmt", "env_logger", "hyper", diff --git a/Cargo.toml b/Cargo.toml index 2506f01..c1b3cd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,3 +27,6 @@ env_logger = "~0.8.3" # Server hyper = { version = "~0.14", features = ["http1", "http2", "server", "runtime"] } tokio = { version = "~1", features = ["full"] } + +# SIGTERM handling for the container image +ctrlc = { version = "~3.1.9", features = ["termination"] } diff --git a/README.md b/README.md index 6acfc2a..b519d27 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,13 @@ Easily create a PAC file from a TOML config. You can generate a PAC file from a TOML file using the latest stable pacgen Docker image: ```shell -cat pac.toml | docker run --rm -i ghcr.io/kjagiello/pacgen:latest - +docker run --rm -it -v $(pwd)/your-proxy.toml:/proxy.toml pacgen proxy.toml ``` You can also serve this file (the HTTP server binds by default at `127.0.0.1:8000`): ```shell -cat pac.toml | docker run --rm -i ghcr.io/kjagiello/pacgen:latest -s - +docker run --rm -it -v $(pwd)/your-proxy.toml:/proxy.toml pacgen -s proxy.toml ``` ### CLI documentation diff --git a/src/cli.rs b/src/cli.rs index a80268e..96fc9f7 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -116,6 +116,12 @@ pub fn main() -> io::Result<()> { }) }; + // Setup a SIGTERM handler + ctrlc::set_handler(move || { + process::exit(1); + }) + .expect("Error setting Ctrl-C handler"); + let config = ServerConfig { addr, pac }; serve(config); } else {