3 ms·
How do you handle operating system signals? like when your autoscale group decides to scala down and you get a SIGTERM with some time to handle it, what do you
by qohen 9y ago
How do you handle operating system signals? like when your autoscale group decides to scala down and you get a SIGTERM with some time to handle it, what do you do?
This might help: from the release notes to Erlang R20 (i.e. latest):
A new event manager to handle a subset of OS signals in Erlang
It's documented in the docs for kernel here:
http://erlang.org/documentation/doc-9.0-rc2/lib/kernel-5.3/doc/html/kernel_app.html#erl_signal_server http://erlang.org/documentation/doc-9.0-rc2/lib/kernel-5.3/d...
You can write your own handler, which you'll install using gen_event (or :gen_event in Elixir), but even if you don't, there's a default handler which handles 3 signals, SIGUSER1, SIGQUIT and SIGTERM.
Per the link above, SIGTERM is handled like so:
The default handler will terminate Erlang normally. This is equivalent to calling init:stop().
Also worth a look, to see how os:set_signal/2 works (this allows you to decide which signals should be ignored, handled by the default handler or handled by your own handler):
http://erlang.org/documentation/doc-9.0-rc2/lib/kernel-5.3/doc/html/os.html#set_signal-2 http://erlang.org/documentation/doc-9.0-rc2/lib/kernel-5.3/d...
(And a shout out to legoscia on Stack Overflow for letting us know this might be available:
https://stackoverflow.com/a/41872533 https://stackoverflow.com/a/41872533 )
- anko 9y agoThis is brilliant, I can't believe I missed it! Thank you
- qohen 9y agoIf you hadn't mentioned it, I wouldn't have gone researching it and then finding legocia's 2017 comment to a 2010 StackOverflow thread where he says that perhaps a pull request involving an "event manager for signals" might make it into R20. So, you're welcome...and thank you for getting me to look :-)