Dedicated legacy Linux server: Difference between revisions
From TF2 Classified Wiki
More actions
mNo edit summary |
Added section for cron and systemd service for automation |
||
| Line 148: | Line 148: | ||
More advanced users will likely want to run it using GNU Screen, or using a systemd service, which will be documented here eventually. | More advanced users will likely want to run it using GNU Screen, or using a systemd service, which will be documented here eventually. | ||
== Systemd & Crontab for Automatic Start, Restart and Updating== | |||
For easier automation of server restarts, updating, and booting alongside the system, you may use systemd, which is the default init system for most modern Linux distros and cronjobs. | |||
Create file <code>ssdk2013mp-update</code> and fill in the following | |||
<pre> | |||
@ShutdownOnFailedCommand 1 //set to 0 if updating multiple servers at once | |||
@NoPromptForPassword 1 | |||
login anonymous | |||
app_update 244310 | |||
quit | |||
</pre> | |||
Make it executable with <code>chmod +x ssdk2013mp-update</code> | |||
This script will update the underlying Source SDK 2013 MP Dedicated Server, you may execute it by itself, but in this case we will use it for automatic updates. | |||
Next, create a service file in <code>/etc/systemd/system/</code> | |||
Example <code>tf2classic.service</code>: | |||
<pre> | |||
[Unit] | |||
Description=TF2Classic | |||
After=network-online.target | |||
Wants=network-online.target | |||
[Service] | |||
Type=forking | |||
User=steam | |||
WorkingDirectory=/home/tf2classic | |||
RemainAfterExit=yes | |||
ExecStartPre=/usr/games/steamcmd +runscript /opt/tf2classic/ssdkb2013mp-update | |||
ExecStartPre=/opt/tf2classic/TF2CDownloaderLinux --update | |||
ExecStart=/opt/tf2classic/server/srcds_run -console -game tf2classic +map tr_walkway_fastcat_v1 -port 27020 +maxplayers 32 +sv_setsteamaccount XXXXXXX | |||
TimeoutStartSec=infinity | |||
Restart=always | |||
[Install] | |||
WantedBy=multi-user.target | |||
</pre> | |||
Then, enable the service to start with the init system: | |||
<pre> | |||
# systemctl enable tf2classic.service | |||
</pre> | |||
Next, switch to the <code>root</code> user using <code>sudo su</code> and execute <code>crontab -e</code>. This is where you can set cronjobs, include something like the following: | |||
<pre> | |||
# Restart and update check for TF2Classic every day at 4 AM. | |||
0 4 * * * systemctl restart tf2classic.service | |||
</pre> | |||
You may create as many services as you have TF2C servers but remember to name the service files uniquely, enable them in <code>systemctl</code>, and add them to the <code>crontab</code>. | |||
''</br>See also [[Dedicated_Linux_server_extras|Dedicated Linux Server Extras]].'' | |||
[[Category:Guides]] | [[Category:Guides]] | ||