5

アプリケーションを存続させるために、心臓をどのように使用する必要がありますか?

私がアプリケーションXを持っているとしましょう、私が次のようなものを呼び出すと、それは監視されますか?

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

4

2 に答える 2

4

はい、これにより、ノードを監視するハートプロセスが自動的に開始されます。ハートのドキュメントを参照してください。

更新:はい、漸近線は正しいです。HEART_COMMANDまた、ノードを再起動するときに何をすべきかを心臓に指示するための環境変数も必要です。

于 2011-05-19T07:21:20.767 に答える
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.

今、私はその中に私のためMakefileに実行されるステートメントを持ってerl -heart ...います。私がそれを実行するとき、ここにプロセスリストがあります:

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

PIDを強制3829終了すると、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

したがって、明らかにHEART_COMMANDをある種の再起動ステートメントに設定する必要があります。そうすれば、必要に応じてheartが実行されます。AFAIK、ドキュメントの説明を考えると、heartはクラッシュ時にErlangVMを単に再起動することを意図していません。それはErlangのスーパーバイザーがあなたのためにやるべきことのように聞こえますが、私は間違っているかもしれません。

(もちろん、HEART_COMMANDだけでErlangプログラムを再起動することもできます)。

于 2011-05-19T07:25:56.677 に答える