diff --git a/commands/README.md b/commands/README.md index fe3a3acf..dfbc9fa0 100644 --- a/commands/README.md +++ b/commands/README.md @@ -23,6 +23,7 @@ Replace `./gameserver` with the actual script name. Every command has a short ve | [Validate](validate.md) | `./gameserver validate` | `./gameserver v` | | [Console](console.md) | `./gameserver console` | `./gameserver c` | | [Debug](debug.md) | `./gameserver debug` | `./gameserver d` | +| [Install init](install-init.md) | `./gameserver install-init` | `./gameserver ii` | ## Specific commands diff --git a/commands/install-init.md b/commands/install-init.md new file mode 100644 index 00000000..d62fc33e --- /dev/null +++ b/commands/install-init.md @@ -0,0 +1,25 @@ +# install-init +The `install-init` command can generate the contents from a systemd service file and place the contents automatically into `/etc/systemd/system` + +The naming conventions are the short name of the server (e.g. `mcserver` as minecraft server) plus `-lgsm.service` + +See [running on boot](../configuration/running-on-boot.md) for more information. + +## Commands + +Run the following command to install the systemd service files: + +Standard: `./gameserver install-init` +Short: `./gameserver ii` + +Then enter your root password. + +## Example output + +``` +[ OK ] systemd service file mcserver: Generated the file contents +Information! Enter the password of root: +Password: +Complete! Placed the file in /etc/systemd/system/ as mcserver-lgsm.service +Information! run `systemctl enable mcserver-lgsm.service` (as root), to enable the game on boot +``` diff --git a/configuration/running-on-boot.md b/configuration/running-on-boot.md index 3d91e0af..56a74ae7 100644 --- a/configuration/running-on-boot.md +++ b/configuration/running-on-boot.md @@ -3,41 +3,52 @@ ## Using systemd systemd is the default init system for most modern distros. +You can either generate and place the files contents using the install-init function, which will do it all for you, or do it manually. -You need to create a service file in `/etc/systemd/system/` +- ### Using the install-init command -Example `ts3server.service` + Run `./ install-init`, this will create and place the contents in `/etc/systemd/system/short name-lgsm.service`. + The content will be based on the manual service file. -```text -[Unit] -Description=LinuxGSM Teamspeak3 Server -After=network-online.target -Wants=network-online.target -[Service] -Type=forking -User=ts3server -WorkingDirectory=/home/ts3server -RemainAfterExit=yes #Assume that the service is running after main process exits with code 0 -ExecStart=/home/ts3server/ts3server start -ExecStop=/home/ts3server/ts3server stop -Restart=no +- ### Manual service file + + You need to create a service file in `/etc/systemd/system/` + + Example `gameserver.service` + + ```text + [Unit] + Description=LinuxGSM Game Server + After=network-online.target + Wants=network-online.target + + [Service] + Type=forking + User=gameserver + WorkingDirectory=/home/gameserver + RemainAfterExit=yes # Assume that the service is running after main process exits with code 0 + ExecStart=/home/gameserver/gameserver start + ExecStop=/home/gameserver/gameserver stop + Restart=no + + [Install] + WantedBy=multi-user.target + ``` + + Replace the user and paths to fit your setup. -[Install] -WantedBy=multi-user.target -``` -Replace the user and paths to fit your setup. You need to reload the systemd-daemon once to make it aware of the new service file by `systemctl daemon-reload` -Now you can do +Now you can do (as root) ```bash -systemctl start ts3server # Start the server -systemctl stop ts3server # Stop the server -systemctl enable ts3server # Enable start on boot -systemctl disable ts3server # Disable start on boot +systemctl start gameserver # Start the server +systemctl stop gameserver # Stop the server +systemctl enable gameserver # Enable start on boot +systemctl disable gameserver # Disable start on boot ``` ## Crontab