0

I'm nrew to monit and have a question regarding the pid files: I have added the following to my /etc/monit/monitrc:

cat /etc/monit/monitrc
set daemon 30
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
set eventqueue
      basedir /var/lib/monit/events # set the base directory where events will be stored
      slots 100                     # optionally limit the queue size

check ping.sh
    with path "/path/to/ping.sh"
    every "44 * * * *"
    #if status != 0 then alert

and I got the following in /var/log/monit.log:

[UTC Sep 21 22:44:09] error    : Error reading pid from file '/path/to/ping.sh'
[UTC Sep 21 22:44:09] error    : 'ping.sh' process is not running
[UTC Sep 21 22:44:09] info     : 'ping.sh' trying to restart

while:

ls -l /path/to/ping.sh
-rwxrwxr-x 1 root root 1045 Sep 21 20:08 /path/to/ping.sh

and inside the script, the pid is stored in /var/run/ping.pid:

#!/bin/bash
pidfile="/var/run/ping.pid"
# Get the pid of the currently running script
ps ax | grep $0 | grep $SHELL | awk '{print $1}'>$pidfile

the pid file is deleted on the bottom of the script with:

rm $pidfile

why is there an error: Error reading pid from file '/path/to/ping.sh'?

Just to be transparent: I have posted the same question on the monit-general@nongnu.org mailing list too but it does not seem to be very active. I will synchronize any replies between the two threads!

BitFreak
  • 103
  • 2

1 Answers1

1

The correct syntax is "check program" (https://mmonit.com/monit/documentation/monit.html#Program)

Also ,it is not recommended to specify an unique value in the CRON expression for the minute field. In your case, best is to trigger the check every 120 cycles (1 hours -> 60 minutes -> 1 cycle every 30 sec -> every 120 cycles)

It summarizes to:

check program ping.sh with path "/path/to/ping.sh"
     every 120 cycles
     if status != 0 then alert
DevOps
  • 720
  • 3
  • 15