[Unit] Description=Minecraft server Documentation= Wants=network.target After=network.target [Service] WorkingDirectory=/home/minecraft/server User=minecraft Group=minecraft Type=forking # Run it as a non-root user in a specific directory ExecStart=/usr/bin/tmux -s new minecraft "java -jar server.jar" # Send "stop" to the Minecraft server console ExecStop=/usr/bin/tmux kill-session -t minecraft # Wait for the PID to die - otherwise it is killed after this command finishes! ExecStop=/bin/bash -c "while ps -p $MAINPID > /dev/null; do /bin/sleep 1; done" # Note that absolute paths for all executables are required! [Install] WantedBy=multi-user.target