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