Automatic gameserver reboot

If something doesn't fit in any other forum then post it here.
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
msknight
Advanced User
Advanced User
Posts: 308
Joined: Wed May 10, 2006 11:40 am
Location: U.K.

Automatic gameserver reboot

Post by msknight »

This is part of the dropcalc, but I thought that it needed its own thread because of possible issues ... it could cause some discussion.

For those that are running the V4 dropcalc already, you will know the $gameserver variables.

This has currently been tested on Linux, but I'm not sure if it will work in Windows yet. In theory, comment out the linux variables and uncomment the windows variables at the top of the php script and you are away.

On every run, it will check the gameservers listed, use the port numbers to try and determine whether the gameserver is up or down, and try to restart it if it is down.

The initial script is set to safe mode, so it will simply tell you what it would try and do ... until you chance the safe mode variable from 1 to 0. Linux users would need to run it regularly onder the crontab of the user they would normally start the gameserver under.

If you want to include the logon server in this, you can ... better to make it the first entry in the gameserver array.

Code: Select all

<?php 
error_reporting(E_ERROR | E_WARNING | E_PARSE);

/*
Michelle Knight's Drop Calc - Version 4
Author - Michelle Knight
Copyright 2006/2007
Contact - dropcalc@msknight.com

GNU General Licence
Use and distribute freely, but leave headers intact and make no charge.
Code distributed without warantee or liability as to merchantability as
no charge is made for its use.  Use is at users risk.
*/


// --------------------------------------------------------
// -----              Common Code Block               -----
// --------------------------------------------------------

//Gamserverdbs - copied straight from the config.php file.
$gameservers = ARRAY(
ARRAY("Title", "db_location", "db_database", "db_username", "db_password", defaultskin, "server files location", gameserver_port, "knight_db", "gameserver_telnet_ip", "gameserver_telnet_port", "gameserver_Telnet_password", gameserver_timeout)
);

$safe_mode = 1;

$start_string = "startGameServer.sh";		// For Linux
$start_prefix = "./";
$start_suffix = "  > /dev/null";
// $start_string = "startGameServer.bat";		// For Windows
// $start_prefix = "start /b ";
// $start_suffix = "";

function checkport($ip, $port) 
{
        if ($check = @fsockopen($ip, $port, $errno, $errstr, 1.0)) 
		{
                fclose($check);
                return 1;
        }
        return 0;
}


$g_array_count = count($gameservers);
$i = 0;
while ($i < $g_array_count)
{
	$g_name = $gameservers[$i][0];
	$g_ip = $gameservers[$i][1];
	$g_port = $gameservers[$i][7];
	$g_location = $gameservers[$i][6];
	if (!checkport($g_ip, $g_port))
	{	
		sleep(30);		// If gameserver is down wait 30 seconds and try again in case it is restarting itself.
		if (!checkport($g_ip, $g_port))
		{
			chdir($g_location);
			$shell_cmd = $start_prefix . $start_string . $start_suffix;
			if ($safe_mode < 1)
			{	
			   exec($shell_cmd);	
				echo "Issued $shell_cmd\n";
			}
			else
			{	echo "Would have issued for $g_name - $shell_cmd\n";	}
		}
	}

	$i++;
}

?>
My friend is a paranoid schizophrenic ... she'll take over the world, as long as nobody minds.
Post Reply