Systemd Unit file for Minecraft Server
- Connect to the server or if you want to run the server on your machine, open a terminal
- Become root using suorsudo- To validate that you're now root, run id
 
- To validate that you're now root, run 
- Next install the necessary packages
apt-get install -y openjdk-11-jre-headless curl screen nano bash grep 
- Create the /optfolder if it doesn't already existmkdir /opt 
- Now you need to create the user for the service
adduser --system --shell /bin/bash --home /opt/minecraft --group minecraft chmod +t /opt/minecraft 
- Create the Systemd Unit file:
ornano /etc/systemd/system/[email protected] # paste the contents of [email protected] curl https://raw.githubusercontent.com/agowa338/MinecraftSystemdUnit/master/minecraft%40.service > /etc/systemd/system/[email protected] 
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:
- Create a subdirectory of /opt/minecraftfor your Minecraft server, we'll be usingfeed-the-beastas an example- It is recommended to use a name which only includes lowercase characters, spaces should be replaced with dashes
 cd /opt/minecraft mkdir feed-the-beast
- Upload your files to the /opt/minecraft/feed-the-beastdirectory- Note: All uploaded files should be owned by the minecraftuser
 chown -R minecraft:minecraft /opt/minecraft/feed-the-beast 
- Note: All uploaded files should be owned by the 
- Accept the Minecraft server's EULA
echo 'eula=true' > eula.txt 
With [email protected] 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=2048MSome 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' minecraftsystemctl enable minecraft@ftb-beyondsystemctl disable minecraft@ftb-beyondsystemctl start minecraft@ftb-beyondsystemctl stop minecraft@ftb-beyondTo 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' minecraftNote: To detach (exit) from the session, press CTRL + A followed by D.