Created
September 29, 2024 15:20
-
-
Save loulecrivain/589007022412b7925c21a956611009be to your computer and use it in GitHub Desktop.
PaperMC systemd service template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Minecraft Server %i | |
After=network.target | |
[Service] | |
WorkingDirectory=/opt/minecraft/%i | |
# Solves the issue where the minecraft server will endlessly restart itself | |
# See https://askubuntu.com/questions/953920/systemctl-service-timed-out-during-start for more info | |
Type=forking | |
#PrivateUsers=true | |
# Users Database is not available from within the unit, only root and minecraft is available, everybody else is nobody | |
User=minecraft | |
Group=minecraft | |
#ProtectSystem=full | |
# Read only mapping of /usr /boot and /etc | |
#ReadWritePaths=/tmp | |
#ProtectHome=true | |
# /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). | |
#ProtectKernelTunables=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. | |
# Implies MountFlags=slave | |
#ProtectKernelModules=true | |
# 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 | |
# Implies NoNewPrivileges=yes | |
#ProtectControlGroups=true | |
# It is hence recommended to turn this on for most services. | |
# Implies MountAPIVFS=yes | |
CPUQuota=90% | |
# Set default memory values | |
Environment="MCMINMEM=512M" "MCMAXMEM=1024M" "SHUTDOWN_DELAY=5" "POST_SHUTDOWN_DELAY=10" | |
# Change memory values in environment file | |
EnvironmentFile=-/opt/minecraft/%i/server.conf | |
# Uncomment this to fix screen on RHEL 8 | |
#ExecStartPre=+/bin/sh -c 'chmod 777 /run/screen' | |
# Simplified of alternative | |
ExecStart=/usr/bin/tmux new-session -s mc-%i -d '/usr/bin/java -server -XX:+AlwaysPreTouch -XX:+ParallelRefProcEnabled -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1HeapRegionSize=4M -XX:MaxInlineLevel=15 -Xmx${MCMAXMEM} -Xms${MCMINMEM} -jar server.jar --nogui' | |
ExecStop=/usr/bin/tmux send -t mc-%i 'stop' ENTER | |
Restart=on-failure | |
RestartSec=60s | |
[Install] | |
WantedBy=multi-user.target | |
######### | |
# HowTo | |
######### | |
# | |
# Create a 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 | |
# | |
# To change specific server memory assignment, create file /opt/minecraft/XX/server.conf (where XX is your server name) and add below lines: | |
# MCMINMEM=512M | |
# MCMAXMEM=2048M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment