Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monit - stop service and stay stopped?

Tags:

monit

I have a daemon which runs via the usual init.d/service scripts.

I have monit running which ensures these daemons are restarted if they crash.

I have a request that 'service foo stop' should stop the deamon, and because it was explicitly stopped, not a crash, monit should not restart it. How can I achieve this with monit?

I could have the service script's stop() routine call 'monit unmonitor' but this seems circular and wrong.

Thanks, Dave

like image 719
David Kennedy Avatar asked Sep 15 '11 12:09

David Kennedy


People also ask

How do I cancel monit service?

MONIT HTTPD. If specified in the control file, Monit will start with HTTP support. You can then use Monit CLI to start and stop services, disable or enable service monitoring as well as view the status of each service.

How do I restart monit service?

Now, If we want Monit to also start at boot so I need to edit the service configuration file at /etc/default/monit and ensure “START” is set to “yes”. And that's it. It will automatically restart any service or script. Moreover it is very simple to setup.

How do I check my monit status?

The monit configuration can be re-read after installing the PSM by entering the command “monit reload”, or by rebooting the machine. You can obtain the status of the PSM and other important services via the monit web interface at http:// <server ip address>:2812 or on the command line.

How long is a monit cycle?

30 or 60 seconds is a good interval. – Ezra Z. the set daemon config options.


2 Answers

I think you should use monit stop foo instead of service foo stop. That way Monit is aware that the service didn't crash -- and won't restart it.

like image 66
jmonteiro Avatar answered Sep 19 '22 15:09

jmonteiro


There is a MODE param for that:

Monit supports three monitoring modes per service: active, passive and manual.

Syntax:

MODE In active mode (the default), Monit will pro-actively monitor a service and in case of problems raise alerts and/or restart the service.

In passive mode, Monit will passively monitor a service and will raise alerts, but will not try to fix a problem by executing start, stop or restart.

In manual mode, Monit will enter active mode only if a service was started via Monit

From here: https://mmonit.com/monit/documentation/monit.html#SERVICE-MONITORING-MODE

This way if you manage services via runit or upstart and just want to use monit for alerts and dashboards you simply set for all such services mode to passive.

For example:

check process heka with pidfile /etc/sv/myservice/supervise/pid
    start program = "/usr/bin/sv start myservice"
    stop program = "/usr/bin/sv stop myservice"
    mode passive

If you need to enable/disable that online but not permanently -- please refer to other people's answers, they are fine.

like image 32
timurb Avatar answered Sep 19 '22 15:09

timurb