简体   繁体   中英

Restart monit automatically after it has been killed by the system

I am using monit to monitor my WEB service. Everything went OK until monit process was killed by the system. There is a part of monit log file showing the issue

监控日志文件

To have monit automatically launched at startup and restarted on failure I added upstart config for monit (I am running Ubuntu 14.04), that looks like this:

    # 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

When I reboot the system monit is not running.

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

How can I configure upstart to keep monit running and monitored?

I had the wrong path to the config file in the start monit command. The correct commands are

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

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

It starts monit as daemon and restarts when I kill it:

    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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM