4

I want to restart a process monitored by monit, when the checksum of a file failed. Currently i use

check process prosody with pidfile /var/run/prosody/prosody.pid
    depends certificate_file
    start program "/etc/init.d/prosody start"
    stop program "/etc/init.d/prosody stop"
    restart program "/etc/init.d/prosody restart"

check file certificate_file with path /etc/prosody/certs/fullchain.pem
    if changed checksum then exec "/usr/bin/monit restart prosody"

But i would like to have some command like if changed checksum then restart prosody instead of using the monit binary via exec.

The restart action seems to be limited to restart the currently monitored process, so an action in a check file block doesn't do anything.

allo
  • 1,524
  • 1
  • 19
  • 35

1 Answers1

3

Simply put action restart

check process prosody with pidfile /var/run/prosody/prosody.pid
    depends certificate_file
    start program "/etc/init.d/prosody start"
    stop program "/etc/init.d/prosody stop"
    restart program "/etc/init.d/prosody restart"

check file certificate_file with path /etc/prosody/certs/fullchain.pem
    if changed checksum then restart

Event restart will be propagated to all dependency with log similar to

[CEST Mar 27 11:57:30] error    : 'certificate_file' checksum was changed for /etc/prosody/certs/fullchain.pem
[CEST Mar 27 11:57:30] info     : 'certificate_file' trying to restart
[CEST Mar 27 11:57:30] info     : 'prosody ' stop: /etc/init.d/prosody stop
[CEST Mar 27 11:57:30] info     : 'prosody ' start: /etc/init.d/prosody start

Be aware that Monit will continue to trigger event again and again with this configuration -> so trigger restart continuously.

Also it seems, start and stop action must to be specified else nothing is done (could be a bug). (Tested with monit 5.14)


EDIT : With an upgraded Monit version 5.21.0, the behavior is way better and there is not endless restart loop

[CEST Mar 27 13:47:22] info     : 'certificate_file' trying to restart
[CEST Mar 27 13:47:22] info     : 'prosody' stop: '/etc/init.d/prosody stop'
[CEST Mar 27 13:47:22] info     : 'certificate_file' checksum has not changed
[CEST Mar 27 13:47:22] info     : 'prosody' start: '/etc/init.d/prosody start'
DevOps
  • 720
  • 3
  • 15