Skip to content

Commit

Permalink
Handle SIGTERM in the container (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjagiello authored May 23, 2021
1 parent 6074596 commit 6f7e6d4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6f7e6d4

Please sign in to comment.