curl
systemfd
=>cargo install systemfd
- Comment out this line in
main.rs
:
std_listener.set_nonblocking(true).expect("Failed to set non-blocking mode");
to
// std_listener.set_nonblocking(true).expect("Failed to set non-blocking mode");
- Build
cargo build
- Run with systemfd
systemfd -s http::5000 -- ./target/debug/tonic-graceful-shutdown
(Replace http port with another value if that port is already used on your system)
- Make a request with curl
curl localhost:5000
- Attempt to shut down the server with pkill
pkill -SIGINT tonic
Notice that the server does not shut down.
- Kill the process
pkill -SIGKILL tonic
- Uncomment this line in
main.rs
:
// std_listener.set_nonblocking(true).expect("Failed to set non-blocking mode");
to
std_listener.set_nonblocking(true).expect("Failed to set non-blocking mode");
- Build
cargo build
- Run with systemfd
systemfd -s http::5000 -- ./target/debug/tonic-graceful-shutdown
(Replace http port with another value if that port is already used on your system)
- Make a request with curl
curl localhost:5000
- Attempt to shut down the server with pkill
pkill -SIGINT tonic
Notice that the server shuts down properly.