[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem keeping a program running after monit starts it

From: Martin Pala
Subject: Re: Problem keeping a program running after monit starts it
Date: Tue, 27 Jan 2015 00:09:18 +0100


it is possible that the "/usr/bin/python /home/pi/temperature/" script forks and thus the resulting daemon has different PID then what you write to the pidfile before you call this script.

You can either modify the python script itself to create/update the pidfile or you can try to use the pattern based process monitoring ('check process sensors matching "/usr/bin/python /home/pi/temperature/"')


On 27 Jan 2015, at 00:00, Chris Sterritt <address@hidden> wrote:


First, thanks for monit -- it looks to be very useful.  My apologies if I've missed something.

I'm having a problem monitoring a program using monit.

I'm running this on a raspberry pi, having built monit 5.11 from source; I tried using the version from the repositories, but it was 5.4 and didn't support some of syntax below that I want.

I'm trying to follow the "Q: I have a program that does not create its own pid file. Since monit requires all programs to have a pid file, what do I do?" [entry in the FAQ](

Here's my script (which just runs my python program, instead of
the java program in the wiki example):


    case $1 in
         echo $$ > /var/run/;
         exec 2>&1 /usr/bin/python /home/pi/temperature/ 1>/tmp/post_temps.out
         kill `cat /var/run/` ;;
         echo "usage: start_sensors {start|stop}" ;;
    exit 0

Here's my `/etc/monit/monitrc` entry:

    # Run temperature sensor monitor
    check process with pidfile /var/run/
       start = "/home/pi/temperature/ start"
       stop = "/home/pi/temperature/ stop"

The output in the monit log looks like:

    [EST Jan 24 14:21:16] info     : 'raspberrypi' Monit reloaded
    [EST Jan 24 14:21:16] error    : '' process is not running
    [EST Jan 24 14:21:16] info     : '' trying to restart
    [EST Jan 24 14:21:16] info     : '' start: /home/pi/temperature/start_sensors.    sh
    [EST Jan 24 14:21:46] error    : '' failed to start (exit status -1) --     Program /home/pi/temperature/ timed out

So as you can see, monit starts up the program, it runs fine, and then monit kills it thirty seconds later due to the "timeout".

My program is running fine, and producing the proper output that I'm sending to the /tmp/post_temps.out file.

I don't understand why monit is timing the program out... it's supposed to be a long-running process!

I've tried changing the script so that it puts the program in the background (and has it write its own /var/run/ file), but then monit starts a new instance up every thirty seconds or so, not stopping the old ones, and writing over the pid file.  It's like it's not even looking at the pid file.

To unsubscribe:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]