Monday, 18 September 2017

unix - Auto-restart process on crash



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?



Answer



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.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...