[Linux]How To Set Your Server Up As A Service On Debian

PrivateDonut

Account Closed
banned
Rep
3
0
0
Rep
3
Vouches
0
0
0
Vouches
0
Posts
533
Likes
444
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 31 71 XP
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 Tutorial

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.

cd /home/trinitycore/Server/bin
ls
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.
sudo nano worldserver.sh

This should open a blank file, where we will insert the following lines.
#!/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.

sudo chmod +x authserver.sh
Now complete the steps again for the worldserver.sh.

sudo nano worldserver.sh
Enter the same text but sightly modified for the worldserver.

#!/bin/bash
./worldserver

Let’s give this shell excusable permissions.
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.

cd /etc/systemd/system/

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

Then we will insert the following information:
[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.

sudo nano worldserver.service
We will then insert the following information:

[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.

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.
sudo systemctl enable worldserver
sudo systemctl enable authserver
You should see some text similar to this:

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.
 
Last edited:

Instadev

MySQL & C++ Developer
banned
Instadev Rep
4
0
0
Rep
4
Instadev Vouches
0
0
0
Vouches
0
Posts
338
Likes
153
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 2 90 XP
Thank you so much!
 
Liked By 1 member :

splicho

Emudevs Founder
Administrator
splicho Rep
6
0
0
Rep
6
splicho Vouches
3
0
0
Vouches
3
Posts
1,003
Likes
1,424
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 248 60 XP
Nice guide, Randy. I am pretty sure this will be useful for someone :peepoHey:
 
Liked By 1 member :

Maijkl

New member
Maijkl Rep
0
0
0
Rep
0
Maijkl Vouches
0
0
0
Vouches
0
Posts
1
Likes
0
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 1 105 XP
Hey, buddy,

thank you for the instructions, it works just as it should. I just have one problem. The service is already running, how do I connect to the currently running service, what if I want to get into the TC terminal to type commands like reload all, debug, account create.... so I don't have to log the game. I know that this can be solved via screen session, but maybe there is another way in your case. Thank you for your help.
 

PrivateDonut

Account Closed
banned
Rep
3
0
0
Rep
3
Vouches
0
0
0
Vouches
0
Posts
533
Likes
444
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 31 71 XP
Hey, buddy,

thank you for the instructions, it works just as it should. I just have one problem. The service is already running, how do I connect to the currently running service, what if I want to get into the TC terminal to type commands like reload all, debug, account create.... so I don't have to log the game. I know that this can be solved via screen session, but maybe there is another way in your case. Thank you for your help.

Glad it's working for you! As far as I know there is no way to connect to the terminal while the service is running. You can check common things in the logs, but if you need to run any specific commands in the console, you would need to turn the service off, and start it manually to view the console. It's just the way it's designed on Debian. :(

Unless there is a way that I just don't know.
 

Tommy

Staff
Staff
Tommy Rep
1
0
0
Rep
1
Tommy Vouches
0
0
0
Vouches
0
Posts
185
Likes
101
2 YEARS
2 YEARS OF SERVICE
LEVEL 6 310 XP
Simple and easy guide! Thanks for sharing. \o/
 

Kerpackie

Well-known member
Kerpackie Rep
3
0
0
Rep
3
Kerpackie Vouches
0
0
0
Vouches
0
Posts
164
Likes
130
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 1 105 XP
Glad it's working for you! As far as I know there is no way to connect to the terminal while the service is running. You can check common things in the logs, but if you need to run any specific commands in the console, you would need to turn the service off, and start it manually to view the console. It's just the way it's designed on Debian. :(

Unless there is a way that I just don't know.
You are correct, usually long-running services use some form of configuration file which you update and then restart the service to read in the updated config. So it wouldn't really be adaptive for things such as running commands to create an account etc. Some form of API would need to be built to allow accessing the service remotely through a different means than the terminal, or at least directly with the service VIA Terminal.

Great guide btw, very useful for lots of things, not just running WoW Servers!
 

RedLine

Divine
Divine
RedLine Rep
0
0
0
Rep
0
RedLine Vouches
0
0
0
Vouches
0
Posts
74
Likes
28
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 4 205 XP
Neat and solid !
 

3,389

1,271

9,555

428

Top