From 2c9a98313aa72def237a23b7e4f10063930d7985 Mon Sep 17 00:00:00 2001 From: Nathan Ogden Date: Thu, 9 Nov 2023 11:15:46 +0800 Subject: [PATCH] chore: Notes for running as system service (#1252) * Note for running as system service Note for running as system service * Additional detailing of linux service. * Added darkflame.service file changed readme to reference new file --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ systemd.example | 19 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 systemd.example diff --git a/README.md b/README.md index 287ae834..310e75eb 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,44 @@ sudo setcap 'cap_net_bind_service=+ep' AuthServer ``` and then go to `build/masterconfig.ini` and change `use_sudo_auth` to 0. +### Linux Service +If you are running this on a linux based system, it will use your terminal to run the program interactively, preventing you using it for other tasks and requiring it to be open to run the server. +_Note: You could use screen or tmux instead for virtual terminals_ +To run the server non-interactively, we can use a systemctl service by copying the following file: +```shell +cp ./systemd.example /etc/systemd/system/darkflame.service +``` + +Make sure to edit the file in `/etc/systemd/system/darkflame.service` and change the: +- `User` and `Group` to the user that runs the darkflame server. +- `ExecPath` to the full file path of the server executable. + +To register, enable and start the service use the following commands: + +- Reload the systemd manager configuration to make it aware of the new service file: +```shell +systemctl daemon-reload +``` +- Start the service: +```shell +systemctl start darkflame.service +``` +- Enable OR disable the service to start on boot using: +```shell +systemctl enable darkflame.service +systemctl disable darkflame.service +``` +- Verify that the service is running without errors: +```shell +systemctl status darkflame.service +``` +- You can also restart, stop, or check the logs of the service using journalctl +```shell +systemctl restart darkflame.service +systemctl stop darkflame.service +journalctl -xeu darkflame.service +``` + ### First admin user Run `MasterServer -a` to get prompted to create an admin account. This method is only intended for the system administrator as a means to get started, do NOT use this method to create accounts for other users! diff --git a/systemd.example b/systemd.example new file mode 100644 index 00000000..d82985df --- /dev/null +++ b/systemd.example @@ -0,0 +1,19 @@ +[Unit] +# Description of the service. +Description=Darkflame LEGO Universe Server +# Wait for network to start first before starting this service. +After=network.target + +[Service] +Type=simple +# Services should have their own, dedicated, user account. +# The specific user that our service will run as, you can find your current user by issuing `id -un` +User=darkflame +# The specific group that our service will run as, you can find your current primary group by issuing `id -gn` +Group=darkflame +# Full Path to the darkflame server process +ExecStart=/PATH/TO/DarkflameServer/build/MasterServer + +[Install] +# Define the behavior if the service is enabled or disabled to automatically started at boot. +WantedBy=multi-user.target \ No newline at end of file