当文件的校验和发生改变时,使用 monit 重新启动进程

当文件的校验和发生改变时,使用 monit 重新启动进程

当文件校验失败时,我想重新启动 monit 监控的进程。目前我使用

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"

但我希望有一些类似的命令,if changed checksum then restart prosody而不是通过使用 monit 二进制文件exec

restart操作似乎仅限于重新启动当前监视的进程,因此check file块中的操作不会执行任何操作。

答案1

简单来说就是行动重新开始

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

事件重启将传播到所有依赖项,日志类似如下

[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

请注意,Monit 将通过此配置不断触发事件 -> 因此会不断触发重启。

似乎,开始停止行动必须需要指定,否则不执行任何操作(可能是错误)。(使用 monit 5.14 测试)


编辑:升级到 Monit 版本 5.21.0 后,行为变得更好,并且不会出现无限重启循环

[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'

相关内容