SRCDS Steam group


Running SRCDS as a Windows Service with crash (normal and hung srcds) protection
#1
I have been looking for something like this for ages, and I finally found one. I hope you guys enjoy it.

For this guide, I assume that you are comfortable with:
  • The command line (if you don't know what this is, go learn then continue)
  • SRCDS and know how to run it from the command line (if you don't know what this is, go learn then continue)
  • Editing the registry (hopefully it won't come to this, but you should know how)

Phase 1:

First, what is a Windows Service? A Windows Service allows a program to run in the background without a user being logged in (that's how I think of it).

Why would you want to run SRCDS as a Windows Service?
  • You don't need someone logged into the box to keep the servers running (wasting memory and CPU time)
  • You can start and stop them at the push of a button
  • If setup properly, they will automatically restart SRCDS if it crashes

There are lots of different ways to do this, many of which are not very good.

With the method I use in this guide:
  • Stopping the service will kill the SRCDS process
  • If SRCDS crashes or closes, it will automatically restart

********** WARNING **********

The actions described in this guide involve using a piece of software that modifies the Windows Registry. If you are following the steps in this guide, I am assuming that you know what the implications are. If you do not, I suggest you stop reading now.

I take no responsibility for any damages that you incur as a result of this guide.

********** WARNING **********

Paths:

I am assuming that
  • The root of your SRCDS server is %SRCDSSERVER%
  • You extracted the SrvStart package to %SRVSTART%
  • You created the config file %SRVSTART%\config.txt

Steps:
  1. Download SrvStart (the Executable package) from here.
  2. Extract it to %SRVSTART%
  3. Create a blank text file with Notepad in %SRVSTART% called config.txt
Now let's pause for a second and talk about how SrvStart works. SrvStart gets all the parameters (e.g. what programs to start and how to start them) from a config file. The config file is in a basic ini format. There is a section for each service / program that you want to start and values in that section saying how exactly to start and monitor it.

# This is a ep1 engine cstrike server
[srcds_srv_1]
startup=%SRCDSSERVER%\srcds.exe -console -autoupdate -game cstrike +map de_dust2 +maxplayers 16 -ip 0.0.0.0 -port 27015 -tickrate 66 +fps_max 500
startup_dir=%SRCDSSERVER%
shutdown_method=kill
auto_restart=y

# This is an ep2 engine gmod 10 server
[srcds_srv_2]
startup=%SRCDSSERVER%\orangebox\srcds.exe -console -autoupdate -game garrysmod +map gm_construct +maxplayers 16 -ip 0.0.0.0 -port 27016 -tickrate 66 +fps_max 500
startup_dir=%SRCDSSERVER%\orangebox
shutdown_method=kill
auto_restart=y

Each section starts with a name in square brackets, and goes to the beginning of the next section. You can provide global options at the top of the file before any sections, but I haven't used that yet so I can't advise it.

The section names are names of Windows Services. When SrvStart exe runs (as a programmer, this is my guess), it gets the name of the service it's supposed to run and searches the config file for a section matching that name.

For each SRCDS server you want to run, you must create a Windows Service AND a matching section in the config file for each one.

Setup all the SRCDS servers you want to run in your configuration file and save it as %SRVSTART%\config.txt.

For this guide, I am assuming that you are using the exact config file that I posted above (you'll see where things need to change for your version).

For each SRCDS server you want to run, follow the below steps:
  1. Open a command window and cd to %SRVSTART%
  2. Enter the following command: srvstart install srcds_srv_1 -c %SRVSTART%\config.txt
  3. SrvStart will hopefully report back that the service installed successsfully. If it didn't, make sure you are not trying to install a service that already exists.
You can now start the services to make sure they are working. Please check your command line options with a non service SRCDS to make sure it works BEFORE you create a service.

You have completed phase one and your server is now protected from crashes.

The next phase will allow you to have it automatically restarted if the server stops responding to rcon commands (a good indication that it hung and didn't close).

Phase 2:

This phase involves running a special program on the SAME machine that you are hosting your servers.

With the help of a C# RCON library from http://aiusepsi.co.uk/, I have created a C# .NET application that when run, will check all the servers in it's configuration file to see if they are up and running (by sending a rcon status command), and if a server isn't, it restarts the service.

I haven't tested it completely yet, but if you want an early copy, you can get one from https://svn.projects.okbehappy.net:444/rconserverchecker/trunk (login / pw = anonsvn / anonsvn). You will need VS08 to build the source code.

I recommend that after configuring it, you set it up to run as a scheduled task every few minutes.

Once it's fully tested, I will post binaries and a full step by step guide.
Reply
#2
*** Bump

Added phase 2 details (hung server protection).
Reply
#3
What (if any) benefit is there in running srcds as a service as opposed to the console version?
Reply
#4
Does anybody know where i could get this rcon server checker? That is if it still exists somewhere.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)