我有一个我想用 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'"
Run Code Online (Sandbox Code Playgroud)
eww*_*ite 10
我会编写一个包含所需事件操作的小型 bash 脚本。从 Monit 调用该脚本。
它更干净、更模块化并且行为更可预测。同样的想法也适用于 cron 作业。
例如,从Monit 示例页面,您是否愿意支持这一点:
检查目录 httpd_core 与路径 /var/crash/core 如果更改时间戳然后 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
Run Code Online (Sandbox Code Playgroud)
哪里script.sh包含了所有的丑陋。