1.X.X - GeheimagentNr1/AutoRestart GitHub Wiki

This mod restarts the Minecraft server by itself or with an external restart script.
The mod can only be used on server side and won't work on the client side.

Common Config

The config file can be found in the config folder and is named "auto_restart.toml".

  • auto_restart
    Should the Server do automatic restarts?

  • restart_times
    Times in 24-hour format on with the server will automatically restart i.e.: ["14:00", "16:32"].

  • restart_message
    Message that is shown on auto restart.

  • uses_restart_script Is the server started by an external restart script?

  • restart_on_crash
    Should the server be automatically restarted when it crashes.

  • restart_command
    Command that is executed on Server stopped to restart the server.
    Only called if "uses_restart_script" option is false.

Commands

  • /restart
    Restarts the server

How to use the Restart Mod

You can let the mod use the restart command to restart the server, or use an external restart script.
The script examples are Linux sh scripts.
You can find Windows script examples on: https://github.com/GeheimagentNr1/AutoRestart/wiki/Windows-Scripts

Restart Command

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'

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 restarts!'
done

Thanks for the logo to Muse31.
You can use this mod in non-commercial modpacks without asking.
You can find more mods from me here.