我有一个自定义的服务,我想监视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调用该脚本。
它更干净,更模块化,performance更可预测。 同样的想法适用于cron作业。
例如,从Monit示例页面 ,您是否需要支持这一点:
检查path为/ var / crash / core的目录httpd_core(如果已更改时间戳),然后执行“/ bin / bash -c”if [
/bin/cat /tmp/monit_httpd_core.tmp | head -1!=/bin/ls /var/crash/core/core.httpd* | tail -1];然后/ 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 [email protected] [email protected]; fi'“
或这个:
check directory httpd_core with path /var/crash/core if changed timestamp then exec script.sh
script.sh包含所有的丑陋。