Skip to content

Instantly share code, notes, and snippets.

@nathanielc
Created August 20, 2014 05:07
  • Star 31 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nathanielc/9b98350ccbcbf21256d7 to your computer and use it in GitHub Desktop.
Minecraft systemd unit file
[root@plex ~]# cat /etc/systemd/system/minecraft@.service
[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
@Nirei
Copy link

Nirei commented Dec 19, 2019

This is not working.

@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