Lutz Mader,

Thanks for the reply. Yes i understand that using separate script file is
good idea.
But just curious to know how things work and what might have gone wrong.

Here is the details:
monit 5.23.0
Centos 7
gnome: 3.14.2

On Sun, Aug 27, 2017 at 1:20 AM, Lutz Mader <[email protected]> wrote:

> 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
>
>
> --
> To unsubscribe:
> https://lists.nongnu.org/mailman/listinfo/monit-general
>
-- 
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general

Reply via email to