Skip to content

Instantly share code, notes, and snippets.

@brianwarner
Created July 23, 2018 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianwarner/477e38c5a660a9fcce9292e9a6fc4b63 to your computer and use it in GitHub Desktop.
Save brianwarner/477e38c5a660a9fcce9292e9a6fc4b63 to your computer and use it in GitHub Desktop.
Minecraft systemd script, uses mcrcon instead of screen
[Unit]
Description=Minecraft server - %i
After=local-fs.target network.target
[Service]
User=minecraft
Group=minecraft
UMask=0027
EnvironmentFile=/etc/mcrcon.conf
KillMode=none
SuccessExitStatus=0 1
NoNewPrivileges=true
PrivateDevices=true
PrivateTmp=true
ProtectHome=true
ProtectSystem=full
WorkingDirectory=/opt/minecraft/%i
ExecStart=/usr/bin/java -server -Xms512M -Xmx2048M -XX:+UseG1GC -XX:+CMSIncrementalPacing -XX:+CMSClassUnloadingEnabled -XX:ParallelGCThreads=2 -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -jar current-minecraft.jar nogui
ExecStop=/usr/bin/mcrcon -P ${%i} -H ${SERVER_IP} -p ${RCON_PASSWD} stop
[Install]
WantedBy=multi-user.target
# Copy this file to /etc/systemd/system/
#
# Create a new directory in /opt/minecraft to hold each game. In this example:
# /opt/minecraft/serverdirectory1
# /opt/minecraft/serverdirectory2
# ...
#
# Rename the Minecraft .jar to current-minecraft.jar
#
# Start a game in each directory to create all necessary files, and accept the EULA
#
# In each directory, modify server.properties:
# server-ip=<your server's IP>
# server-port=<your game's port, unique for each game>
# enable-rcon=true
# rcon.port=<a unique port for each game, NOT same as server-port>
# rcon.password=<an admin password you choose, same for each game>
#
# Install mcrcon:
# $ cd /opt/minecraft
# $ git clone https://github.com/Tiiffi/mcrcon
# $ cd mcrcon
# $ gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c
# $ sudo cp mcrcon /bin/bash/mcrcon
#
# Create /etc/mcrcon.conf
# RCON_PASSWD=(password you set in server.properties)
# SERVER_IP=(IP address of this server)
# <serverdirectory1>=<rcon.port from serverdirectory1/server.properties>
# <serverdirectory2>=<rcon.port from serverdirectory2/server.properties>
# ...
# Note that <serverdirectory> is case-sensitive, and relative to /opt/minecraft.
#
# Enable the service:
# $ sudo systemctl enable minecraft@serverdirectory1
# $ sudo systemctl enable minecraft@serverdirectory2
#
# Configure your client to connect to each game server:
# Server Name = Something that refers to your game
# Server Address = <your server's IP>:<your game's port>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment