Difference between revisions of "SystemD Server Guide"
From Unofficial Stationeers Wiki
m (Fixed minor typos) |
(No need to edit this file manually. Furthermore, it's not safe and error prone.) |
||
(5 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | [Category:Tutorials]] | + | [[Category:Tutorials]] |
== Requirements == | == Requirements == | ||
Line 10: | Line 10: | ||
To maximize server security, we will be setting up a dedicated user that only has the privileges to run the dedicated server, and nothing else. | To maximize server security, we will be setting up a dedicated user that only has the privileges to run the dedicated server, and nothing else. | ||
− | <code>sudo useradd -m | + | <code>sudo useradd -m -s /sbin/nologin stationeers</code> |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Installing SteamCmd == | == Installing SteamCmd == | ||
Line 51: | Line 45: | ||
<code>ExecStart</code> starts the Stationeers dedicated server. Be sure to replace all the UPPERCASE entries with what you want for your server. See here: https://github.com/rocket2guns/StationeersDedicatedServerGuide/blob/main/README.md<br> | <code>ExecStart</code> starts the Stationeers dedicated server. Be sure to replace all the UPPERCASE entries with what you want for your server. See here: https://github.com/rocket2guns/StationeersDedicatedServerGuide/blob/main/README.md<br> | ||
<code>User</code> and <code>Group</code> ensures that the dedicated server runs with the user we set up earlier.<br> | <code>User</code> and <code>Group</code> ensures that the dedicated server runs with the user we set up earlier.<br> | ||
− | <code>StandardOutput=journal</code> directs all log-messages to the system journal. If something goes wrong, you don't have to locate any log-files, you just run the command <code>journalctl -fu stationeers</code> to browse the journal for what | + | <code>StandardOutput=journal</code> directs all log-messages to the system journal. If something goes wrong, you don't have to locate any log-files, you just run the command <code>journalctl -fu stationeers</code> to browse the journal for what the user <code>stationeers</code> has output.<br> |
<code>Restart=on-failure</code> ensures that if the server crashes, it will automatically restart.<br> | <code>Restart=on-failure</code> ensures that if the server crashes, it will automatically restart.<br> | ||
<code>WorkingDirectory=/home/stationeers</code> makes sure that everything we do assumes that we're standing in this folder when we do it. It's kind of redundant here, but I keep it in for safety. | <code>WorkingDirectory=/home/stationeers</code> makes sure that everything we do assumes that we're standing in this folder when we do it. It's kind of redundant here, but I keep it in for safety. | ||
Line 58: | Line 52: | ||
Now that we've created the service-file, we have to let SystemD know it's there. Run <code>sudo systemctl daemon-reload</code> to do that. Any time you edit the service-file, you have to run this command to make SystemD aware of the changes you've made. | Now that we've created the service-file, we have to let SystemD know it's there. Run <code>sudo systemctl daemon-reload</code> to do that. Any time you edit the service-file, you have to run this command to make SystemD aware of the changes you've made. | ||
− | That's it! All we need to do now is run <code>sudo systemctl start stationeers</code>, and it will download Stationeers Dedicated Server, start it with the parameters we've set, and run until we either reboot the machine, or run <code>sudo systemctl stop stationeers</code>. | + | That's it! All we need to do now is run <code>sudo systemctl start stationeers</code>, and it will download Stationeers Dedicated Server, start it with the parameters we've set, and run until we either reboot the machine, or run <code>sudo systemctl stop stationeers</code>.<br> |
+ | If there's an update to Stationeers, just run <code>sudo systemctl restart stationeers</code>, and the <code>ExecStartPre</code> line in the service-file will ensure that <code>steamcmd</code> downloads the latest version. | ||
Want the dedicated server to start with the machine every time you reboot? Just run <code>sudo systemctl enable stationeers</code> to enable start-on-boot, and <code>sudo systemctl disable stationeers</code> to disable it again. | Want the dedicated server to start with the machine every time you reboot? Just run <code>sudo systemctl enable stationeers</code> to enable start-on-boot, and <code>sudo systemctl disable stationeers</code> to disable it again. |
Latest revision as of 02:53, 12 April 2023
Contents
Requirements[edit]
- A machine that runs any Linux distribution that uses SystemD
- Access to, and basic knowledge of your Linux shell
-
sudo
-rights - At least 16GB RAM
Preparing the server[edit]
To maximize server security, we will be setting up a dedicated user that only has the privileges to run the dedicated server, and nothing else.
sudo useradd -m -s /sbin/nologin stationeers
Installing SteamCmd[edit]
Follow the instructions here to get SteamCmd installed: https://developer.valvesoftware.com/wiki/SteamCMD#Package_From_Repositories
Creating the SystemD service[edit]
Now it's time to create the service-file for SystemD so we can use it to control starting and stopping the Stationeers server.
sudo nano /etc/systemd/system/stationeers.service
Paste the following into the editor:
[Unit]
Description=Stationeers Dedicated Server
Wants=network-online.target
After=syslog.target network.target nss-lookup.target network-online.target
[Service]
Environment="LD_LIBRARY_PATH=./linux64"
ExecStartPre=/usr/games/steamcmd +force_install_dir "/home/stationeers/StationeersDedicatedServer" +login anonymous +app_update 600760 validate +quit
ExecStart=/home/stationeers/StationeersDedicatedServer/rocketstation_DedicatedServer.x86_64 -loadlatest "NAME_OF_SAVE" PLANET -difficulty DIFFICULTY_SETTING -settings StartLocalHost true ServerVisible true LocalIpAddress IP_ADDRESS ServerName "NAME_IN_SERVER_LIST" ServerPassword "YOUR_SECURE_PASSWORD" ServerMaxPlayers MAX_PLAYERS UPNPEnabled false
User=stationeers
Group=stationeers
StandardOutput=journal
Restart=on-failure
WorkingDirectory=/home/stationeers
[Install]
WantedBy=multi-user.target
The stuff under [Unit]
and [Install]
is just to name the service in Linux, and declare when it's safe to start. It's the stuff under [Service]
that is the "business end" of this file.
ExecStartPre
runs the steamcmd
application to update the dedicated server. You might want to check that steamcmd
is actually installed in /usr/games/ by running the following command: find /usr/ -name "steamcmd"
ExecStart
starts the Stationeers dedicated server. Be sure to replace all the UPPERCASE entries with what you want for your server. See here: https://github.com/rocket2guns/StationeersDedicatedServerGuide/blob/main/README.md
User
and Group
ensures that the dedicated server runs with the user we set up earlier.
StandardOutput=journal
directs all log-messages to the system journal. If something goes wrong, you don't have to locate any log-files, you just run the command journalctl -fu stationeers
to browse the journal for what the user stationeers
has output.
Restart=on-failure
ensures that if the server crashes, it will automatically restart.
WorkingDirectory=/home/stationeers
makes sure that everything we do assumes that we're standing in this folder when we do it. It's kind of redundant here, but I keep it in for safety.
Wrapping it all up[edit]
Now that we've created the service-file, we have to let SystemD know it's there. Run sudo systemctl daemon-reload
to do that. Any time you edit the service-file, you have to run this command to make SystemD aware of the changes you've made.
That's it! All we need to do now is run sudo systemctl start stationeers
, and it will download Stationeers Dedicated Server, start it with the parameters we've set, and run until we either reboot the machine, or run sudo systemctl stop stationeers
.
If there's an update to Stationeers, just run sudo systemctl restart stationeers
, and the ExecStartPre
line in the service-file will ensure that steamcmd
downloads the latest version.
Want the dedicated server to start with the machine every time you reboot? Just run sudo systemctl enable stationeers
to enable start-on-boot, and sudo systemctl disable stationeers
to disable it again.