Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to modify signal used to terminate process and/or wait for shutdown? #215

Open
brownjohnf opened this issue Oct 19, 2022 · 3 comments

Comments

@brownjohnf
Copy link

I love cargo watch, and use it all the time. I'm hitting an issue now though where I need to perform some cleanup/teardown prior to shutting down the watched process (I need some syscalls to complete in order to be able to re-run the process).

Unless I'm missing something, there's no ability to add a delay or customize the shutdown signal sent to the process, is that correct? I think in a perfect world, I'd be able to send a SIGINT, wait some number of seconds, and then follow it up with a SIGKILL if the process still hadn't exited.

Apologies if I'm missing some combination of features that make this already possible. I'm also open to contributing, if this is a feature that doesn't exist but you're interested in. Thanks!

@passcod
Copy link
Member

passcod commented Oct 20, 2022

Watchexec can do most of it (send a signal, wait 60 seconds, sigkill), though there's an outstanding bug watchexec/watchexec#426 where it doesn't quite work correctly (it waits 60 seconds regardless of whether the program ends after the signal or not). Eventually that will come to cargo watch. I'm not currently working on watchexec/cargo-watch due to motivation and other projects taking precedence.

@dxps
Copy link

dxps commented Feb 10, 2024

The aforementioned watchexec issue is solved now. So, I believe cargo-watch could also properly send the termination signal to the process when restarting it due to detected changes.

Meanwhile, I just tested watchexec's behavior (since I really wanted to have my executable gracefully shutdown during development) and seems to work just fine (which for now, in my case, is the alternative to cargo watch ...):

❯ 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]

@passcod
Copy link
Member

passcod commented Feb 11, 2024

Yeah, when I upgrade cargo watch's underlying watchexec this will make it in. Unfortunately I have little time to spent on this project at the moment due to external factors... but it will happen eventually!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants