Erlang的心脏如何运作?

时间:2011-07-29 07:40:19

标签: bash erlang heartbeat

这个问题与我之前的问题有关:Running erlang shell as a daemon/service

我有一个看起来像这样的脚本:

#!/bin/bash
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions


export HEART_COMMAND="/etc/init.d/script restart"

start() {


        erl  -heart -pa DIR -sname NAME -setcookie COOKIE -env port 21 -s M -s M2 --
        ### Create the lock file ###
        touch /var/lock/lock
}

stop() {

        erl -noshell -sname temp_control -setcookie COOKIE -eval "rpc:call(NAME@ubuntu, init, stop, [])" -s init stop
        ### Now, delete the lock file ###
        rm -f /var/lock/lock
}


### main logic ###
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
       # start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac

exit 0

我不知道如何模拟崩溃所以我只是尝试了ctrl + c并中止了shell,输出看起来像这样:

root@ubuntu:/etc/init.d# ./script start
heart_beat_kill_pid = 17512
Erlang R13B03 (erts-5.7.4) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.7.4  (abort with ^G)
(NAME@ubuntu)1> Starting M2
Listening on port 21

(NAME@ubuntu)1>
(NAME@ubuntu)1>
(NAME@ubuntu)1>
(NAME@ubuntu)1>
(NAME@ubuntu)1>
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution
a
heart: Fri Jul 29 09:25:10 2011: Erlang has closed.
root@ubuntu:/etc/init.d# heart_beat_kill_pid = 17557
heart: Fri Jul 29 09:25:13 2011: Erlang has closed.
/etc/init.d/NAME: line 20: 17557 Killed                  erl  -heart -pa DIR -sname NAME -setcookie COOKIE -env port 21 -s M -s M2 --
heart: Fri Jul 29 09:25:13 2011: Executed "/etc/init.d/script restart". Terminating.
heart_beat_kill_pid = 17602
heart: Fri Jul 29 09:25:15 2011: Erlang has closed.
/etc/init.d/NAME: line 20: 17602 Killed                  erl  -heart -pa DIR -sname NAME -setcookie COOKIE -env port 21 -s M -s M2 --
heart: Fri Jul 29 09:25:15 2011: Executed "/etc/init.d/script restart". Terminating.
heart: Fri Jul 29 09:25:17 2011: Executed "/etc/init.d/script restart". Terminating.

root@ubuntu:/etc/init.d#

如果我不在启动它的脚本中注释代码行,那么这种情况永远存在。这就像终止erlang shell ......或其他东西的无限循环。

如果我尝试例如“export HEART_COMMAND =”/ bin / echo hello“它说”写错误:断管“。

为什么不起作用?如何正确模拟碰撞以检查心脏命令是否有效?

感谢你提出的任何建议。

1 个答案:

答案 0 :(得分:2)

回答你没问过的问题 (但有几次提到你不知道该怎么做)

模拟崩溃,kill -SEGV <PID>

示例:

$ sleep 30 &
[1] 13274


$ kill -SEGV 13274
[1]+  Segmentation fault      sleep 30

另外,虽然我不知道erlang,我认为它产生了多个线程,一个线程可以通过发送心跳消息来监视另一个线程。如果另一个线程没有响应,则假定它被挂起并重新启动。