# 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. # # See the systemd.service man pages for more information about possible options and other examples. # The systemd_autostart.txt file is another example for simpler usage. 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=on-failure [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 "/command" > /run/minecraft.control", replace 'command' with the desired command.