Direct answer
Use a service unit that runs Minecraft as a dedicated user from its server directory. Verify the Java command works manually before enabling automatic startup. A service manager cannot fix an invalid JAR, unsupported Java release or incorrect file permissions.
Example unit file
Example for a self-managed Linux host with the server installed in /srv/minecraft and the JAR named server.jar. Change memory values, user, path and JAR name to match your setup:
[Unit]
Description=Minecraft Server
After=network.target
[Service]
Type=simple
User=minecraft
WorkingDirectory=/srv/minecraft
ExecStart=/usr/bin/java -Xms2G -Xmx4G -jar server.jar nogui
Restart=on-failure
RestartSec=15
TimeoutStopSec=120
[Install]
WantedBy=multi-user.target
Install and inspect
- Make a consistent backup and confirm the directory and JAR work as
minecraftbefore writing/etc/systemd/system/minecraft.service. - Run
sudo systemctl daemon-reload, thensudo systemctl start minecraft.service. - Use
systemctl status minecraft.serviceandjournalctl -u minecraft.service -n 100 --no-pagerto check errors. Enable boot startup withsudo systemctl enable minecraft.serviceonly after tests pass.
Version and safety notes
The unit example is illustrative, not safe to deploy untested. Verify orderly shutdown, correct java path, access permissions and console control on your platform.
Shutdown and recovery
Service stop behavior depends on the server process and console integration. Verify that systemctl stop performs a clean world save on your setup; a timeout may cause an unsafe kill if the server does not exit. Consider a tested shutdown/control method for your platform before production use. Do not run another terminal instance against the same world directory.
References
Check documentation for the versions and hosting environment you actually run.
Related guides
Help us improve this article
Tell us what is missing, unclear, outdated, or incorrect. You can also suggest something we should add.