[erlang-questions] Release handling + Heart = headache

Garrett Smith g@REDACTED
Fri Jan 6 20:49:22 CET 2012


Hi Zabrane,

On Sat, Dec 31, 2011 at 1:48 AM, Zabrane Mickael <zabrane3@REDACTED> wrote:
> Hi guys,
>
> I've successfully generated a release for a simple project and now,
> I'm interested to use "-heart" option for monitoring.
>
> When running the project in dev mode with heart,  the HEART_COMMAND
> is taken into account and my program restart as expected (in case of
> crash, unresponsive VM ...).
>
> But the same program is never restarted under release mode.

What are you specifying for HEART_COMMAND? It should be the same as
what you're using under "release mode".

> The doc say the HEART_COMMAND is ignored under release mode,
> and advices to set the start_prg envirnoment variable for SASL.

What doc is that?

I'm not sure what you mean by "release mode". When you run erl, you're
always running a release. You can specify an alternative boot file
(which specifies how the release is started) using the -boot option.

> I tried this somewhere in my code without success:
> application:set_env(sasl, start_prg, HEART_COMMAND),

HEART_COMMAND should be a system environment variable.

I haven't used sasl's start_prg setting -- I have no idea what that does :)

You'd typically specify that value in  a .config file, which is
specified to erl using the -config option (minus the .config
extension).

So you'd have an Erlang config file that might look like this:

[{sasl, [{start_prg, "your_cmd"}]}].

BUT -- I don't know what that will do :)

Here's an example you can run to experiment with heart.

1. Create a module that prints the Erlang process to a file:

-module(writepid).
-export([start/0]).
start() -> file:write_file("test.pid", os:getpid()).

2. Compile it:

$ erlc writepid.erl

3. Test it:

$ erl -run writepid -detached
$ cat test.pid
PID

4. Kill the Erlang process:

$ kill PID

5. Now run with heart

$ HEART_COMMAND="erl -run writepid -detached" erl -run writepid -detached -heart
$ cat test.pid
PID2

6. Kill that Erlang process (it's being monitored by heart):

$ kill PID2
$ cat test.pid
PID3

If you kill PID3, heart won't restat it because heart isn't running.
You need to include -heart in the HEART_COMMAND if you want to keep
using heart forever.

Note that his has nothing to do with the "release" -- you're free to
specify -boot and -config in your erl command. Just remember that
HEART_COMMAND will be used to restart the Erlang system -- so make
sure you have that correct.

Garrett



More information about the erlang-questions mailing list