# 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.