Modern SrcDS for L4D2 on Linux

by Jake Basile on 2012-07-30

As it says in the sidebar, I am not just a programmer, but a gamer as well. These paths sometimes cross in interesting ways, most recently while trying to run a L4D2 server for some of my friends to blast zombies on.

As anyone who has tried to do this on Linux knows, SrcDS is a painful thing. Many of the tutorials are outdated. It can't daemonize itself. Overall, fun times. Here is how I made it a bit less painful.

Step One: The Server

Just grab a server on any number of hosting platforms. Rackspace is where I got mine, but EC2 should work too. Get one with at least 512MB RAM and 20GB of storage to avoid pain, the more the better. Put Ubuntu 12.04 LTS on it.

After SSHing into the server, I proceeded to make myself a l4d2 account on the server, so I didn't have to log in as root:

# adduser l4d2
# adduser l4d2 sudo

I then logged out and back in as the new l4d2 user.

Step Two: Steam

You need the Steam binary to download the game files that SrcDS needs. You get the Steam binary through hldsupdatetool.bin, which needs the ia32-libs package. Make all this happen by running the following commands:

$ sudo apt-get update
$ sudo apt-get install ia32-libs
$ wget http://www.steampowered.com/download/hldsupdatetool.bin
$ chmod +x hldsupdatetool.bin
$ ./hldsupdatetool.bin
$ ./steam

Step Three: The Game

As stated, I'm planning on running an L4D2 server. You should be able to run any Source game on this server though, by using the appropriate game name to the -game switch to steam. My command was the following:

$ ./steam -command update -dir . -game left4dead2

This particular command will take quite some time. Let it spin and download what is needed.

Step Four: The Config

There are as many config files as their are server admins, but here's mine for an L4D2 co-op only server:

hostname <Your Server Name>
sv_search_key <Your Super Secret Key>
sv_allow_lobby_connect_only 0
sv_consistency 1
sv_voiceenable 1
sv_lan 0
sv_pure 1
sv_cheats 0
sv_gametypes "coop,versus"
sv_logecho 1

You may change it as you see fit. Put this text into a file at ~/left4dead2/left4dead2/cfg/server.cfg.

Step Five: Running The Server

To run it, I used Supervisor, my go-to process management software. Set it up by first installing it:

$ sudo apt-get install supervisor

And then configure it by changing your /etc/supervisor/supervisord.conf file. You'll need to sudo editing it. Add the following section:

[program:srcds]
command=/home/l4d2/left4dead2/srcds_run -console -game left4dead2 +maxplayers 8 +ip <Your Server's IP> -autoupdate -norestart
stdout_logfile=logs/srcds.txt
stderr_logfile=logs/srcds-err.txt
priority=1
user=l4d2

Be sure to create the logs directory with:

$ mkdir ~/logs

You then can start the server by running:

$ sudo supervisorctl reload

Step Six: The Security

Setting up some minor security on your new server is prudent. You can enable the firewall with these commands:

$ sudo ufw allow 22
$ sudo ufw allow 27015
$ sudo ufw allow 27016
$ sudo ufw allow 27017
$ sudo ufw default deny
$ sudo ufw enable

Step Seven: The Game

You can now force L4D2 to join your server by putting sv_search_key <your search key> into "Set Launch Options...", available from the game properties menu in Steam. Then start a new lobby, invite your friends, and pick "Best Dedicated Server".

Modify the config as you see fit and restart with sudo supervisorctl restart srcds. Shoot zombies and have fun.