Linux Scripts - GeheimagentNr1/AutoRestart GitHub Wiki

Everything, that is in angle brackets (<>) in the examples, must be replaced, by what is described in them.

Restart Command Script

This script can be used to run the server once, i.e. if you configured Auto Restart to not use an external restart script.
You configure "restart_command" as the script with the path, where your start-script is located, i.e "<Path of your Minecraft server>/<Name of your script>.sh"

bash -c 'cd <Path of your Minecraft server>; screen -d -m -S <Name of your Screen, i.e. your folders name without spaces> java -jar forge-<Minecraft version>-<Forge version>.jar'

External Restart Script

These scripts are for the use, if you have configured, that you are using an external restart script.
The first script is named "restart_start.sh". It is used to start the "restart_loop.sh" script in a screen.

bash -c 'cd <Path of your Minecraft server>; screen -d -m -S <Name of your Screen, i.e. your folders name without spaces> ./restart_loop.sh'

The "restart_loop.sh" script has the logic in it, to restart or stop the server. It will restart the server always, except in the "./auto_restart/restart" file is "0".
The Auto Restart Mod writes "-1", "0" or "1" to the file. When the script reads the file,

  • "-1" means that server crashed.
  • "0" means the server was shutdown with the "/stop" command and should be stopped.
  • "1" means the server that the server was stopped with the "/restart" command or an auto restart and should be restarted.

After the server was stopped for a restart, the script waits 5 seconds until it restarts the Minecraft server.

while true
do
    java -Xmx<Amount of RAM in gigatytes you want to allocate to Minecraft>G -jar forge-<Minecraft version>-<Forge version>.jar
    read -r should_restart < ./auto_restart/restart
    if [ $should_restart = "0" ]
    then
        break
    fi
    echo 'If you want to stop the server completely, press STRG-C, \before the countdown is at 1!'
    echo "Rebooting in:"
    for i in 5 4 3 2 1
    do
        echo "$i..."
        sleep 1
    done
    echo 'Server neustart!'
done