[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [monit] Check if a process is running
From: |
eric |
Subject: |
Re: [monit] Check if a process is running |
Date: |
Sat, 23 May 2009 21:56:53 +0200 |
User-agent: |
Thunderbird 2.0.0.18 (Windows/20081105) |
mercadodei mercado a écrit :
Hello All
To check if a process is running the only thing I have to do is :
check process <process> with pidfile "/var/run/<process>.pid"
start = "/etc/init.d/<process> start"
stop = "/etc/init.d/<process> stop"
right ?
and if the process doesn't have pid file (I know that this question
is already answered but I would like to know your opinions)
Thanks
The lonely way is to ... create a pid file !
Try something like this (if 'nopidfilebinary' is the name of your
program that does not create pid file) :
-----8<----------------------------------------------------------------------------
check process nopidfilebinary.pidfile with pidfile
/var/run/nopidfilebinary.pid
start program = "/usr/local/bin/nopidfilebinary && (ps -C
nopidfilebinary -o pid= | tr -d ' ')> /var/run/nopidfilebinary.pid"
stop program = "test -f /var/run/nopidfilebinary.pid && kill -TERM
`cat /var/run/nopidfilebinary.pid` && rm -f /var/run/nopidfilebinary.pid "
[...]
-----8<----------------------------------------------------------------------------
Assuming :
1) monit will start the program because pid file is missing, so it MUST
NOT be started at boot by rc.d init process, or monit will try to start
a program that is already running.
2) monit should receive a 'stop all' command on machine shutdown mainly
if 'depends on' allow cleaner stop of your program, else the killall
will stop your program in raw way.
3) 'ps' is present on your plateforme, as well 'tr' (used to remove
blanks before PID sent by 'ps'). And 'ps' allow '-C' and '-o' args.
regards