Windows Scripts - GeheimagentNr1/AutoRestart GitHub Wiki

Everything, that is in angle brackets (<>) in the examples, must be replaced, by what is described in them.
All scripts on this page are batch scripts and must be saved with the ending ".cmd".
If you have problems, check the Troubleshooting page.

Java command

The Java command to start the server depends on the mod loader and the Minecraft version:

  • Forge 1.16.5 or older: java -Xmx<Amount of RAM in gigabytes you want to allocate to Minecraft>G -jar forge-<Minecraft version>-<Forge version>.jar
  • Forge 1.17.1 or newer: java -Xmx<Amount of RAM in gigabytes you want to allocate to Minecraft>G @libraries/net/minecraftforge/forge/<Minecraft version>-<Forge version>/win_args.txt
  • NeoForge (1.20.2 or newer): java -Xmx<Amount of RAM in gigabytes you want to allocate to Minecraft>G @libraries/net/neoforged/neoforge/<NeoForge version>/win_args.txt

In the examples below, replace <Java command> by the matching command.

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 path of this script, i.e "<Path of your Minecraft server>\\start.cmd" (All "\" have to be "\\")
"restart_command" must only contain the path of the script, without any other commands or arguments. Values like "cmd /c start.cmd" or "start.cmd nogui" don't work, because the whole value is used as the name of the program to start. Put everything else into the script.
The script must start the server in a new window (with start) and must end directly. Don't use pause in this script, because it is started by the stopping server and has no console.

cd /d "<Path of your Minecraft server>"
start <Java command>

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.cmd". It is used to start the "restart_loop.cmd" script in a new window.

cd /d "<Path of your Minecraft server>"
start .\restart_loop.cmd

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

  • "-1" means that the server crashed.
  • "0" means the server was shutdown with the "/stop" command and should be stopped.
  • "1" means 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.

echo OFF
:start
    <Java command>
    SET /p should_restart=<.\auto_restart\restart
    if "%should_restart%" == "0" goto stop
    echo If you want to stop the server completely, press Ctrl+C before the countdown is at 1!
    echo Rebooting in:
    timeout /T 5 /nobreak
    echo Server restarts!
    goto start
:stop