Skip to content

Instantly share code, notes, and snippets.

@zoredache
Created August 23, 2017 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoredache/3a996fcea47be2c7992143eb841cfd06 to your computer and use it in GitHub Desktop.
Save zoredache/3a996fcea47be2c7992143eb841cfd06 to your computer and use it in GitHub Desktop.
systemd minecraft unit - /etc/systemd/system/minecraft@.service
# adapted from https://gist.github.com/nathanielc/9b98350ccbcbf21256d7
[Unit]
Description=Minecraft Server %i
[Service]
Environment="JAVABIN=/usr/bin/java" "JAVAOPTS=-Xmx1024M -Dlog4j.configurationFile=log4j2.xml" "MCJAR=paperclip.jar" "MCOPTS=--
log-strip-color"
EnvironmentFile=-/srv/mc/%i/environment
WorkingDirectory=/srv/mc/%i/data/
User=mc_%i
UMask=0002
ExecStart=/usr/bin/screen -DmS %i $JAVABIN -Dinstance=%i $JAVAOPTS -jar $MCJAR $MCOPTS nogui
ExecStop=/usr/bin/screen -p 0 -S %i -X eval 'stuff "say SERVER SHUTTING DOWN. Saving map..."\\015'
ExecStop=/usr/bin/screen -p 0 -S %i -X eval 'stuff "save-all"\\015'
ExecStop=/usr/bin/screen -p 0 -S %i -X eval 'stuff "stop"\\015'
ExecStop=/bin/sleep 2
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment