Использование сердца Эрланга
Вопрос
Как можно использовать сердце, чтобы сохранить приложение в живых?
Позвольте сказать, что у меня есть приложение X, будет мониторировано, если я просто назвать что-то вроде:
erl -boot X -heart -env HEART_BEAT_TIMEOUT 30 -detached
.
?
Решение
Yes, this will automatically start a heart process that monitors your node. See the heart documentation.
Update: Yes, Asymptote is correct. You also need a HEART_COMMAND
environment variable to instruct heart of what to do when restarting the node.
Другие советы
http://www.erlang.org/doc/man/heart.html
This modules contains the interface to the heart process. heart
sends periodic heartbeats to an external port program, which is
also named `heart`. The purpose of the heart port program is to
check that the Erlang runtime system it is supervising is still
running. If the port program has not received any heartbeats within
`HEART_BEAT_TIMEOUT` seconds (default is 60 seconds), the system
can be rebooted. Also, if the system is equipped with a hardware
watchdog timer and is running Solaris, the watchdog can be used to
supervise the entire system.
<snip>
If the system should be rebooted because of missing heart-beats, or
a terminated Erlang runtime system, the environment variable
HEART_COMMAND has to be set before the system is started. If this
variable is not set, a warning text will be printed but the system
will not reboot.
Right now I have a Makefile
with a statement in it that will run erl -heart ...
for me. When I execute it here's the process list:
ubuntu 3814 3579 3814 3579 0 22:03 pts/0 00:00:00 make webstart
ubuntu 3829 3814 3814 3579 25 22:03 pts/0 00:00:01 /usr/local/lib/erlang/erts-5.8.3/bin/beam.smp -K true -A 5
ubuntu 3848 3829 3848 3848 0 22:03 ? 00:00:00 heart -pid 3829
When I kill PID 3829
, the following output appears in the Erlang shell:
heart: Wed May 18 22:04:09 2011: Erlang has closed.
heart: Wed May 18 22:04:09 2011: Would reboot. Terminating.
make: *** [webstart] Terminated
So clearly I need to set HEART_COMMAND to some sort of reboot statement, and then heart will perform as required. AFAIK, given the description in the docs, heart is not intended to simply restart the Erlang VM on crashing; that sounds like something an Erlang supervisor should be doing for you, but I may be wrong.
(Of course, you could get just HEART_COMMAND to restart your Erlang program).