Skip to content

fpetry/MinecraftSystemdUnit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

MinecraftSystemdUnit

Systemd Unit file for Minecraft Server

Installation

  1. Connect to your (v)root server or if you want to run the server on your machine, open a terminal.
  2. Become root using su or sudo. To check if you are root run "echo $EUID" if it returns "0" you are root.
  3. Next install the necessary packages "apt install openjdk-8-jre-headless curl screen nano bash grep"
  4. Create the /opt folder if it doesn't already exist "mkdir /opt"
  5. Now you need to create the user for the service: "adduser --system --shell /bin/bash --home /opt/minecraft --group minecraft"
  6. Create the Systemd Unit file "nano /etc/systemd/system/[email protected]" : "curl https://raw.githubusercontent.com/agowa338/MinecraftSystemdUnit/master/minecraft%40.service > /etc/systemd/system/[email protected]"

Setup Instance

Now you can Upload your FTB Modpacks into an subfolder of /opt/minecraft/. For example you would place the modpack "FTB Beyond" in "/opt/minecraft/FTBBeyond" (without spaces in the name).

If you want to run vanilla instances, just create a folder within /opt/minecraft and upload the minecraft_server.jar and create the eula.txt file (using: echo "eula=true" > /opt/minecraft/vanilla/eula.txt).

After you uploaded the minecraft server files, make sure, that "minecraft" is the owner and owning group. To do so just run "ls -la /opt/minecraft". If it is not, run "chown minecraft:minecraft /opt/minecraft/FTBBeyond".
You may also require to complete the installation. For current FTB packages you would run:

cd /opt/minecraft/FTBBeyond
echo "eula=true" > /opt/minecraft/FTBBeyond/eula.txt
su -c "/opt/minecraft/FTBBeyond/FTBInstall.sh" -s "/bin/bash" minecraft

Usage

Enable Autostart

systemctl enable minecraft@FTBBeyond

Disable Autostart

systemctl disable minecraft@FTBBeyond

Start Manually

systemctl start minecraft@FTBBeyond

Stop Manually

systemctl stop minecraft@FTBBeyond

Enter Server Commands

Entering commands into the console is somehow complicated thorugh the nature of systemd.
So to enter the console "screen" is used (that's why it is in the script).
Note: To detach (exit) screen press [STRG] + [A] followed by [D].

chmod 666 $(tty)
su -c "/usr/bin/screen -r" minecraft
chmod 430 $(tty)

The first command allows otter users to read and write to your terminal.
The second switches the user context to the minecraft service account.
The last one restores the original terminal access rights for security. It is not very recommended to set the tty access to 666, but it seam to be the only way to enter a screen session within a su session.

About

Systemd Unit file for Minecraft Server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published