Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This question already has an answer here:

I have a Java server process which runs native code and the possibility of the entire process crashing due to a problem in native code is always there. Is there any mechanism offered by *nix operating systems wherein I can make the process re-spawn itself when it exists abnormally (exit status != 0)?

Is there any tool/utility out there which can automate this task for any kind of process by providing a certain level of control/configuration at the same time?

share|improve this question

marked as duplicate by Kevin Panko, Tog, Jeff F., Excellll, Scott Mar 5 at 0:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

2 Answers

up vote 9 down vote accepted

There's a few options - you could always wrap it in a short shell script like this:-

#!/bin/sh

RC=1
while [ $RC -ne 0 ]; do
   ./my-java-app
   RC=$?
done

Far from elegant, but may suffice.

share|improve this answer
    
Works nice! One more question: is there any tool/utility out there which can automate this task for any kind of process by providing a certain level of control/configuration at the same time? –  sasuke Dec 18 '10 at 18:08
    
Sounds like something I should write :-D –  Andy Smith Dec 18 '10 at 19:34
    
You really should I guess ;-) BTW, up-voted and accepted. –  sasuke Dec 19 '10 at 6:31
    
You may also want to look at using crontab to monitor your process. This script will also survice a reboot. servermonitoringhq.com/blog/how_to_keep_a_job_running_in_linux –  Ian Purton Feb 3 '12 at 11:56
add comment

What you're looking for is usually called process monitoring or process supervision. There are many tools that do this, usually as part of a varying set of features. Upstart is more and more used for system services in the Linux world. Monit is the first thing I'd try for a program not started by root, but there are many alternatives.

share|improve this answer
    
Those tools sounds interesting. For the time being I've decided to go with the simple approach suggested by Andy, but I'll surely keep these tools in mind when it comes to a bit more involved process management. Thanks. –  sasuke Dec 19 '10 at 6:29
    
BTW, just wanted to confirm, given that Monit is GPL'ed tool, would it be OK if it was used for monitoring proprietary apps running on my box? –  sasuke Dec 19 '10 at 6:30
    
@sasuke: The GPL doesn't put any restriction on what you can use the program for. In fact it only comes into play if you distribute GPL material. –  Gilles Dec 19 '10 at 13:25
    
Ah, got that. Mucho appreciated. :-) –  sasuke Dec 19 '10 at 16:52
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.