• Software
  • Cookbook
  • Software
  • Cookbook
  • Home
  • Rand
    • Minecraft Sucks
  • Docs
    • SPA Deployments in AWS
    • Minecraft Server Administration
    • Test Harness for Postgres Integrations
    • Enterprise REST API
  • Cookbook
    • Cookies
    • Muffins
    • Pasta

Minecraft Server Administration

I run a minecraft server on my Homelab. This post includes a walkthrough of how to set up your own server and run it as a service on some Linux host, as well as some handy scripts to inspect and manage multiple worlds.

Play safe, have fun.

Requirements

OS

For this tutorial you should be on some Linux machine. I run RedHat flavoured linux on a repurposed gaming PC, but if you're on something close you should be fine. Just be aware of your system's package manager and ensure you're on a systemd-having distribution.

Install Java

The Java runtime version needs to be compatible with whatever Minecraft version you plan on playing. I'm on OpenJDK Java 21, and play MC version 1.20. If you just pick the latest of each you should be fine. These can be updated later along with new releases of the game.

$ sudo dnf install java-21-openjdk
$ java -version
openjdk version "21.0.6" 2025-01-21
OpenJDK Runtime Environment (Red_Hat-21.0.6.0.7-1) (build 21.0.6+7)
OpenJDK 64-Bit Server VM (Red_Hat-21.0.6.0.7-1) (build 21.0.6+7, mixed mode, sharing)

Download Minecraft Server

Create a minecraft directory ~/minecraft and download server.jar from the minecraft website.

$ mkdir ~/minecraft && cd ~/minecraft
$ wget -O server.jar https://piston-data.mojang.com/v1/objects/e6ec2f64e6080b9b5d9b471b291c33cc7f509733/server.jar

Server Setup

Once you have java installed and have managed to pull down a copy of server.jar we can start setting up our server. First thing we have to do is accept the End-User License Agreement

Accept the EULA

You need to accept the EULA, so run server.jar to initialize the server and create the necessary files.

$ java -jar server.jar nogui

This will populate ~/minecraft with the folders and files the server needs. In here you'll find a file called eula.txt.

$ ls
eula.txt  libraries  logs  server.jar  server.properties  versions
$ sed -i 's/eula=false/eula=TRUE/' eula.txt

Create the Service

You can go ahead and run the server manually if you want,

$ java -Xmx8G -Xms4G -jar /home/sigh/minecraft/server.jar nogui

but in order to manage the server as a service, we need to set up a unit file. So create the following file:

/etc/systemd/system/minecraft.service
# /etc/systemd/system/minecraft.service

[Unit]
Description=Minecraft Server
After=network.target

[Service]
WorkingDirectory=/home/$USER/minecraft
User=$USER
Group=$USER
Type=simple
Restart=on-failure
ExecStart=/usr/bin/java -Xmx8G -Xms4G -jar /home/$USER/minecraft/server.jar nogui

[Install]
WantedBy=multi-user.target

Replace $USER with your username.

You'll want to update the server's max and min memory settings - -Xmx and -Xms respecively - to match your system's resources. Those are my settings running on a machine with 16GB of RAM.

Enable the Service (Optional)

If you want the server to start when the machine boots you can "enable" the service like so:

$ sudo systemctl enable minecraft.service

Start/Stop the Service

To manage the server's lifecycle manually you can use the systemctl start and stop commands.

# start
$ sudo systemctl start minecraft.service

# stop
$ sudo systemctl stop minecraft.service

Checkpoints

I suck at the game, so I cheat and save my game every so often.

I have the two following scripts in ~/home/$USER/bin. The checkpoint script would be easy to run via cron, but you'll note that it stops and starts the server. I disconnect and copy the directory to avoid issues with serialization. I doubt there's an issue just doing this while in-game, but I haven't tested.

Save

checkpoint
#! /bin/bash

sudo systemctl stop minecraft.service
rm -r ~/minecraft/world_checkpoint
cp -r ~/minecraft/world ~/minecraft/world_checkpoint
sudo systemctl start minecraft.service

Load

restore_checkpoint
#! /bin/bash

sudo systemctl stop minecraft.service
mv ~/minecraft/world ~/minecraft/world_backup
cp -r ~/minecraft/world_checkpoint ~/minecraft/world
rm -r ~/minecraft/world_backup
sudo systemctl start minecraft.service

Utilities

Here are some scripts you can include to extrapolate metadata from your server logs.

Advancements

$ advancements
Feb 27 12:52:15 [Stone Age]
Feb 27 12:52:48 [Getting an Upgrade]
Feb 27 13:08:45 [Monster Hunter]
Feb 27 13:22:58 [Sweet Dreams]
~/bin/advancements
#! /bin/bash

set -e
username=YourInGameUsername

# Find most recent game start time
most_recent_world_start=$(journalctl -r -u minecraft.service \
	| grep "No existing world data" \
	| sed -n '1p' \
	| awk '{ print $1, $2, $3 }'
)

# log advancements 
journalctl -u minecraft.service --since="$most_recent_world_start" \
	| grep "$username has made the advancement" \
	| awk '{
		date = $1 " " $2 " " $3;
		rest = $0;
		gsub(/.*\[/, "[", rest);
		print date, rest;
	}'

Latest Game

$ latest
World: world; Version: 1.21.4; Created: Feb 27 12:49:07
~/bin/latest
#! /bin/bash

journalctl -r -u minecraft.service | awk '
/server version/ {
 version = $NF;
 found_start = 1;
}

/Preparing level/ && found_start == 1 {
 world = $NF;
}

/No existing world/ && found_start == 1 {
 date = $1 " " $2 " " $3;
 print "World: " world "; Version: " version "; Created: " date;
 found_start = 0;
}' | sed -n '1p' | sed 's/"//g'
Prev
SPA Deployments in AWS
Next
Test Harness for Postgres Integrations