|
| 1 | +## Linux Unit File for Minecraft Server |
| 2 | + |
| 3 | +This is a unit file to stop and start Minecraft server using systemd. |
| 4 | + |
| 5 | +This file must be placed in `/etc/systemd/system` |
| 6 | + |
| 7 | +Please modify the **Description** and **WorkingDirectory** to use this unit file. |
| 8 | + |
| 9 | +> **For those who are not familiar with unit file, here are some of the additional information** |
| 10 | +> |
| 11 | +> Description=xxxxx is a description that shown when running `sudo systemctl status minecraft.service` |
| 12 | +> |
| 13 | +> WorkingDirectory=xxxx is the folder that the server is located, recommanded to put it inside /opt/ or /srv/ (eg /opt/minecraft_server) |
| 14 | +> |
| 15 | +> Whenever you modified the file, please run `sudo systemctl daemon-reload` to update the systemd |
| 16 | +
|
| 17 | +--- |
| 18 | + |
| 19 | +To use this script, user named `minecraft` must present in the server. To create it please run `sudo useradd -s /bin/bash -m minecraft`, then `sudo passwd minecraft` to assign a password to the user. |
| 20 | + |
| 21 | +Screen command must also need to be installed. To install it on Ubuntu, please run `sudo apt install screen` |
| 22 | + |
| 23 | +A `start.sh` bash script is recommended, you can generate it in here: [Start Script Generator | PaperMC Docs](https://docs.papermc.io/misc/tools/start-script-gen) |
| 24 | + |
| 25 | +In this unit file, it will automatically execute the `./start.sh` file located in the in the root directory of the Minecraft server using a screen instance as the user `minecraft`. |
| 26 | + |
| 27 | +--- |
| 28 | + |
| 29 | +**To enable the auto-start of the server during the boot process, please run** |
| 30 | +`sudo systemctl enable minecraft.service` |
| 31 | + |
| 32 | +**To disable the auto-start of the server during the boot process, please run** |
| 33 | +`sudo systemctl disable minecraft.service` |
| 34 | + |
| 35 | +**To start the server manually, please run** |
| 36 | +`sudo systemctl start minecraft.service` |
| 37 | + |
| 38 | +**To stop the server manually, please run** |
| 39 | +`sudo systemctl stop minecraft.service` |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +For more information regarding systemd and unit file, please refer to this article [systemd - ArchWiki (archlinux.org)](https://wiki.archlinux.org/title/systemd) |
0 commit comments