Git Product home page Git Product logo

signal_handler's Introduction

signal_handler

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.

Configuration

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
end

By default, modules is [System.SignalHandler.GracefulShutdown], which simply maps SIGTERM to :init.stop().

Usage

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()

signal_handler's People

Contributors

tsutsu avatar

Stargazers

Max Chernyak avatar Oleg Pudeyev avatar Vlad avatar William Austin avatar Randy Thompson avatar Peter Marreck avatar Radek Szymczyszyn avatar

Watchers

James Cloos avatar  avatar Randy Thompson avatar  avatar

signal_handler's Issues

Compilation error on Elixir 1.12

Hello, I have upgraded a project to Elixir 1.12.3 and this dependency no longer compiles:

$ cat .tool-versions 
erlang 23.1.1
elixir 1.12.3-otp-23

$ mix compile --force
Compiling 3 files (.ex)
warning: redefining module System.SignalHandler (current version loaded from /Users/tyler/.asdf/installs/elixir/1.12.3-otp-23/bin/../lib/elixir/ebin/Elixir.System.SignalHandler.beam)
  lib/signal_handler.ex:1


== Compilation error in file lib/signal_handler/graceful_shutdown.ex ==
** (CompileError) lib/signal_handler/graceful_shutdown.ex:4: undefined function handle/2

I received the same error on 1.12.0. It was previously working with 1.11.1.


I took a look through the release notes and didn't see anything that should break this. Although I do see that there is now a built-in System.trap_signal/3 so for now I will try to use that instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.