2

这个问题与我之前的问题有关: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”,它会显示“写入错误:管道损坏”。

为什么它不起作用?如何正确模拟崩溃以检查 heart 命令是否有效?

感谢您提供的任何建议。

4

1 回答 1

3

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

为了模拟崩溃,所以kill -SEGV <PID>

例子:

$ sleep 30 &
[1] 13274


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

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

于 2011-08-01T22:29:31.660 回答