Simple Instructions: 1.3 Setup (MC 1.17.1 or newer, Linux, Restart Script) - GeheimagentNr1/AutoRestart GitHub Wiki

In this example, we suppose, that you installed the Minecraft server in the directory "/opt/minecraft/servers/Minecraft Server/" and use the Minecraft version 1.18.1 and the Forge version 39.0.17.

First, you create a file named restart_start.cmd in the "/opt/minecraft/servers/Minecraft Server/" directory.
Next, you insert the restart start script into the restart_start.cmd file:

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'

In our example, the Minecraft server is in the directory "/opt/minecraft/servers/Minecraft Server/" installed and the restart_start.cmd file would look like this:

bash -c 'cd /opt/minecraft/servers/Minecraft Server/; screen -d -m -S MinecraftServer ./restart_loop.sh'

As a third step, you create a file named restart_loop.cmd in the "/opt/minecraft/servers/Minecraft Server/" directory.
Next, you insert the restart loop script into the restart_loop.cmd file:

while true
do
    java -Xmx<Amount of RAM in gigatytes you want to allocate to Minecraft>G @libraries/net/minecraftforge/forge/<Minecraft version>-<Forge version>/unix_args.txt
    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

In our example we give the Minecraft server 6 GB RAM to use, with Minecraft version 1.18.1 and Forge version 39.0.17 it would look like this:

while true
do
    java -Xmx6G @libraries/net/minecraftforge/forge/1.18.1-39.0.17/unix_args.txt
    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

Last, we have to feed the configuration file named auto_restart-server.toml. It is located in the world/serverconfig directory in the installation directory of your server. In our example, is in the directory "/opt/minecraft/servers/Minecraft Server/world/serverconfig".
In the config file, we have to set use_external_restart_script to true;

In our example, it would look like this:

#Options for restarting:
[restart]
	#Is the server started by an external restart script?
	use_external_restart_script = true
	#Command that is executed on Server stopped to restart the server. Only called if "[restart, use_external_restart_script]" is false.
	restart_command =  ""

Now we can start the Minecraft server and the Minecraft server restarts, if you use the /restart command.

After testing that the Minecraft server can restart, we continue configuring the features of the Auto Restart mod, starting with the mod naming Auto Restart feature.
Auto Restart Feature