Skip to content

Instantly share code, notes, and snippets.

@nathanielc
Created August 20, 2014 05:07
Show Gist options
  • Save nathanielc/9b98350ccbcbf21256d7 to your computer and use it in GitHub Desktop.
Save nathanielc/9b98350ccbcbf21256d7 to your computer and use it in GitHub Desktop.
Minecraft systemd unit file
[root@plex ~]# cat /etc/systemd/system/[email protected]
[Unit]
Description=Minecraft Server %i
[Service]
WorkingDirectory=/opt/minecraft-%i
User=mcserver
ExecStart=/usr/bin/screen -DmS mc-%i /bin/java -Xmx2048M -jar minecraft_server.jar nogui
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say SERVER SHUTTING DOWN. Saving map..."\\015'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "save-all"\\015'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "stop"\\015'
ExecStop=/bin/sleep 2
[Install]
WantedBy=multi-user.target
#########
# HowTo
#########
#
# Create directory in /opt/minecraft-XX where XX is a name like 'survival'
# Add minecraft_server.jar into dir with other conf files for minecraft server
#
# Enable/Start systemd service
# systemctl enable minecraft@survival
# systemctl start minecraft@survival
#
# To run multiple servers simply create a new dir structure and enable/start it
# systemctl enable minecraft@creative
# systemctl start minecraft@creative
@nathanielc
Copy link
Author

@Nirei Hi, I haven't used this gist in a few years now. I created this instead https://github.com/nathanielc/minecraft-multi-server. It serves my needs better. It uses docker instead of screen to background and manage the minecraft server processes. Maybe it can be of use to you as well.

@Nirei
Copy link

Nirei commented Dec 31, 2019

Thank you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment