Search code examples
javalinuxcentosforever

Java - how to use forever tool for the jar file?


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


Solution

  • 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.