Running erlang shell as daemon / service

I have an Erlang program that runs in the Erlang shell, and I want to control it.

This is what I want:

  • When the machine starts, the Erlang shell must start with it, as well as the program that runs in the shell.
  • If the Erlang shell crashes for any reason, it must be restarted.
  • You should be able to manually start / stop / restart the Erlang shell.

Example:

/etc/init.d/foobar start /etc/init.d/foobar stop /etc/init.d/foobar restart 

I did not start with the whole “restart myself if it crashes,” but still got stuck with ease, or is it easy?

I have done the following:

Took the skeletal code from /etc/init.d/skeleton and replaced PATH, DESC, NAME, etc. etc .... It works, I can do:

 /etc/init.d/foobar start 

However, I can’t stop it ... The fact is that I run the Erlang shell with "erl", which is a script that does some bizarre things that I don’t understand. It is one thing to create a very long and complex process name. This is not just "erl" like this:

/usr/lib/erlang/erts-5.7.4/bin/beam.smp - -root / usr / lib / erlang -progname erl - -home / home / xxx -.... and some more.

Is there a better way to do this?

OS: Ubuntu 11.04

+4
source share
3 answers

In addition to creating the target release, the standard Erlang production environment, as recommended by @Martin, you need the following:

  • To allow automatic restart of a broken node, you must use the functionality of the heart .

  • To stop a running Erlang node, you can start a temporary Erlang node, connect to a running node and issue the stop command:

     erl -noshell -sname temp_control \ -eval "rpc:call( mynode@myhost , init, stop, [])" \ -s init stop 
    • noshell disables shell output and output
    • sname sets the name of the temporary node
    • eval allows you to execute any valid Erlang expression
      • rpc:call(Node, M, F, A) will call M:F(A) at the specified node ( A is a list of arguments that will be passed to the function as real arguments)
    • s MF runs the function M:F()

    ( eval and s are executed sequentially)

+2
source

What you want to do is create a target system. The documentation for this is here: http://www.erlang.org/doc/system_principles/create_target.html However, at first this is a bit complicated until you get the basic concepts.

Roughly speaking, you do the following:

  • Create an empty node. That is, bin directories, erts and releases (with updated scripts in the basket).
  • Create the release via release_tools, as described in dox.
  • Unzip the release to an empty node, set release / start_erl.data to indicate the versions of the new version and erts.

Then it can be managed as a service with restarts / monitors and all you want to add.

+3
source

The recently released erld project is a great way to truly uninstall the Erlang application. It provides support for all the things a daemon needs to do, namely:

  • Can be started / stopped from init script
  • When launched, the control does not return to the console until the program successfully starts (or is not done).
  • Startup diagnostic information can be printed to the console to indicate progress, but the output stops after the daemon starts.
  • When returning to the console, the return code indicates success (0) or failure (some other number).
  • Log rotation may be triggered by sending SIGHUP

See their github page here: https://github.com/ShoreTel-Inc/erld

+2
source

All Articles