Wrong PID

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Wrong PID

Bhuvan Gupta
Hello all,

I have written check command like

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>/tmp/sample-test.log & 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


# cat /tmp/sample-test.pid
#11445

#ps -aux | grep sleep

root     11446  0.0  0.0 107896   608 ?        S    15:04   0:00 sleep 1000
root     11445  0.0  0.0 113120   652 ?        S    15:04   0:00 /bin/sh -c cd /tmp && nohup sleep 1000 1>/tmp/sample-test.log 2>/tmp/sample-test.log & echo $! > /tmp/sample-test.pid



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?

Request for help

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general
Reply | Threaded
Open this post in threaded view
|

Re: Wrong PID

Bryan Harris
I think you would have a better time writing a script.  Inside script put your commands.

start = "/tmp/script.sh" with timeout 10



On Sat, Aug 26, 2017 at 5:44 AM, Bhuvan Gupta <[hidden email]> wrote:
Hello all,

I have written check command like

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>/tmp/sample-test.log & 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


# cat /tmp/sample-test.pid
#11445

#ps -aux | grep sleep

root     11446  0.0  0.0 107896   608 ?        S    15:04   0:00 sleep 1000
root     11445  0.0  0.0 113120   652 ?        S    15:04   0:00 /bin/sh -c cd /tmp && nohup sleep 1000 1>/tmp/sample-test.log 2>/tmp/sample-test.log & echo $! > /tmp/sample-test.pid



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?

Request for help

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general


--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general
Reply | Threaded
Open this post in threaded view
|

Re: Wrong PID

Lutz Mader
In reply to this post by Bhuvan Gupta
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
Reply | Threaded
Open this post in threaded view
|

Re: Wrong PID

Bhuvan Gupta
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 <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

RE: Re: Wrong PID

Lutz Mader
In reply to this post by Bhuvan Gupta

Hello Bhuvan Gupta,
I'm late, but I can't give you some help or hint.
I have no access to an Centos 7 system and do some additional testing on a Mac OS X, Linux and AIX system an everything works well.

 

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

 

The way you try to start an application via monit works well, unfortunately not on your prefered Centos 7 system.
Bye, Lutz

Verbose Log output, Linux/SLES 11 and Monit 5.210:
[CEST Sep  1 16:52:10] info     : 'sample-test' start on user request
[CEST Sep  1 16:52:10] info     : Monit daemon with PID 75595 awakened
[CEST Sep  1 16:52:10] info     : Awakened by User defined signal 1
[CEST Sep  1 16:52:10] debug    : 'sample-test' process test failed [pid=95537] -- No such process
[CEST Sep  1 16:52:10] info     : 'sample-test' start: '/bin/sh -c cd /home/test/monit/conf; nohup sleep 1000 >/dev/null 2>&1 & echo $! >/home/test/monit/conf/sample-test.pid'
[CEST Sep  1 16:52:10] debug    : 'sample-test' started
[CEST Sep  1 16:52:10] debug    : 'sample-test' monitoring enabled
[CEST Sep  1 16:52:10] info     : 'sample-test' start action done
[CEST Sep  1 16:52:10] debug    : 'sample-test' process is running with pid 106421
[CEST Sep  1 16:52:10] debug    : 'sample-test' process is running with pid 106421
[CEST Sep  1 16:52:10] debug    : 'sample-test' zombie check succeeded


Mit TravelXtra profitieren Sie von 5% Rückvergütung auf den Reisepreis – bekannte dt. Reiseanbieter und ein umfangreiches Reiseangebot wie im Reisebüro!
https://email.freenet.de/reisen/index.html
--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general
Reply | Threaded
Open this post in threaded view
|

Re: Re: Wrong PID

Bhuvan Gupta
Thanks for putting in time.

As suggest by the community i have moved to using separate shell files, which work great :)

Thanks 

On Fri, Sep 1, 2017 at 8:38 PM, <[hidden email]> wrote:

Hello Bhuvan Gupta,
I'm late, but I can't give you some help or hint.
I have no access to an Centos 7 system and do some additional testing on a Mac OS X, Linux and AIX system an everything works well.

 

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

 

The way you try to start an application via monit works well, unfortunately not on your prefered Centos 7 system.
Bye, Lutz

Verbose Log output, Linux/SLES 11 and Monit 5.210:
[CEST Sep  1 16:52:10] info     : 'sample-test' start on user request
[CEST Sep  1 16:52:10] info     : Monit daemon with PID 75595 awakened
[CEST Sep  1 16:52:10] info     : Awakened by User defined signal 1
[CEST Sep  1 16:52:10] debug    : 'sample-test' process test failed [pid=95537] -- No such process
[CEST Sep  1 16:52:10] info     : 'sample-test' start: '/bin/sh -c cd /home/test/monit/conf; nohup sleep 1000 >/dev/null 2>&1 & echo $! >/home/test/monit/conf/sample-test.pid'
[CEST Sep  1 16:52:10] debug    : 'sample-test' started
[CEST Sep  1 16:52:10] debug    : 'sample-test' monitoring enabled
[CEST Sep  1 16:52:10] info     : 'sample-test' start action done
[CEST Sep  1 16:52:10] debug    : 'sample-test' process is running with pid 106421
[CEST Sep  1 16:52:10] debug    : 'sample-test' process is running with pid 106421
[CEST Sep  1 16:52:10] debug    : 'sample-test' zombie check succeeded


Mit TravelXtra profitieren Sie von 5% Rückvergütung auf den Reisepreis – bekannte dt. Reiseanbieter und ein umfangreiches Reiseangebot wie im Reisebüro!
https://email.freenet.de/reisen/index.html

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general


--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general
Reply | Threaded
Open this post in threaded view
|

Re: Wrong PID

Bhuvan Gupta
In reply to this post by Bhuvan Gupta
Using monit 5.23.0 on centos 7

On Sat, Aug 26, 2017 at 3:14 PM, Bhuvan Gupta <[hidden email]> wrote:
Hello all,

I have written check command like

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>/tmp/sample-test.log & 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


# cat /tmp/sample-test.pid
#11445

#ps -aux | grep sleep

root     11446  0.0  0.0 107896   608 ?        S    15:04   0:00 sleep 1000
root     11445  0.0  0.0 113120   652 ?        S    15:04   0:00 /bin/sh -c cd /tmp && nohup sleep 1000 1>/tmp/sample-test.log 2>/tmp/sample-test.log & echo $! > /tmp/sample-test.pid



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?

Request for help


--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general