Dedicated Linux server: Difference between revisions

From TF2 Classified Wiki
Jump to navigation Jump to search
Webb (talk | contribs)
Fix capitalisation on SourceMod in subtitle
Webb (talk | contribs)
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 246: Line 246:
SourceMod is a server modding platform that provides admin tools, permissions, and plugin support. Installing it is strongly recommended if you plan to run a publicly-facing server.
SourceMod is a server modding platform that provides admin tools, permissions, and plugin support. Installing it is strongly recommended if you plan to run a publicly-facing server.


You'll need to install the '''latest development version''' of SourceMod, as well as MetaMod which SourceMod depends on to work. '''It will not work with stable releases currently'''. As of writing this article, it's 7301 and 1389 respectively..
You'll need to install the '''a development version''' of SourceMod, as well as MetaMod which SourceMod depends on to work. '''It will not work with stable releases currently'''. As of writing this article, the latest known working development build is 7301 and 1389 respectively.


<pre>
<pre>
Line 264: Line 264:


Existing SourceMod plugins are not guaranteed to work and may require special steps or patching to get working.
Existing SourceMod plugins are not guaranteed to work and may require special steps or patching to get working.
==== Installing the patched TF2 Tools extension ====
Many plugins depend on the built-in TF2 Tools extension that comes with Sourcemod. This isn't compatible with TF2C. Instead, we can use a patched version of the extension which enables the use of many plugins.
There's currently no public download link for this extension. After joining the Team Fortress 2 Classified Discord server you can find the files you need in [https://discordapp.com/channels/196337717267791874/1011914229307166780/1467172013637636327 this message]. Specifically, you need <code>game.tf2.ext.2.tf2.so</code> and <code>sm-tf2.games.txt</code>.
First, we'll need to disable automatic game data updating to prevent our gamedata file from being removed.
<pre>
$ nano ~/classified/tf2classified/addons/sourcemod/configs/core.cfg
</pre>
Replace <code>"no"</code> in this part of the file with <code>"yes"</code>
<pre>
        /**
        * Enables or Disables SourceMod's automatic gamedata updating.
        *
        * The default value is "no". A value of "yes" will block the Auto Updater.
        */
        "DisableAutoUpdate"                    "no" // Change to "yes"
</pre>
Next we'll add both the gamedata file and the plugin to our installation.
<pre>
$ mv $WHEREVER_YOU_PUT_IT/sm-tf2.games.txt ~/classified/tf2classified/addons/gamedata/sm-tf2.games.txt
$ mv $WHEREVER_YOU_PUT_IT/game.tf2.ext.2.tf2.so ~/classified/tf2classified/addons/extensions/x64
</pre>
Finally, create an empty file so that the extension is automatically loaded.
<pre>
$ touch ~/classified/tf2classified/addons/sourcemod/extensions/game.tf2.autoload
</pre>


== Troubleshooting ==
== Troubleshooting ==

Latest revision as of 16:15, 21 April 2026

Reading this article

A command prefixed by # is meant to be run as root.

A command prefixed by $ is meant to be run as a regular user without root permissions. In this case the srcds user.

A command prefixed by Steam> is meant to be run inside of a SteamCMD shell.

Some commands are listed in-line with the rest of a paragraph and lack this symbol, in which case you should run the command as whichever account you're currently logged in with.

Prerequisites

  • A Linux server running Ubuntu Server* on an amd64 CPU** with root access
  • At least 25GB of free storage
  • A minimum of a ten megabit upload speed if you intend on hosting a server over the Internet, more will be needed if you host custom content
  • An opened port on your firewall for the server if you want a persistent IP address (unless using SDR, see this section on enabling the Steam Datagram Relay)
  • Optional: An SSH/SFTP client if doing remote access/file management

* This guide was written for and tested on Ubuntu Server 24.04 LTS Minimal. Other Linux distributions may use different package names and conventions.

**Architectures other than amd64 (including 32-bit x86) are unsupported. Compatibility layers like FEX or Box64 may not work or cause unexpected problems.

Preparing for install

Dependencies

We'll need to install some required software and tools for our server first. Let's start with SteamCMD, which we'll use to download and update the server software.

Since SteamCMD is built for 32-bit, we'll need to enable 32-bit packages. We'll also add the multiverse repository which has SteamCMD.

# add-apt-repository multiverse
# dpkg --add-architecture i386
# apt update

Next, we'll install the dialog package so the Steam Subscriber Agreement dialog works, and then the rest of the packages we need.

# apt install dialog
# apt install steamcmd p7zip aria2 tilde lib32z1 libbz2-1.0:i386 lib32gcc-s1 lib32stdc++6 libcurl3-gnutls:i386 libsdl2-2.0-0:i386 wget

If your version of Ubuntu doesn't come with a text editor, you may install one now. For this guide we'll use nano.

# apt install nano

Creating a user for the server

Pick a directory to install your server into. Many put it under a directory in /opt, but for this guide we'll be using /home/srcds.

Create a disabled user with a home directory.

# useradd -s /bin/false -mr srcds

-m creates a home directory for the new user, -r specifies that it's a system account that will not have a password, and -s /bin/false prevents the account from having a default shell.

Installing the live TF2 server

The live version of TF2's dedicated server is required to run a Classified server.

# sudo -Hu srcds bash
$ cd ~
$ . /etc/environment
$ steamcmd
Steam>force_install_dir /home/srcds/tf
Steam>login anonymous
Steam>app_update 232250 validate
Steam>quit

Installing the dedicated server

Ensure you've quit SteamCMD before continuing.

$ cd ~
$ . /etc/environment
$ steamcmd
Steam>force_install_dir /home/srcds/classified
Steam>login anonymous
Steam>app_update 3557020 validate
Steam>quit

Before continuing, we'll need to symlink the install's steamclient.so to a special directory.

$ mkdir -p ~/.steam/sdk64
$ ln -s ~/classified/linux64/steamclient.so ~/.steam/sdk64/

Testing the server

Before proceeding, we can manually run the server to make sure the install was successful.

$ cd ~/classified
$ ./srcds.sh -port 27015 -tf_path ~/tf +map ctf_2fort +sv_password changethis

If all goes well, it should start and be accessible over the internet.

Server configuration

For a basic, private server, you should only need to set a password in classified/tf2classified/cfg/server.cfg by appending the file with sv_password yourpassword. You can also make it LAN-only by appending sv_lan 1 in the same file.

If you want a more complicated setup, consider using cfg.tf. If you don't need this you can skip to the next section.

Make sure the server type is set to “Internet and LAN” if you want players outside your LAN to be able to join (you may need to port forward if you’re on consumer broadband or open ports on your firewall).

Upload the generated ZIP file to your server, perhaps using SFTP, and unzip the folder.

$ cd /tmp
$ unzip $PATH_TO_ARCHIVE

And merge the cfg folder with /home/srcds/classified/tf2classified/cfg.

$ rsync /tmp/cfg ~/classified/tf2classified/cfg
$ rm -rf /tmp/cfg

Managing the server via Systemd

Systemd is a program that will automatically handle things like logging, restarts, and starting your server when your machine boots. We'll use this to run our server, instead of manually running commands.

Creating an update script

We're going to create a script that will update the dedicated server for us instead of typing it out manually each time. Later, we'll optionally use this script to check and update our server automatically when the server starts.

First, let's create a directory for the script.

$ mkdir ~/bin
$ nano ~/bin/update-classified.steamcmd

Fill the file with the following contents:

@ShutdownOnFailedCommand 1 //set to 0 if updating multiple servers at once
@NoPromptForPassword 1
force_install_dir /home/srcds/classified
login anonymous
app_update 3557020
quit

You can execute this script manually by using the +runscript argument on SteamCMD.

$ . /etc/environment
$ steamcmd +runscript /home/srcds/bin/update-classified.steamcmd

Similarly, we will create one for the live TF2 server as that will need to be updated occasionally. We'll put it at /home/srcds/bin/update-tf.steamcmd.

@ShutdownOnFailedCommand 1 //set to 0 if updating multiple servers at once
@NoPromptForPassword 1
force_install_dir /home/srcds/tf
login anonymous
app_update 232250
quit

Creating a service file

Create a service file in /etc/systemd/system/ as root. For this guide we'll use /etc/systemd/system/tf2c.service.

[Unit]
Description=TF2C Server
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=srcds
StandardError=journal
StandardOutput=journal
WorkingDirectory=/home/srcds/classified
RemainAfterExit=no
ExecStartPre=-/usr/games/steamcmd +runscript /home/srcds/bin/update-tf.steamcmd
ExecStartPre=-/usr/games/steamcmd +runscript /home/srcds/bin/update-classified.steamcmd
Environment="LD_LIBRARY_PATH=".:bin/linux64:$LD_LIBRARY_PATH""
ExecStart=/usr/bin/script -e -c "/home/srcds/classified/srcds_linux64 -port 27015 -tf_path /home/srcds/tf +map ctf_2fort +maxplayers 24" /dev/null
TimeoutStartSec=infinity
Restart=always

[Install]
WantedBy=multi-user.target

Then, enable the service to start with Systemd on boot.

# systemctl enable tf2c.service

You may create as many services as you have TF2C servers but remember to name the service files uniquely. When modifying existing service files, remember to run systemctl daemon-reload before restarting the service.

Automatic restarts using crontab

Cron is a program built into most Linux distros that runs scheduled commands.

As root, execute crontab -e. This will open a special file in your editor where you can declare what jobs you want to run and when. Let's add a job to run at 04:00 that will restart our server.

0 4 * * * systemctl restart tf2c.service

Manually managing services

If you don't wish to use the service files above to automatically boot servers, or you need to perform these actions for maintenance: you may issue commands to manually start, stop, restart, or update the server(s) through systemd.

# systemctl restart tf2c # in case you need to restart manually or to grab updates!! 
# systemctl stop tf2c # in case you need to stop the server manually
# systemctl start tf2c # in case you need to start the server manually
# systemctl disable tf2c # in case you need to stop the server from booting as your system initializes 
# systemctl enable tf2c # in case you need to start the server to boot as your system initializes 

Extras

Enabling the Steam Datagram Relay

Servers can use the Steam Datagram Relay. It masks your server's IP address, helps prevent DDoS attacks, and allows you to run a server without port forwarding or configuring firewalls. However, this comes at the cost of added latency and using ephemeral IP addresses for your server, the latter breaking server favoriting and IP bans.

You can enable this by adding sv_use_steam_networking 1 to classified/tf2classified/cfg/default.cfg.

If you want your server to appear on the server browser with SDR enabled you will need to supply a GLST token. You can acquire a key by going to this page. Once you've got it, put sv_setsteamaccount $KEY in your configuration, replacing $KEY with the token from the page.

Installing SourceMod

SourceMod is a server modding platform that provides admin tools, permissions, and plugin support. Installing it is strongly recommended if you plan to run a publicly-facing server.

You'll need to install the a development version of SourceMod, as well as MetaMod which SourceMod depends on to work. It will not work with stable releases currently. As of writing this article, the latest known working development build is 7301 and 1389 respectively.

$ cd ~
$ wget https://mms.alliedmods.net/mmsdrop/2.0/mmsource-2.0.0-git1389-linux.tar.gz -O /tmp/mm.tar.gz
$ wget https://sm.alliedmods.net/smdrop/1.13/sourcemod-1.13.0-git7301-linux.tar.gz -O /tmp/sm.tar.gz
$ tar -xf /tmp/mm.tar.gz
$ tar -xf /tmp/sm.tar.gz
$ mv addons ~/classified/tf2classified
$ mv cfg/sourcemod ~/classified/tf2classified/cfg
$ rm -r cfg
$ rm /tmp/mm.tar.gz
$ rm /tmp/sm.tar.gz

Once the server starts it should work. A good way to test if everything is running properly is to use the !motd command in chat. If the MOTD pops up after the command that means SourceMod is working. For further information on setting up SourceMod, read the documentation.

Existing SourceMod plugins are not guaranteed to work and may require special steps or patching to get working.

Installing the patched TF2 Tools extension

Many plugins depend on the built-in TF2 Tools extension that comes with Sourcemod. This isn't compatible with TF2C. Instead, we can use a patched version of the extension which enables the use of many plugins.

There's currently no public download link for this extension. After joining the Team Fortress 2 Classified Discord server you can find the files you need in this message. Specifically, you need game.tf2.ext.2.tf2.so and sm-tf2.games.txt.

First, we'll need to disable automatic game data updating to prevent our gamedata file from being removed.

$ nano ~/classified/tf2classified/addons/sourcemod/configs/core.cfg

Replace "no" in this part of the file with "yes"

        /**
         * Enables or Disables SourceMod's automatic gamedata updating.
         *
         * The default value is "no". A value of "yes" will block the Auto Updater.
         */
        "DisableAutoUpdate"                     "no" // Change to "yes"

Next we'll add both the gamedata file and the plugin to our installation.

$ mv $WHEREVER_YOU_PUT_IT/sm-tf2.games.txt ~/classified/tf2classified/addons/gamedata/sm-tf2.games.txt
$ mv $WHEREVER_YOU_PUT_IT/game.tf2.ext.2.tf2.so ~/classified/tf2classified/addons/extensions/x64

Finally, create an empty file so that the extension is automatically loaded.

$ touch ~/classified/tf2classified/addons/sourcemod/extensions/game.tf2.autoload

Troubleshooting

Sounds are missing/only stock weapons are usable

This is likely due to a problem with libvstdlib.so. It's possible it wasn't updated or is corrupted. Validate your install.

$ cd ~
$ . /etc/environment
$ steamcmd
Steam>force_install_dir /home/srcds/classified
Steam>login anonymous
Steam>app_update 3557020 validate
Steam>quit

Server not showing up on the server browser while using SDR

This is likely happening because you enabled use of the SDR but didn't supply a game key. Read the last paragraph of this section for more information.

Server using high levels of CPU when ran via the service file

The service file included in this guide has a workaround for Source servers refusing to log without a TTY present. There has been at least one report of this causing unusually high CPU usage. It's believed this happens on servers with slower SSDs and spinning hard drives. You can disable it, but it will mean there will be no journald logs for your server and you can't use features like Systemd sockets.

To disable it, unwrap the srcds_linux64 command from script.

ExecStart=/usr/bin/script -e -c "/home/srcds/classified/srcds_linux64 -port 27015 -tf_path /home/srcds/tf +map ctf_2fort +maxplayers 24" /dev/null
ExecStart=/home/srcds/classified/srcds_linux64 -port 27015 -tf_path /home/srcds/tf +map ctf_2fort +maxplayers 24