1

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

我想要做的是monit检查该文件的时间戳,如果它在最后一分钟没有更改,则重新启动脚本。

这是我的python脚本:

测试.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

所以我可以看到它正在工作,但让我感到困惑的另一件事是当我执行monit statusfetch_output status 参数时Invalid Type,不知道它是什么意思,但肯定有问题。

Process 'wrapper_test'
  status                            Initializing
  monitoring status                 Initializing
  data collected                    Fri, 23 Aug 2013 14:32:17

File 'fetch_output'
  status                            Invalid type
  monitoring status                 Monitored
  permission                        0
  uid                               0
  gid                               0
  timestamp                         Wed, 31 Dec 1969 19:00:00
  size                              0 B
  data collected                    Fri, 23 Aug 2013 14:42:14
4

0 回答 0