Running Minecraft Server with SystemD

At the time, there was no reliable way to run Minecraft under Ubuntu’s new systemd setup, so I had to put one together. Oddly enough I found this pretty simple and straightforward. Let’s set it up.

You can find out elsewhere how to install java and get the minecraft server up and running. Once you’re there and everything is working, this is how you set it up as a server where you don’t need to login and start it up manually.

Begin by using root to create a minecraft directory in /opt, moving all your Minecraft server’s files there. (This isn’t essential, but it’s more correct to do it this way.) Next, create a user called minecraft and give that user ownership of all of the server’s files inside /opt/minecraft, as well as ownership of the minecraft directory itself just to avoid problems.

Finally, under /etc/systemd/system, stored as minecraft.service:

Description=start and stop the minecraft-server

RestartSec=20 5
ExecStart=/usr/bin/java -Xms512M -Xmx1024M -jar minecraft_server.jar nogui


Of course you can replace the minimum and maximum memory levels there with whatever you prefer.