Monit - stop service and stay stopped?
Asked Answered
C

4

16

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

Campus answered 15/9, 2011 at 12:46 Comment(0)
P
30

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.

Professoriate answered 21/11, 2011 at 1:11 Comment(0)
H
8

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.

Hussy answered 8/2, 2016 at 11:35 Comment(0)
W
2

The model is: Monit runs as a service by init.d and therefore controlled (stop/start/restart) by init.d . (Others, please me if I am wrong). Applications that require to be monitored are handled by monit.

Therefore, such applications should be only controlled i.e. stop/start/restart via monit. monit

Woodborer answered 17/10, 2013 at 2:20 Comment(0)
G
1
SET ONREBOOT LASTSTATE

As per: https://mmonit.com/monit/documentation/monit.html#SYSTEM-REBOOT-AND-SERVICE-STARTUP

Gaylagayle answered 1/12, 2021 at 14:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.