I'm looking for a way to monitor a process, and relaunch the executable if the process dies for whatever reason. Does Linux have a built-in tool that can do this?
feedback
|
|
If it's launched from init, you can have it respawned by init. Set the action for the process to 'respawn' for the run levels you want the process at. | |||||
feedback
|
|
Do you only want to restart it if it dies? The problem with this is that it doesn't handle situations where it freezes. So to just check for the process won't always help. So if this is something like a web server, you want to have a script checking it from the user's perspective. If you set up Nagios Monitoring, you can then use event handlers. These are just scripts that you write that will run when the service down, so you could have one that restarts something like Apache if the web site is down. | |||||
feedback
|
|
I have answered a similar question before. In your case:
Replace | ||||
feedback
|
|
Depending on the distro, but we've successfully used "monit" for this task. It's pretty easy. You can write your own checks, monitor the proces PID, etc. Example monitrc file:
| |||
|
feedback
|
|
Why not a simple bash script?
Replace xeyes with program of your choice. | |||
|
feedback
|
|
Short Answer: No you have to do it yourself. Long Answer: You'll need a parent process to start it, and then keep checking that it's alive and restart it if needed. You could use something like | ||||
feedback
|