Server: catch SIGTERM and SIGINT to terminate nicely
Now that the server is multiprocessed comes the question of the termination of worker processes upon signal received by the main process.
-
SIGINT
: the main process quits (with theKeyboardInterrupt
exception), the worker process are unaffected and end up adopted. -
SIGTERM
: ignored by the main process. -
SIGKILL
(for the record): the main process dies immediately, the worker process are unaffected and adopted.
Noticed because I had hundreds or HGitaly worker processes after some intense and parallel runs of the Rails app tests, as these launch a dedicated HGitaly server and terminate it with SIGKILL
(soon will be changed of course to SIGTERM
).
Side note: if a worker process receives SIGTERM
, it terminates with error.SignalInterrupt
, thanks to catchterm()
in mercurial.dispatch
.