I play minecraft. A lot. And so, some time ago I decided to setup a server on a VPS to play modded with some friends, and when looking on setting up the server, I came across with Pahimar’s Forgecraft script. Okay, less “came across” and more “hear about in a stream”. But eitherway, let’s get going.
You will need a debian-like server with java installed, as well as a copy of the minecraft server, either moded or vanilla
Installing the init script
So, the init script looks something like this:
(Due to the script beeing rather large, I’ve moved it to github: https://gist.github.com/amardomingo/a509ba6fca844922b808 )
You will need to change the relevant variables in the header. Set the username to run the server jar, the folder where the server lives, the backups folder and the java home to your java installation.
Then, just save the script in /etc/init.d/ and enable it:
root@host:~# update-rc.d minecraft defaults
And you are good to go.
Setting the check server
As you may have notice, in Pahimar’s repo there is a java class called “CheckServer”. This class is responsible for keeping tabs on the server, and restarting it, in the case it would not respond to any command. So, in the previous init script, you should have set the CHECKSERVER variable to where the java class is. Build it, and it’s done:
Setting up the backups
Finally, the script includes a backup method using rdiff-backup. Just add the command to the crontab, with whatever frecuency you want the backups. I chose 1 hour:
# Minecraft backups every hour 0 * * * * /etc/init.d/mc170 backup >>/opt/minecraft/backup.log 2>&1
Food for though
- There are a lot of Java Options there. For a normal minecraft server It should suffice with just the memory options.
- The CheckServer script may work better in other language, like python or bash, where you don’t need to compile it.