4

On CentOS 7 i have /home/www/html/java-server/Objects/server.jar file which time to time crash for good reason and need to re-start again automatic so that its always running.

How to use forever like tool or any other similar for Java on CentOS?

For example on my NodeJS server i use as below.

forever start --minUptime 1000 --spinSleepTime 1000 SERVER.js
  or 
forever -m5 server.js

EDIT:

Reference: https://stackoverflow.com/a/28704296/285594

  • I don't of any tool doing that for a java process, but I would use shell scripting to achieve this. A response can be found [here](https://stackoverflow.com/questions/696839/how-do-i-write-a-bash-script-to-restart-a-process-if-it-dies) – Olimpiu POP Dec 14 '17 at 14:31
  • 2
    https://unix.stackexchange.com/questions/10646/repeat-a-unix-command-every-x-seconds-forever – slim Dec 14 '17 at 15:16

3 Answers3

1

Wrap your jar in a shell script (this is optional but often useful) and use Supervisor to monitor it. Supervisor is highly customizable so you can set how many times your process can be restarted in a period of time, etc.

Luciano Afranllie
  • 4,053
  • 25
  • 23
1

Here is how I did it.

I was trying to get a spring boot executable jar to run.

I created a bash script like the following

#!/bin/bash
forever start -c bash ./my-app.jar

The key here is to use "-c bash" otherwise forever failed to run the jar. Forever kept trying to run with node

Timothy Jeffcoat
  • 775
  • 2
  • 9
  • 26
0

You can write a class in Java that loops. It would call your application and catch exceptions, restarting the application after each exception. Make sure the wrapper class releases references to the application so that it can be GC'ed.

Steve11235
  • 2,849
  • 1
  • 17
  • 18