monit无法启动脚本

时间:2013-08-23 18:43:30

标签: python linux ubuntu admin monit

我正在尝试测试monit。我的想法是我有一些打印文本的python脚本,我还有一个shell脚本充当启动/停止脚本。此shell脚本将输出重定向到名为fetch_output的文件。

我想要做的是让monit检查该文件的时间戳,以及它是否在最后一刻没有改变而不是重新启动脚本。

这是我的python脚本:

test.py

 import time
 import sys

 for i in range(100):
     time.sleep(1)
     sys.stdout.write('a'*i)
     sys.stdout.flush()

wrapper_test

 #! /bin/bash

 PIDFILE=/home/jhon/workspace/producer/wrapper_test.pid

 case $1 in
   start)
     echo $$ > ${PIDFILE};
     exec /usr/bin/python /home/jhon/workspace/producer/test.py >> fetch_output.txt 2>&1
     ;;
   stop)
     kill `cat ${PIDFILE}`
     ;;
   *)
     echo "Usage: wrapper {start|stop}" 
     ;;

 esac
 exit 0

/etc/monit/conf.d/test

 check process wrapper_test with pidfile /home/jhon/workspace/producer/wrapper_test.pid
   start program = "/home/jhon/workspace/producer/wrapper_test start"
   stop program = "/home/jhon/workspace/producer/wrapper_test stop"
   depends on fetch_output

 check file fetch_output with path /home/jhon/workspace/producer
   if timestamp > 1 minutes then
       exec "/usr/bin/monit restart wrapper_test"

问题是此脚本不会将输出写入文件。 但是我可以做到

ps aux | grep test
root     18333  0.0  0.0  31108  4612 ?        S    14:39   0:00 /usr/bin/python /home/jhon/workspace/producer/test.py

所以我可以看到它正在工作,但另一件让我感到困惑的事情就是当我{fill_output状态参数为monit status时,我不知道它是什么意思,但肯定是错误的。< / p>

Invalid Type

0 个答案:

没有答案
相关问题