User:Webb/New linux server: Difference between revisions
From TF2 Classified Wiki
More actions
No edit summary |
More work |
||
| Line 124: | Line 124: | ||
=== Testing the server === | === Testing the server === | ||
Before proceeding, we can test the server to make sure the install | Before proceeding, we can test the server to make sure the install runs. | ||
<pre> | <pre> | ||
| Line 131: | Line 131: | ||
</pre> | </pre> | ||
If all goes well, it should | If all goes well, it should start. | ||
=== Server Configuration === | === Server Configuration === | ||
| Line 141: | Line 141: | ||
Upload the generated ZIP file to your server using SFTP, unzip the folder using: | Upload the generated ZIP file to your server using SFTP, unzip the folder using: | ||
<pre>unzip | <pre> | ||
$ cd /tmp | |||
$ unzip $PATH_TO_ARCHIVE</pre> | |||
And merge the <code>cfg</code> folder with <code>/home/srcds/sdk/tf2classic/cfg/</code>. | And merge the <code>cfg</code> folder with <code>/home/srcds/sdk/tf2classic/cfg/</code>. | ||
<pre> | |||
$ rsync /tmp/cfg ~/srcds/sdk/tf2classic/cfg | |||
$ rm -rf /tmp/cfg | |||
</pre> | |||
== | == Running 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 SDK 2013 update script === | |||
We're going to create a script that will update our SDK 2013 for us instead of typing it out manually each time. Later, we'll optionally use this script to check and update SDK 2013 on our server. | |||
First, let's create a directory for the script. | |||
<pre> | <pre> | ||
$ | $ mkdir ~/bin | ||
$ nano ~/bin/update-sdk.steamcmd | |||
</pre> | </pre> | ||
Inside this file, place the following contents: | |||
<pre> | <pre> | ||
@ShutdownOnFailedCommand 1 //set to 0 if updating multiple servers at once | @ShutdownOnFailedCommand 1 //set to 0 if updating multiple servers at once | ||
@NoPromptForPassword 1 | @NoPromptForPassword 1 | ||
force_install_dir /home/srcds/sdk | |||
login anonymous | login anonymous | ||
app_update 244310 -beta previous2021 | app_update 244310 -beta previous2021 | ||
| Line 187: | Line 178: | ||
</pre> | </pre> | ||
You can execute this script manually by using the +runscript argument on SteamCMD. | |||
<pre> | |||
$ . /etc/environment | |||
$ steamcmd +runscript /home/srcds/bin/update-sdk.steamcmd | |||
</pre> | |||
=== Creating a service file === | |||
Example <code> | Create a service file in <code>/etc/systemd/system/</code> as root. | ||
Example <code>tf2c.service</code>: | |||
<pre> | <pre> | ||
[Unit] | [Unit] | ||
Description= | Description=TF2C | ||
After=network-online.target | After=network-online.target | ||
Wants=network-online.target | Wants=network-online.target | ||
[Service] | [Service] | ||
Type= | Type=simple | ||
User= | User=srcds | ||
WorkingDirectory=/home/ | StandardError=journal | ||
RemainAfterExit= | StandardOutput=journal | ||
ExecStartPre=/usr/games/steamcmd +runscript / | WorkingDirectory=/home/srcds/sdk | ||
RemainAfterExit=no | |||
ExecStartPre=/usr/games/steamcmd +runscript /home/srcds/bin/update-sdk.steamcmd # Exclude or comment this if you don't want to check for an update on each restart | |||
Environment="LD_LIBRARY_PATH=".:bin:$LD_LIBRARY_PATH"" | |||
ExecStart=/usr/bin/script -e -c "/home/srcds/sdk/srcds_linux +map ctf_2fort -game tf2classic -port 27000 +maxplayers 26" /dev/null | |||
TimeoutStartSec=infinity | TimeoutStartSec=infinity | ||
Restart=always | Restart=always | ||
[Install] | |||
WantedBy=multi-user.target | |||
[Install] | [Install] | ||
| Line 220: | Line 221: | ||
</pre> | </pre> | ||
=== Automatic restarts using crontab === | |||
As root, execute <code>crontab -e</code>. This will open a special file where you can set cronjobs. For example, adding the following line will restart your game server every day at 04:00: | |||
<pre> | <pre> | ||
0 4 * * * systemctl restart tf2classic.service | 0 4 * * * systemctl restart tf2classic.service | ||
</pre> | </pre> | ||