dxps / fullstack-rust-axum-dioxus-rwa

A RealWorld app implementation as a fullstack Rust project using Axum (back-end) and Dioxus (front-end).
MIT License
79 stars 6 forks source link

[back-end cli] Gracefully restart on code changes #23

Closed dxps closed 5 months ago

dxps commented 8 months ago

While the server can gracefully shutdown if it receives the expected signal, cargo-watch does not have an option to specify which signal to send to the running (server) process, nor wait for it to shutdown (see this).

The alternative is to use watchexec.

dxps commented 5 months ago

The watchexec way works like this:

❯ watchexec --exts rs --restart -- cargo run --bin server -- --port 9091 --log debug
[Running: cargo run --bin server -- --port 9091 --log debug]
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
     Running `target/debug/server --port 9091 --log debug`
2024-02-10T19:15:42.006302Z  INFO server: The server is starting up (pid 300564) ...    
2024-02-10T19:15:42.006400Z  INFO server: Listening for requests on http://[::1]:9091 ...    
2024-02-10T19:15:53.488047Z  INFO server: Shutting down gracefully ...    
[Running: cargo run --bin server -- --port 9091 --log debug]
...