I am not into Minecraft, but my kids are.
I decided to local host a small Minecraft server on a RHEL 7 vm. There are tons of guides on how to install Minecraft on Linux, but I did not find much of anything that details how to get the software to start at boot-time via systemd.
Below are the steps that I took. These instructions should work on RHEL 6/7, Centos 6/7, or any other Linux that utilizes systemd for starting services.
Change directory to the systemd directory.
# cd /etc/systemd/system
Create a systemd service file using your favorite text editor. Mine is called minecraft.service.
[root@minecraft system]# cat minecraft.service
Make the systemd script executable.
# chmod +x /etc/systemd/system/minecraft.service
Next, create a startup script. Again use your favorite text editor. In the example above, systemd is configured to run the script “/root/start_minecraft_server.bash”. We now need to create that script. Its contents are below.
exec java -Xmx2048M -Xms2048M -jar minecraft_server.1.12.2.jar nogui
Make the script above executable.
#chmod +x /root/start_minecraft_server.bash
Now reload systemd.
# systemctl daemon-reload
Enable and start your service
#systemctl enable minecraft.service
#systemctl start minecraft.service
4 thoughts on “Linux: How to start a Minecraft server at boot via Systemd”
If your aritelcs are always this helpful, “I’ll be back.”
This article was super helpful! Thank you for posting this. I do, however, have a few questions:
1.) I setup my bash file to enable the gui but it doesn’t show up. Is there anyway to get the gui activated?
2.) Is there a way to properly shut down the server manually? Maybe a command to run in the terminal?
3.) Is there a way to shut down the server automatically on system shut down? When it does this, can I make it save the map and back it up to a compressed folder?
4.) This is a curiosity question: Before this method, I was booting the Minecraft server from the terminal. When I was watching the processor usage (while the server was up), it was idling around 60% with no one on the server and 80-90% when some one was on. After setting it up to run on boot, the processor now idles around 10-20% with no one on and I only managed to get it up to 60% by flying (in creative mode). Can you explain why that made such a big difference?
I am new to Linux and have little experience with it but I am learning. Thanks again, I really appreciate the help.
I am very new to Linux but I managed to get through and get it working. This was super helpful! Thanks you for posting it. I do have a few questions though:
1) On boot up, I have the command in the bash file to start up the gui however, the gui doesn’t pop up. Is there a way to get it to come up on boot? Or is there a command I can type in the terminal after its running?
2) Is there a way to manually shut it off? I used to to stop it by typing Ctrl+C in the terminal to end the process but on boot, the terminal window doesn’t pop up. So I can’t actually see the process running.
3) Before when I executed the command that starts the server in the terminal by hand, my processor was running at about 60% with no one on the server and about 80-90% when someone was on. However, now that the server starts on boot, it runs at about 20% with no one on and 60% while I fly in creative (I was trying to push the server). My question is, what is the difference between starting it normally and starting it on boot up? Why is there such a drastic reduction in processor usage?
Again thank you for your help!
admin@yuno:/etc/systemd/system$ sudo systemd-analyze verify minecraft.service
[/etc/systemd/system/./minecraft.service:1] Invalid section header ‘[root@minecraft system]# cat minecraft.service’
minecraft.service: Failed to create minecraft.service/start: Unit minecraft.service is not loaded properly: Bad message.
Looks like the first line of the service is causing errors, removing it seems to fix it.