monit-general
[Top][All Lists]
Advanced

[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

Hello,

it is possible that the "/usr/bin/python /home/pi/temperature/post_temps.py" 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/post_temps.py"')

Regards,
Martin



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

Hello,

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](http://mmonit.com/wiki/Monit/FAQ#pidfile).

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

    #!/bin/bash

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

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

    # Run temperature sensor monitor
    check process start_sensors.sh with pidfile /var/run/start_sensors.pid
       start = "/home/pi/temperature/start_sensors.sh start"
       stop = "/home/pi/temperature/start_sensors.sh 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    : 'start_sensors.sh' process is not running
    [EST Jan 24 14:21:16] info     : 'start_sensors.sh' trying to restart
    [EST Jan 24 14:21:16] info     : 'start_sensors.sh' start: /home/pi/temperature/start_sensors.    sh
    [EST Jan 24 14:21:46] error    : 'start_sensors.sh' failed to start (exit status -1) --     Program /home/pi/temperature/start_sensors.sh 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 start_sensors.sh script so that it puts the program in the background (and has it write its own /var/run/start_sensors.pid 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.

THANKS!
--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general


reply via email to

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