Is there a command that will monitor a process for exiting (crash or normal exit) and then execute another command based on the said process no longer being active?
Or is there a "wrapper" command that runs a process and when that process exists due to crashing or just exiting normally) that another process can be run.
Thanks,
Jerry
On Thu, Jan 10, 2008 at 10:22:56AM -0500, Jerry Geis wrote:
Is there a command that will monitor a process for exiting (crash or normal exit) and then execute another command based on the said process no longer being active?
You can use SNMP to do this. It will set a flag in a certain OID which you then need to monitor. I _believe_ you may even be able to tell snmpd itself to call a process, but I don't recall on that.
Check the man pages.
Or is there a "wrapper" command that runs a process and when that process exists due to crashing or just exiting normally) that another process can be run.
You might look into something like daemontools[1]. It might be a little overly complex. You could certainly script something yourself. However, daemontools are quite reliable.
Ray
Jerry Geis wrote:
Is there a command that will monitor a process for exiting (crash or normal exit) and then execute another command based on the said process no longer being active?
Or is there a "wrapper" command that runs a process and when that process exists due to crashing or just exiting normally) that another process can be run.
Thanks,
Jerry
Try monit. http://tildeslash.com/monit/
The link seems to be down. But the rpm is available on rpmforge and the manpage is excellent.
Jerry Geis wrote:
Is there a command that will monitor a process for exiting (crash or normal exit) and then execute another command based on the said process no longer being active?
Or is there a "wrapper" command that runs a process and when that process exists due to crashing or just exiting normally) that another process can be run.
Why not use a shell script as a wrapper? If you don't put something in the background with an & on the line, the next line will execute when/if the program started on the current line exits. There are nearly always other copies of the shell running anyway so you get shared-text efficiency. If you just want to keep restarting the same program, something like this should run forever.
while : do my_program done
Les Mikesell wrote:
Jerry Geis wrote:
Is there a command that will monitor a process for exiting (crash or normal exit) and then execute another command based on the said process no longer being active?
Or is there a "wrapper" command that runs a process and when that process exists due to crashing or just exiting normally) that another process can be run.
Why not use a shell script as a wrapper? If you don't put something in the background with an & on the line, the next line will execute when/if the program started on the current line exits. There are nearly always other copies of the shell running anyway so you get shared-text efficiency. If you just want to keep restarting the same program, something like this should run forever.
while : do my_program done
This has two issues (at least): - if the program is a daemon, it returns immediately, so the scrpit will try to start the program again and again - if the script gets a signal, it will be killed. back to start.
also, whatever method is used, one must not spend cpu restarting a program that crashes after 2 seconds (thus looping on restart). if the program keeps crashing, an alert should be sent (and the program fixed or removed).
On Sat, Jan 12, 2008, mouss wrote:
Les Mikesell wrote:
Jerry Geis wrote:
Is there a command that will monitor a process for exiting (crash or normal exit) and then execute another command based on the said process no longer being active?
Or is there a "wrapper" command that runs a process and when that process exists due to crashing or just exiting normally) that another process can be run.
Why not use a shell script as a wrapper? If you don't put something in the background with an & on the line, the next line will execute when/if the program started on the current line exits. There are nearly always other copies of the shell running anyway so you get shared-text efficiency. If you just want to keep restarting the same program, something like this should run forever.
while : do my_program done
This has two issues (at least):
- if the program is a daemon, it returns immediately, so the scrpit will
try to start the program again and again
- if the script gets a signal, it will be killed. back to start.
If you use ``kill -0 pid'' it shouldn't affect the running process, and will return success ($? = 0) if the process is running, and fail otherwise.
A fairly standard way of checking things like this is:
pidfile=/var/run/progname.pid progname_signal() { [ -f $progname_pidfile ] && kill -$1 `cat $progname_pidfile` } if progname_signal 0 then echo is running else echo not running fi
Bill -- INTERNET: bill@celestial.com Bill Campbell; Celestial Software LLC URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676
"If taxation without consent is robbery, the United States government has never had, has not now, and is never likely to have, a single honest dollar in its treasury." -- Lysander Spooner, Letter to Grover Cleveland 1886
On Fri, 2008-01-11 at 16:06 -0800, Bill Campbell wrote:
On Sat, Jan 12, 2008, mouss wrote:
Les Mikesell wrote:
Jerry Geis wrote:
Is there a command that will monitor a process for exiting (crash or normal exit) and then execute another command based on the said process no longer being active?
Or is there a "wrapper" command that runs a process and when that process exists due to crashing or just exiting normally) that another process can be run.
Why not use a shell script as a wrapper? If you don't put something in the background with an & on the line, the next line will execute when/if the program started on the current line exits. There are nearly always other copies of the shell running anyway so you get shared-text efficiency. If you just want to keep restarting the same program, something like this should run forever.
while : do my_program done
This has two issues (at least):
- if the program is a daemon, it returns immediately, so the scrpit will
try to start the program again and again
- if the script gets a signal, it will be killed. back to start.
If you use ``kill -0 pid'' it shouldn't affect the running process, and will return success ($? = 0) if the process is running, and fail otherwise.
A fairly standard way of checking things like this is:
pidfile=/var/run/progname.pid progname_signal() { [ -f $progname_pidfile ] && kill -$1 `cat $progname_pidfile` } if progname_signal 0 then echo is running else echo not running fi
Bill
ISTM that the trap command could be quite useful in this scenario. "man bash", under built-in commands. One can analyze various returns, timestamp to prevent runaway restarting, etc.
I've used it in the (far distant) past to great advantage.
<snip sig stuff>
HTH
On 1/10/08, Jerry Geis geisj@pagestation.com wrote:
Is there a command that will monitor a process for exiting (crash or normal exit) and then execute another command based on the said process no longer being active?
If you want something simple, the wait(1) command can block until some process specified by its PID terminates.
-- Daniel