基本上,当一个文件"product_id“准备好时,启动一个进程"CAD”。我的配置如下:
check file product_id with path /etc/platform/product_id
if does not exist then alert
check process cad with pidfile /var/run/cad.pid
depends on product_id
start = "/bin/sh -c 'cd /home/root/cad/scripts;./run-cad.sh 2>&1 | logger -t CAD'" with timeout 120 seconds
stop = "/bin/sh -c 'cd /home/root/cad/scripts;./stop-cad.sh 2>&1 | logger -t CAD'"我期望“monit”调用“start”,直到文件可用。但是它似乎每个周期都会重新启动进程(停止和启动)。
这里有什么配置错误吗?
感谢任何人的帮助。
发布于 2016-05-04 02:45:32
它每个周期重新启动的原因是因为product_id文件还没有准备好。如果检查失败,依赖于product_id的所有内容都将重新启动。
我建议编写一个脚本,检查product_id是否存在,如果存在,则启动CAD。然后,您可以在monit中的"check program“块中运行此脚本。
发布于 2018-07-13 17:10:09
我是这样做的:
check program ThisIsMyProgram with path "/home/user/program_check.sh"
every 30 cycles
if status == 1 then alert这将运行shell脚本,如果status = 1,则会出现错误。
Shell脚本:
#!/bin/bash
FILE=/path/to/file/that/needs/to/exist.json
PID=$(sudo pidof ThisIsMyProgram)
if [ -s $FILE ]; then
if [ ! -z "$PID" ];then
exit 0
else
sudo service thisismyprogram start 2>&1 >> /dev/null
exit 1
fi
else
exit 0
fiShell脚本检查文件是否存在,如果存在,它将启动进程并保持其运行。
https://stackoverflow.com/questions/36273685
复制相似问题