|
From: | Bhuvan Gupta |
Subject: | Re: Wrong PID |
Date: | Mon, 28 Aug 2017 21:15:16 +0530 |
Hello,
I try to check your sample based on Monit 5.19.0 on a Mac OS X system
and everything works well.
Which operating system or monit version do you use?
Your sample works well.
check process sample-test with pidfile /tmp/sample-test.pid
start = "/bin/sh -c 'cd /tmp; nohup sleep 1000 1>/tmp/sample-test.log
2>&1 & echo $! > /tmp/sample-test.pid'" with timeout 10 seconds
stop = "/bin/sh -c 'kill -9 `cat /tmp/sample-test.pid`'"
if does not exist then alert
if does not exist then restart
if 2 restarts within 5 cycles then alert
[MacBookPro:~] lutz% ps -fu $USER | grep sleep
504 2474 1 0 8:52pm ?? 0:00.00 sleep 1000
504 2568 2280 0 9:06pm ttys000 0:00.00 grep sleep
[MacBookPro:~] lutz% cat sample-test.pid
2474
I use the way suggested by Bryan in general to start applications.
cmd: the used command
log: the log file
pidout: the pid
case $1 in
start)
nohup "$cmd" >> /var/log/$log.log 2>&1 &
if [ "$!" != "" ]; then
echo "$!" > "/var/run/$pidout.pid"
echo "Started $!" >> /var/log/$log.log
fi
;;
stop)
if [ -f /var/run/$pidout.pid ]; then
pid=`cat /var/run/$pidout.pid`
if [ "$pid" != "" ] && kill -0 $pid 2>/dev/null; then
kill -15 $pid
while [ $? -eq 0 ]; do
ps -p $pid >/dev/null
done
rm /var/run/$pidout.pid
echo "Stopped $pid" >> /var/log/$log.log
fi
fi
;;
> *Question 1: Why "/bin/sh -c cd /tmp..." PID is getting loged in pid file,
> instead of "sleep 1000" pid.*
> *What am i doing wrong?*
Sorry, no idea what's going wrong (on your system),
Lutz
[Prev in Thread] | Current Thread | [Next in Thread] |