Skip to content

A multi-server service for systemd that utilizes GNU Screen to communicate with the server's console.

License

Notifications You must be signed in to change notification settings

untodesu/minecraft-systemd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minecraft server systemd service

A multi-server service for systemd that utilizes GNU Screen to communicate with the server's console.

Installation

Prerequisites

You would need to have this stuff already present in your system:

  • GNU Bash or compatible shell.
  • GNU Screen.
  • A headless Java runtime.
  • Obviously a server jar.

Creating a user

The script requires a user named minecraft to exist in the system. The home directory must be /srv/minecraft/.
NOTE: For some reason Screen refuses to run correctly if this user is using nologin/false instead of an actual shell: needs to be fixed.

sudo mkdir -p /srv/minecraft/
useradd -s /bin/bash -d /srv/minecraft/ minecraft

Creating Screen directory

sudo mkdir -p /srv/minecraft/screen/

Copying files

Only two files are required to be copied at their destinations:

  1. minecraft@.service should be copied to /etc/systemd/system/
  2. service.sh should be copied to /srv/minecraft/
  3. environment.conf may be copied to /srv/minecraft/servername/

NOTE: the service.sh script must also be executable:

sudo chmod +x /srv/minecraft/service.sh

Creating a new server

  1. Create a new directory
    sudo mkdir -p /opt/minecraft/servername/
  2. Copy the server jar to it.
    The server jar may be vanilla server or patched one - the script literally doesn't care about it. But the jar itself must be named as /srv/minecraft/servername/server.jar
    sudo cp whatever.jar /opt/minecraft/servername/server.jar
  3. Start the server for the first time, letting the patched versions to patch themselves and create the eula.txt
    sudo systemctl start minecraft@servername
  4. Accept the EULA by changing the eula property to true
    sudo vim /opt/minecraft/servername/eula.txt
    # ... some evil ViM actions go here, then :wq
  5. Optionally modify the server.properties
    sudo vim /opt/minecraft/servername/server.properties
    # ... some evil ViM actions go here, then :wq
  6. Make sure that the owner of all files in the directory is set to minecraft. Otherwise the server may fail to basically create some files and write logs to the disk.
    sudo chown -R minecraft /opt/minecraft/
  7. Start and optionally enable the server service
    sudo systemctl start minecraft@servername
    sudo systemctl enable minecraft@servername
  8. When you get tired, stop the service
    sudo systemctl stop minecraft@servername

TODO

  • 30-second shutdown timeout that will force systemd to wait until the server is safely stopped instead of rude SIGTERM and non-successful return code
  • fix screen not being able to write to /run/screens/
  • fix screen not being able to run when the shell is /sbin/nologin
  • make screen to redirect standard output to the journal somehow
  • probably use title and subtitle commands when the server is scheduled to stop.
  • maybe add support for pre-run scripts so I can change MOTD every server restart without any third-party plugins that probably eat the already poor performance.

Resources

I have been researching though a lot of projects to figure out why don't my script work as intended. I even tried to use tmux instead of screen but as it turns out, tmux refuses to work without a config or something so I considered using tmux as a cringy way.
So anyway, here's some useful resources:

About

A multi-server service for systemd that utilizes GNU Screen to communicate with the server's console.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages