加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 当受监视的进程失败时,如何让monit执行多个操作?

发布时间:2020-12-13 16:36:20 所属栏目:Linux 来源:网络整理
导读:我有一个我想用monit监控的自定义服务.当进程失败时,我想将日志复制到共享文件系统并重新启动该服务.像下面这样的东西,但我不确定是什么.任何提示将不胜感激. check process pipeline with pidfile /var/run/pipeline.pid start program = "/sbin/start pipe
我有一个我想用monit监控的自定义服务.当进程失败时,我想将日志复制到共享文件系统并重新启动该服务.像下面这样的东西,但我不确定是什么.任何提示将不胜感激.
check process pipeline with pidfile /var/run/pipeline.pid
   start program = "/sbin/start pipeline"
   stop  program = "/sbin/stop pipeline"
   if 10 restarts within 10 cycles then timeout
   # Not sure what to write next
   if <service has failed> 
      restart and 
      exec "/bin/bash -c 'cp /var/log/upstart/pipeline.log /nfs/logs/`hostname`.`date +'%m-%d-%Y_%H.%M.%S'`.log'"

解决方法

我会写一个包含所需事件动作的小bash脚本.从Monit调用该脚本.

它更清洁,更模块化,行为更可预测.同样的想法适用于cron工作.

例如,从Monit examples page开始,您是否愿意支持这一点:

check directory httpd_core with path /var/crash/core if changed
timestamp then exec “/bin/bash -c ‘if [ /bin/cat
/tmp/monit_httpd_core.tmp | head -1
!= /bin/ls
/var/crash/core/core.httpd* | tail -1
]; then /usr/bin/gdb -x
/etc/gdb.batch /usr/sbin/httpd /bin/ls /var/crash/core/core.httpd* |
tail -1 | tee /tmp/monit_httpd_core.tmp
| mail -s httpd_crash
admin@foo.bar webmaster@foo.bar; fi'”

或这个:

check directory httpd_core with path /var/crash/core   if changed
timestamp then exec script.sh

其中script.sh包含所有的丑陋.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读