0

I've installed monit on my Deabian server with the following configuration:

set logfile /var/log/monit.log

check process myprogram with pidfile /var/run/myprogram.pid
    start program = "/etc/init.d/myprogram start"
    stop program = "/etc/init.d/myprogram stop

on issuing: /etc/init.d/monit start the service goes up and starts myprogram properly.

If I manually kill myprogram, I expected monit to restart it automatically, but seens that monit gets lost. It not only does not restart the process but the monit proecess is finished and cannot be restarted (/etc/init.d/monit start says OK, but the process does not come up. No data on log file).

I can only restart everything if I delete /var/run/myprogram.pid, so I have the following questions:

a) What is the default interval that monit checks for the process? b) Will monit rely on /var/run/myprogram.pid? I'm not sure this file will be deleted in case of crash.... c) Why killing the process did not forced monit to restart?

Please advice what I can be doing wrong...

My program init.d script /etc/init.d/myprogram:

#!/bin/bash

#
# Program parameters
#
NAME=myprogram
DIR=/usr/local/bin/myprogram/bin
AEIRTU_HOME=/usr/local/bin/myprogram

#
# Internal variables
#
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
EXEC=$DIR/$NAME
PIDFILE=/var/run/$NAME.pid

if ! [[ -x "$EXEC" ]]
then
    echo "File '$EXEC' is not executable or not found. Aborting."
fi

function start_app {
    echo "Starting $NAME...";
    cd $DIR
    AEIRTU_HOME=$AEIRTU_HOME nohup "$EXEC" 1>>"/var/log/$NAME.log" 2>&1 &
    echo $! > "/var/run/$NAME.pid"
    echo "$NAME started ok";
}

function stop_app {
    echo "Stopping $NAME...";
    if [[ -e "$PIDFILE" ]]
    then
        kill `cat /var/run/$NAME.pid`
        echo "$NAME stopped."
    else
        echo "Cannot stop $NAME...";
    fi
}

case $1 in
start)
start_app ;;
stop)
stop_app ;;
restart)
stop_app
sleep 5
start_app
;;
*)
echo "usage: myprogram {start|stop|restart}" ;;
esac
exit 0

1 Answer 1

0

a) What is the default interval that monit checks for the process? This is defined either:

  • set globally with SET DAEMON <seconds>
  • set at rule level with
    • EVERY [number] CYCLES
    • EVERY [cron]
    • NOT EVERY [cron]

b) Will monit rely on /var/run/myprogram.pid? Monit will check is a program is running with the pid number contained in the file. if no program exist with this pid, Monit will take action as defined in the rule when Monit wakes up.

c) Why killing the process did not forced monit to restart? Probably, Monit did not wake up in the meantime due to a SET DAEMON too important. When Monit wakes each SET DAEMON interval, it look for rules that have to verified.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.