Skip to content

Instantly share code, notes, and snippets.

@gatopeich
Created April 8, 2019 22:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gatopeich/36ed7fab3850367bbcd8e6f40becd4e5 to your computer and use it in GitHub Desktop.
Save gatopeich/36ed7fab3850367bbcd8e6f40becd4e5 to your computer and use it in GitHub Desktop.
Systemd service for Minecraft Bedrock server (MCMrARM's mcpelauncher-server)
# /etc/systemd/system/minecraft@.service by gatopeich
#########
# HowTo #
#########
#
# - Copy this file to /etc/systemd/system/minecraft@.service
#
# - adduser --system --shell /bin/bash --home /opt/mcpe --group minecraft
#
# Under /opt/mcpe:
# - Install mcpelauncher-server binary at /opt/mcpe
# - Create subdir in /opt/mcpe/XX where XX is a name like 'survival'
# - Create a /opt/mcpe/XX/server.properties
# - Dump mcpe versions under /opt/mcpe/versions/
#
# Enable/Start systemd service
# systemctl enable minecraft@XX
# systemctl start minecraft@XX
#
# To run multiple servers simply create a new subdir structure and enable/start it
# systemctl enable minecraft@creative
# systemctl start minecraft@creative
#
# Credits:
# based on https://github.com/agowa338/MinecraftSystemdUnit
[Unit]
Description=Minecraft Bedrock Server %i
After=network.target
[Service]
WorkingDirectory=/opt/mcpe/%i
# Users Database is not available for within the unit, only root and minecraft is available, everybody else is nobody
PrivateUsers=true
User=minecraft
Group=minecraft
# Read only mapping of /usr /boot and /etc
ProtectSystem=full
# /home, /root and /run/user seem to be empty from within the unit. It is recommended to enable this setting for all long-running services (in particular network-facing ones).
ProtectHome=true
# /proc/sys, /sys, /proc/sysrq-trigger, /proc/latency_stats, /proc/acpi, /proc/timer_stats, /proc/fs and /proc/irq will be read-only within the unit. It is recommended to turn this on for most services.
ProtectKernelTunables=true
# Implies MountFlags=slave
# Block module system calls, also /usr/lib/modules. It is recommended to turn this on for most services that do not need special file systems or extra kernel modules to work
ProtectKernelModules=true
# Implies NoNewPrivileges=yes
ProtectControlGroups=true
# It is hence recommended to turn this on for most services.
# Implies MountAPIVFS=yes
ExecStart=/usr/bin/screen -LDmS mc-%i /opt/mcpe/mcpelauncher-server -dg /opt/mcpe/versions/1.10.0.7 -dd /opt/mcpe/%i
ExecReload=/usr/bin/screen -p 0 -S mc-%i -X stuff "reload^M"
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X stuff "say SERVER SHUTTING DOWN. Saving map...^M"
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X stuff "save-all^M"
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X stuff "stop^M"
# ExecStop=/bin/sleep 10
Restart=on-failure
RestartSec=30s
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment