System.SignalHandler is an Elixir application containing a NIF module. This NIF can register itself as the recipient of arbitrary POSIX signals directed at the Erlang node, and will then hand them off as messages to Erlang-land.
Important note: System.SignalHandler runs in the context of an ERTS scheduler thread, so unexpected behavior could occur if you were able to override signal registrations used by ERTS. You can see which signals these are using System.SignalHandler.erts_reserved_signals/0. It is not recommended to override these signals, but System.SignalHandler does nothing to stop you from doing so.
In your config.exs:
config :signal_handler, :modules, [YourHandler]Then, in your_handler.ex:
defmodule YourHandler do
use System.SignalHandler
handle :winch do
# oh hey the terminal size changed
end
endBy default, modules is [System.SignalHandler.GracefulShutdown], which simply maps SIGTERM to :init.stop().
Installing a predefined signal-handler module at runtime:
System.SignalHandler.install(YourHandler)Registering a one-off signal handler at runtime:
System.SignalHandler.register(:term, &:init.stop/0)Unregistering a signal:
System.SignalHandler.unregister(:term)Getting the state of all known signals:
System.SignalHandler.signals()