[erlang-questions] Starting Erlang as a Unix daemon

Sam Bobroff <>
Fri Jan 9 01:26:58 CET 2009


Hi Joe,

On Thu, 8 Jan 2009 15:10:46 +0100
Joe Armstrong <> wrote:

> Read
> 
> http://www.sics.se/~joe/tutorials/web_server/web_server.html#m2
> 
> This is specific to red-hat - but it is pretty easy to adapt to other
> *nix systems
> 
> /Joe Armstrong

I already use a system very like the one described on your web page but
I'm having several problems with it. They are:

* The init script should return success (a zero exit code and an "OK"
  message) if and only if the server has started successfully. Running
  "erl -detached" (as your script does) unfortunately always returns
  success. It's just not acceptable to have a service report that it's
  started successfully when it hasn't.
* Running the stop init script should only return success if it has
  actually managed to stop the server. (*)

Without these properties a system can't be (safely) used from package
managers like RPM and it also looks bad to system administrators (who
have to use "ps" and look at some log file just to see if it's started
up).

I think I'll have to write a C wrapper program to handle this. It could
register itself as a C node and run Erlang as a (non-detached) child
process. It could then display any output from Erlang during the start
up phase on the terminal, and once it receives a specific message from
the Erlang application (via a simple message to the C node) it could
detach itself from the terminal and return a result code (leaving Erlang
running in the background). If that sounds useful to anyone else, let
me know and I'll try to open source it :-)

(Even better would be to include this functionality in erl itself, and
provide a BIF that you could call from within your Erlang application to
complete the detachment and return a result code from erl to the shell.)

Cheers,

Sam.

(*) I've got this part working fairly well by using a system similar to
yours but by also passing the result of the stop function out to the
init script using halt(1) or halt(0).
-- 
Sam Bobroff |  | M5 Networks



More information about the erlang-questions mailing list