2011-05-18 4 views
5

¿Cómo se debe usar el corazón para mantener viva una aplicación?uso del corazón de erlang

Digamos que tengo una aplicación X, ¿se efectuara cuando acabo de llamar algo así como:

erl -boot X -heart -env HEART_BEAT_TIMEOUT 30 -detached 

?

Respuesta

4

Sí, esto iniciará automáticamente un proceso de corazón que supervisa su nodo. Ver the heart documentation.

Actualización: Sí, la asíntota es correcta. También necesita una variable de entorno HEART_COMMAND para indicar qué hacer al reiniciar el nodo.

2

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. 

Ahora mismo tienen una Makefile con una declaración en ella que se ejecutará erl -heart ... para mí. Cuando yo haga que aquí está la lista de procesos:

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 

Cuando mato PID 3829, el resultado siguiente aparece en el shell de Erlang:

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 

Así que está claro que necesito para establecer HEART_COMMAND a algún tipo de reinicio enunciado, y luego corazón realizará según sea necesario. AFAIK, dada la descripción en los documentos, heart no tiene la intención de simplemente reiniciar la VM de Erlang al estrellarse; eso suena como algo que un supervisor de Erlang debería estar haciendo por ti, pero puedo estar equivocado.

(Por supuesto, puede obtener HEART_COMMAND para reiniciar su programa Erlang).

+0

Sí, el propósito del corazón es exactamente eso (¡un supervisor de Erlang es algo completamente diferente!). De los documentos: 'El propósito del programa de puerto de corazón es verificar que el sistema de tiempo de ejecución de Erlang que está supervisando aún se esté ejecutando. Si el programa de puerto no ha recibido ningún latido dentro de HEART_BEAT_TIMEOUT segundos (el valor predeterminado es 60 segundos), el sistema se puede reiniciar. –

Cuestiones relacionadas