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...
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:
The screen list code is simply
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
stop.sh
I tried running:
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)
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:
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
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, $error, 5))
echo ' <B><FONT COLOR=red>Offline</b></FONT><br>';
else{
echo ' <B><FONT COLOR=lime>Online</b></FONT><br>';
fclose($sock);
}
echo '</pre>';
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!'
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');
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