SRCDS Steam group


DIY Web-based Server Admin!
#1
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 "12.35.67.43";
$port "27015";
$name "Teamplay TF2 Public ";
echo 
'<pre>'.$name;
if (! 
$sock = @fsockopen($ip$port$num$error5))
  echo 
' <B><FONT COLOR=red>Offline</b></FONT><br>';
else{
  echo 
' <B><FONT COLOR=lime>Online</b></FONT><br>';
fclose($sock);
}
echo 
'</pre>'
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:
Code:
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:
start.sh
Code:
echo 'Starting TF2 Server #1...'
/usr/bin/screen -A -m -d -S Server1 /etc/steam/orangebox/srcds_run -game tf +ip 123.12.22.44 -port 27015 +maxplayers 24 +map cp_dustbowl +exec server1.cfg -a autoupdate
echo 'Server Started!'
stop.sh
Code:
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/start.sh'); 
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/start.sh)
Code:
cd /etc/steam/orangebox/
./start.sh

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. www.site.com/server.php?mode=start
    
if ($_GET['mode']=="start") {
    
$output shell_exec('sudo /var/www/site/htdocs/start.sh');
    }
    
    if (
$_GET['mode']=="stop") {
    
$output shell_exec('sudo /etc/steam/orangebox/stopmatch.sh');
    }


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.

Fyfey
Reply
#2
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?
Reply
#3
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?
Reply
#4
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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)