Server restarting plugin

I have an idea for a plugin that adds a /restart command to restart your server. This is just an idea, I don’t really need it, but if you want to make a simple plugin then here’s an idea for you.

This can easily be done by changing your startup script.
I run my server on linux and use the following script to restart the server automaticly when it crashes or when typing /stop in-game.
I’m sure that a similar script already exists for windows, or cloud easily be made.

#!/bin/bash

while true; do
        echo "Starting the server"
        /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.71-2.b15.el7_2.x86_64/jre/bin/java -server -Xms1G -Xmx4G -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=2 -XX:+AggressiveOpts -jar spongevanilla-1.8.9-3.1.0-BETA-221.jar

        echo "Waiting 60 seconds before starting the server again"
        sleep 60
done

On a second note if you want to restart your server periodicly, for example at midnight, you can do this with crontab and screen.
I run my server in a screen called minecraft and can then send command to it via crontab.
The first line messages all players in-game that it will restart and the second stops the server, and then the script will automaticly restart it again after 60 seconds.

0 0 * * * screen -S minecraft -p 0 -X stuff "say Restarting the server in 1 minut\015"
1 0 * * * screen -S minecraft -p 0 -X stuff "stop\015"
2 Likes

There are many server-providers, that do not allow to change your startscript.
So, a possibility to restart your server without really stopping the main thread would be very cool! E.g for Plugins that periodically restart a server, but only if no Players are online.
But i think that’s more an API request than a plugin request :smiley:

1 Like

If you’re restarting your server, surely you want a fresh JVM? If you need your server to restart automatically, and you are paying someone that doesn’t let you auto-restart your server, that is a problem on your side in the form of choosing the wrong host for your needs.