Systemd Unit file for Minecraft Server
su
or sudo
id
apt-get install -y openjdk-11-jre-headless curl screen nano bash grep
/opt
folder if it doesn't already exist
mkdir /opt
adduser --system --shell /bin/bash --home /opt/minecraft --group minecraft
chmod +t /opt/minecraft
nano /etc/systemd/system/minecraft@.service
# paste the contents of minecraft@.service
or
curl https://raw.githubusercontent.com/agowa338/MinecraftSystemdUnit/master/minecraft%40.service > /etc/systemd/system/minecraft@.service
Each server has it's own subdirectory of /opt/minecraft
. This means that when a new server is being added, the following steps need to be followed:
/opt/minecraft
for your Minecraft server, we'll be using feed-the-beast
as an example
cd /opt/minecraft
mkdir feed-the-beast
/opt/minecraft/feed-the-beast
directory
minecraft
user
chown -R minecraft:minecraft /opt/minecraft/feed-the-beast
echo 'eula=true' > eula.txt
With minecraft@.service
it's possible to specify the RAM allocation per server. This can be done using a server.conf
file in the server's directory.
Example
# /opt/minecraft/ftb-beyond/server.conf
MCMINMEM=512M
MCMAXMEM=2048M
Some Feed the Beast packs include a FTBInstall.sh
. This script needs to be executed before starting the server.
cd /opt/minecraft/ftb-beyond
su -c 'bash /opt/minecraft/ftb-beyond/FTBInstall.sh' minecraft
systemctl enable minecraft@ftb-beyond
systemctl disable minecraft@ftb-beyond
systemctl start minecraft@ftb-beyond
systemctl stop minecraft@ftb-beyond
To enter the console, screen
is used.
All screen sessions are owned by the minecraft
user and are prefixed with mc-
.
# This will attach to the Minecraft server called `ftb-beyond`
su -c 'screen -r mc-ftb-beyond' minecraft
Note: To detach (exit) from the session, press CTRL + A followed by D.