monit-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Wrong PID


From: Lutz Mader
Subject: Re: Wrong PID
Date: Sat, 26 Aug 2017 21:50:56 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.6.0

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]