This document contains the content of /resources/docs/text/systemd_minecraft_server_example.txt. Download the file by setting the ?act=download parameter, or access the raw file at either srcs.cc or src.cerium.cc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 # This is an example for a systemd service which starts a Minecraft server after system startup, uses a socket to execute commands, and shuts down gracefully. # This example uses a user named 'minecraft', with the home directory at '/home/minecraft/', and assumes you use a run.sh file to start the server. cat > /etc/systemd/system/minecraft.service << EOF [Unit] Description=A dedicated Minecraft server After=network.target [Service] User=minecraft Type=simple KillSignal=SIGCONT Sockets=minecraft.socket WorkingDirectory=/home/minecraft/ ExecStart=/bin/sh -c "/home/minecraft/run.sh < /run/minecraft.control" ExecStop=/bin/sh -c "echo /stop > /run/minecraft.control" Type=exec Restart=always [Install] WantedBy=multi-user.target EOF cat > /etc/systemd/system/minecraft.socket << EOF [Unit] BindsTo=minecraft.service [Socket] ListenFIFO=/run/minecraft.control FileDescriptorName=control RemoveOnStop=true SocketMode=0660 SocketUser=minecraft EOF systemctl enable minecraft.service systemctl start minecraft.service # Use: 'journalctl -u minecraft.service' to view the service logs, # or view the status and other information with: 'systemctl status minecraft.service'. # # Send commands to the server with: 'echo "/help" > /run/minecraft.control', replace 'help' with the desired command. More resources