Skip to content

Instantly share code, notes, and snippets.

@einarjh
Last active August 3, 2017 12:29
Show Gist options
  • Save einarjh/fb2b6ab7bad679d1bbd107fc3f2a93c4 to your computer and use it in GitHub Desktop.
Save einarjh/fb2b6ab7bad679d1bbd107fc3f2a93c4 to your computer and use it in GitHub Desktop.
A very basic, but functional, minecraft service description for systemd.
[Unit]
Description=Minecraft Server
[Service]
# Adjust these to your liking, the service assumes that minecraft_server.jar and eula.txt already
# exists in this directory, and that the User specified has write access to the WorkingDirectory
#
# To send commands to minecraft, do:
# echo "command" >> minecraft-input
WorkingDirectory=/srv/minecraft
User=minecraft
Group=minecraft
Environment="JavaOptions=-Xmx1024M -Xms1024M"
Restart=on-failure
ExecStartPre=/bin/bash -c 'touch minecraft-input && test -w minecraft-input'
ExecStart=/bin/bash -c 'exec java $JavaOptions -jar minecraft_server.jar nogui < <(tail -n0 -f minecraft-input)'
ExecStop=/bin/bash -c 'echo "stop" >> minecraft-input'
ExecStop=/bin/bash -c 'while kill -0 "$MAINPID" > /dev/null 2>&1; do sleep 1; done'
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment