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

Add option to send different signal to child on graceful exit (e.g. sending SIGTERM on SIGINT) #151

Closed
alex88 opened this issue Apr 22, 2020 · 9 comments
Labels
new feature Requests or requires a new feature

Comments

@alex88
Copy link

alex88 commented Apr 22, 2020

First of all a lot for this nice tool!
I'm using it to re-run an elixir script so when I change something it restarts the command.

When I save a file watchexec correctly uses SIGTERM to shutdown the process, when I do ctrl-c instead the child receives INT which by default makes the elixir script pause its execution and show a few commands.

For example:

➜ simulator git:(master) ✗ mix run --no-halt
19:25:45.904 [info]  Starting simulator^C # <-- CTRL-C here
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
       (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution
^C # <-- CTRL-C again makes the script to exit

➜ simulator git:(master) ✗ mix run --no-halt
19:25:50.452 [info]  Starting simulator
19:25:56.459 [info]  Checking for new content...
19:25:57.345 [info]  SIGTERM received - shutting down # <-- this is with a killall

when I run it via watchexec isntead:

➜ simulator git:(master) ✗ watchexec -r -- mix run --no-halt                                   
19:26:15.108 [info]  Starting simulator
19:26:16.110 [info]  Checking for new content...
19:26:17.111 [info]  Checking for new content...^C # <-- this CTRL-C terminates watchexec and shows the debug commands in the child 
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
       (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution

➜ simulator git:(master) ✗ # <-- If I type c here the child continues in the background while I still have a shell
19:26:19.128 [info]  Checking for new content...
19:26:20.129 [info]  Checking for new content...
19:26:21.130 [info]  Checking for new content...
➜ simulator git:(master) ✗ 
19:26:22.131 [info]  Checking for new content...
19:26:23.132 [info]  Checking for new content...

is it an expected behavior? Maybe it would make sense to add an option to send sigterm on watchexec exit or?

@passcod
Copy link
Member

passcod commented Apr 22, 2020

See the --signal option

@passcod passcod closed this as completed Apr 22, 2020
@passcod
Copy link
Member

passcod commented Apr 22, 2020

Oh wait

@passcod passcod reopened this Apr 22, 2020
@alex88
Copy link
Author

alex88 commented Apr 22, 2020

Signal does work on file change btw

@passcod
Copy link
Member

passcod commented Apr 22, 2020

I feel like if you're telling the process to continue and it continues it shouldn't be terribly surprising. But we can certainly see about adding a way to customise the signal on exit.

@passcod passcod added this to the Command runtime improvements milestone Apr 22, 2020
@passcod passcod added the new feature Requests or requires a new feature label Apr 22, 2020
@passcod passcod changed the title Child keeps running after ctrl-c makes watchexec terminate Add option to send different signal to child on graceful exit (e.g. sending SIGTERM on SIGINT) Apr 22, 2020
@alex88
Copy link
Author

alex88 commented Apr 22, 2020

I feel like if you're telling the process to continue and it continues it shouldn't be terribly surprising. But we can certainly see about adding a way to customise the signal on exit.

you mean the "If I type c here the child continues in the background" part?
That was just to show that the program is actually still alive after watchexec exits. I thought that watchexec would send the same signal it's configured to send when a file changes and the child is still running also on watchexec termination.

(thanks for fixing the title)

@passcod
Copy link
Member

passcod commented Apr 22, 2020

nah, it just passes the signal along in the normal unix fashion

@alex88
Copy link
Author

alex88 commented Apr 22, 2020

Btw in the meantime I've found that option -n, --no-shell works because the child process not finding itself in a shell doesn't prompt anything before terminating

@MrFoxPro
Copy link

Right now process just dies and it's impossible to capture this event
Can watchexec just pass the same signal to kill process?

@passcod
Copy link
Member

passcod commented Dec 9, 2023

This is now possible with a combination of --stop-signal and --map-signal depending on the behaviour you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Requests or requires a new feature
Projects
None yet
Development

No branches or pull requests

3 participants