SRCDS Steam group

DIY Web-based Server Admin!
Hi there. I've rented a dedicated server and am hosting some TF2 servers on it.

The server is running Debian Linux and my fellow admins are getting annoyed when the server goes down they can't use linux to get the server up again.

I've been working on a PHP script that shows the status of each server. And the option to start/stop and update the server.

I've got the status bit done... thanks to a simple bit of PHP I found...
PHP Code:
$ip "";
$port "27015";
$name "Teamplay TF2 Public ";
if (! 
$sock = @fsockopen($ip$port$num$error5))
' <B><FONT COLOR=red>Offline</b></FONT><br>';
' <B><FONT COLOR=lime>Online</b></FONT><br>';
This simply queries the server and if it connects... prints out the server name followed by either online or offline

I'm using screen to manage my seperate servers... I've got it so it prints out the list of screens running which can be quite useful.
I had to use sudo to run this script. I had to add my apache user (www-data) and nobody to my Sudoers file by adding these 2 lines:
www-data ALL=(root) NOPASSWD: ALL
nobody ALL=(root) NOPASSWD: ALL

The screen list code is simply
PHP Code:
    system('sudo screen -ls'); 

Now for starting and stopping the servers... I'm actually running 3 TF2 servers off the same directory. (A bit annoying because of admin mods and such conflicting). But the same concept applies.
I have a start and stop script in shell which reside in /etc/steam/orangebox. Here is an example:
echo 'Starting TF2 Server #1...'
/usr/bin/screen -A -m -d -S Server1 /etc/steam/orangebox/srcds_run -game tf +ip -port 27015 +maxplayers 24 +map cp_dustbowl +exec server1.cfg -a autoupdate
echo 'Server Started!'
echo "Stopping Server#1..."
/usr/bin/screen -dr Server1 -X quit
echo "Server Stopped!"

I tried running:
PHP Code:
    $output shell_exec('sudo /etc/steam/orangebox/'); 
But it seems if you aren't in the directory when you run it... it wont start. So I put a scipt in my website root directory (/var/www/site/htdocs/
cd /etc/steam/orangebox/

I then ran this script from PHP... which changes to the right directory... then executes the start script for the tf2 server. This worked!! So you can then implement a system to start and stop the server.

You could first check the status of each server... if the server is offline... you can have a link to start it. If the server's online, have a link to stop it. Obviously you'd need access restrictions to the webpage. Here's an example of what I used to test it:
PHP Code:
if ($_GET)
// e.g.
if ($_GET['mode']=="start") {
$output shell_exec('sudo /var/www/site/htdocs/');
    if (
$_GET['mode']=="stop") {
$output shell_exec('sudo /etc/steam/orangebox/');

This is probably not the cleanest, best, or most secure way of doing this. But it's the only way I can find of doing it. I don't advise you copy what I've done as allowing root access to your www-data user isn't recommended.

It's simple, dirty... but it works. I just thought it might help someone so there it is!

Edit: I haven't mentioned updating... but it would simply be the case of making a bash script to run the hlds_update with the correct game and directory specified. Then running that as root through PHP as done in the other examples.

Its nice and basic, pretty good for a first go.

my whole system is based on a gaming panel. when starting and stopping servers i have a 1000 (roughly) line php script which accesses a table which is used to store the run settings for a particular game (counter strike source, team fortress 2, counter strike 1.6)

Then the function gets the entry for a server id out of the servers table.

Any missing information is aquired from the users table.

and then it formats the string to run the server and runs it or stops it.

If you want to expand on yours, id be more than happy to help with what ive got?
Oooo sounds interesting. Do you use sudo to run the commands?

I'm now using the GameQ library to fetch server status. This gives me the number of players, max players, map and wether it's online or not.

I've just made start and stop bash scripts for every server and run them. I'd love to have a look at what you've made. I was thinking about storing my servers in the database. What advantages does it give you? Can you edit configs or anything?
When I can use my arm in a week or so (There is a cast on it) I am going to write a multi-game MySQL/PHP powered game server management monitoring system for Windows and linux. I am pretty decent with PHP and it should take my a week or so. I like the simple script though..... simple = better always.

Forum Jump:

Users browsing this thread: 1 Guest(s)