0

I have an executable jar file in a folder with other files and sometimes the jar file crashes, is there something that would automatically restart the file when it crashes because i need this jar file to be running at all times

Thanatos
  • 1
  • 1

2 Answers2

4

For example in bash you can wrap a process into next script respawner.sh

#!/bin/bash

until "$@"; do
    echo "Process crashed with exit code $?.  Respawning.." >&2
    sleep 5
done

and then use it as ./respawner.sh java -jar yourJarfile.jar If the Jvm crashes the script will wait for 5 seconds and restarts it.

maks
  • 5,574
  • 17
  • 72
  • 116
0

Well, the first thing you should do is investigate why the JVM crashes (It's the Java Virtual Machine, your java program, and not the JAR file that crashes), how it crashes (e.g. are you running out of memory -- sometimes tuning the JVM correctly may reduce or even eliminate crashes etc.). Having done that to an extent you can, you should look at using a watchdog. A watchdog is a program that watches another program and restarts it upon failure. See this SO discussion.

Kedar Mhaswade
  • 4,237
  • 2
  • 23
  • 29