I have two service running in linux, call them A and B. Each depends on the other, so if one crashes and restarts, the other one must be restarted immediately.
I have written a monitor program to launch and monitor the two services respectively, and the program can restart one service when it crashes.
I want to improve the monitor program so that when it finds one service has crashed, it will get the other service’s PID and kill it.
There’s a few great solutions that you can program specific responses to different events.
daemontools – http://cr.yp.to/daemontools.html
upstart(if you use ubuntu) – http://upstart.ubuntu.com/
supervisor – http://supervisord.org/