[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 (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)
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) :
check process nopidfilebinary.pidfile with pidfile /var/run/ start program = "/usr/local/bin/nopidfilebinary && (ps -C nopidfilebinary -o pid= | tr -d ' ')> /var/run/" stop program = "test -f /var/run/ && kill -TERM `cat /var/run/` && rm -f /var/run/ "

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.


reply via email to

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