在被系统杀死之后自动重启monit

时间:2016-05-12 07:27:15

标签: monitoring init upstart monit

我使用monit来监控我的网络服务。一切顺利,直到monit进程停止。有一部分monit日志文件

monit log file

要让系统监控monit,我添加了monit配置(我运行的是Ubuntu 14.04),如下所示:

    # This is an upstart script to keep monit running.
    # To install disable the old way of doing things:
    #
    #   /etc/init.d/monit stop && update-rc.d -f monit remove
    #
    # then put this script here:
    #
    #   /etc/init/monit.conf
    #
    # and reload upstart configuration:
    #
    #   initctl reload-configuration
    #
    # You can manually start and stop monit like this:
    # 
    # start monit
    # stop monit
    #

    description "Monit service manager"

    limit core unlimited unlimited

    start on runlevel [2345]
    stop on starting rc RUNLEVEL=[016]

    expect daemon
    respawn

    exec /usr/bin/monit -c /etc/monitrc

    pre-stop exec /usr/bin/monit -c /etc/monitrc quit

当我重启系统时,monit没有运行。

    sudo monit status
    $ monit: Status not available -- the monit daemon is not running

如何配置upstart以保持monit运行和监控?

1 个答案:

答案 0 :(得分:0)

我在start monit命令中有错误的配置文件路径。正确的命令是

    exec /usr/bin/monit -c /etc/monit/monitrc

    pre-stop exec /usr/bin/monit -c /etc/monit/monitrc quit

它作为守护进程启动monit并在我杀死它时重新启动:

    ps aux | grep monit
    root      2173  0.0  0.1 104348  1332 ?        Sl   04:13   0:00 /usr/bin/monit -c /etc/monit/monitrc

    sudo kill -9 2173

    ps aux | grep monit
    root      2184  0.0  0.1 104348  1380 ?        Sl   04:13   0:00 /usr/bin/monit -c /etc/monit/monitrc