[erlang-questions] What happens on TERM?

Dominic Williams mail@REDACTED
Fri Oct 26 19:31:05 CEST 2012


Hi Daniel,

Le 25 oct. 2012 à 20:07, Daniel Dormont a écrit :

> Or, more precisely: I am running an Erlang VM as a daemon on Linux, with a number of applications (Ejabberd and its various dependencies such as Mnesia, specifically). When I issue a shutdown command on the machine, is there a way to have the Erlang VM receive a signal and cleanly shutdown all running applications? Or do I need to use some kind of custom script (for example, Ejabberd includes ejabberdctl which has a stop command, so I guess I could issue that and wait a bit before halting)?

I don't believe it is possible to catch the OS signals sent to the VM itself. You could write a port program that would catch its own and send them to your Erlang application... however this is complicated.

What we do with embedded (daemon) Erlang applications is to have a Linux /etc/init.d script to start, stop and restart it. Then, if you configure this correctly, your daemon will be started automatically at boot time and shutdown cleanly too.

Generating an Erlang release (by hand or with rebar) provides the necessary commands to make writing such a init.d script easy.

Alternatively you could look at the Yaws distribution (especially using e.g. the Debian package), which provides all this, including the init.d script, so you can see how it's done.

Best regards,
Dominic Williams
http://dominicwilliams.net

----




More information about the erlang-questions mailing list