Inbuilt with multi-purpose announcement bar Check here


[Linux]How To Set Your Server Up As A Service On Debian
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

#1
Today I will be showing you how to make your server into a service with systemd.

One reason to set up a server as a service is to keep it running continuously, even if the server or host is restarted. This ensures that the server will come back online as quickly as possible. I will assume you already have a server setup on Linux, if not you can follow my tutorial How To Compile Trinity Core 3.3.5a On Debian 11 – Step By Step Guide


Step 1: Creating Shell Scripts For Your Authserver And Worldserver

If you happened to followed along with my tutorial on how to compile trinity core on Debian, you can follow the steps in this tutorial exactly. Otherwise, I will assume you know where to find the necessary files.
Code:
cd /home/trinitycore/Server/bin
ls

[Image: Screen-Shot-2023-01-08-at-10.16.23-PM-1024x149.png]

Now that you are in the right directory, we will create the authserver.sh first.

Code:
sudo nano worldserver.sh

This should open a blank file, where we will insert the following lines.

Code:
#!/bin/bash
./authserver

After you have completed that, simply hit control+o followed by control+x to exit the file. Now we need to make the file excusable.

Code:
sudo chmod +x authserver.sh

Now complete the steps again for the worldserver.sh.

Code:
sudo nano worldserver.sh

Enter the same text but sightly modified for the worldserver.

Code:
#!/bin/bash
./worldserver

Let’s give this shell excusable permissions.

Code:
sudo chmod +x worldserver.sh

Step 2: Making The Service Files & Enabling Boot On Startup
We will now be navigating to systemd->system, where we will need to create two new system files.

Code:
cd /etc/systemd/system/

We will start off by making the authserver.service first, and you may do that by typing:

Code:
sudo nano authserver.service

Then we will insert the following information:

Code:
[Unit]
Description=auth
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=trinitycore
WorkingDirectory=/home/trinitycore/Server/bin
ExecStart=/bin/bash /home/trinitycore/Server/bin/authserver.sh
[Install]
WantedBy=multi-user.target

After you have inserted the following information, to save the file, press ‘Control + O’ and then ‘Control + X’. Now we will create a similar file for the worldserver.

Code:
sudo nano worldserver.service

We will then insert the following information:

Code:
[Unit]
Description=worldserver
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=trinitycore
WorkingDirectory=/home/trinitycore/Server/bin
ExecStart=/bin/bash /home/trinitycore/Server/bin/worldserver.sh
[Install]
WantedBy=multi-user.target

If you did not follow the tutorial on how to compile on Debian, you may need to modify the file locations and user references in the script.
Step 3: Enabling Boot On Startup
We will start the new services to make sure that there are no errors. If you followed this tutorial correctly, there should not be any errors.

Code:
sudo systemctl start worldserver
sudo systemctl start authserver

Now we will make it so the services will always try to stay on by typing out the following commands.

Code:
sudo systemctl enable worldserver
sudo systemctl enable authserver

You should see some text similar to this:

Code:
Created symlink /etc/systemd/system/multi-user.target.wants/authserver.service → /etc/systemd/system/authserver.service.

You have reached the end of my tutorial, it’s that simple to set your server up as a service and enable it to start upon crashing, restarting or rebooting your host.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)