Skip to content

Instantly share code, notes, and snippets.

@dd-han
Forked from winny-/gist:bb17853ffc76fbb9b039
Last active April 30, 2017 14:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dd-han/0ed20035cb7c7e07c8b0cdf64196773b to your computer and use it in GitHub Desktop.
Minecraft systemd unit file that uses tmux instead of screen
root@dd-han-minecrafts:~# cat /etc/systemd/system/minecraft@.service
[Unit]
Description=Minecraft Server %i
After=network.target
[Service]
#PrivateTmp=true
WorkingDirectory=/home/dd-han/minecraft/%i
User=dd-han
Type=oneshot
RemainAfterExit=yes
KillMode=none
ExecStart=/usr/bin/tmux new-session -s mc-%i -d '/usr/bin/java -Xmx1024M -jar minecraft_server.jar nogui'
ExecStop=/usr/bin/tmux send-keys -t mc-%i:0.0 'say SERVER SHUTTING DOWN. Saving map...' C-m 'save-all' C-m 'stop' C-m
ExecStop=/bin/sleep 2
[Install]
WantedBy=multi-user.target
#########
# HowTo
#########
#
# Create directory in /home/dd-han/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment