dswp.de
http://www.dswp.de/old/

automatic server restart
http://www.dswp.de/old/forum-gameserver-support/automatic-server-restart-t227.html
Page 1 of 1

Author:  wurst [ 12.27.08 ]
Post subject:  automatic server restart

oki guys, heres next try for restarting the gameserver in the case it dont answer properly.
it is (thx xtj7) a little php script that use rcon protocol for querying the gameserver status (like hlsw etc)
if the answer dont contain "statusResponse", the restart batch will kill the server via taskkill and start it again.

thats the checking script
Code:
<?php
$fp = fsockopen( 'udp://127.0.0.1', 22222, $errno, $error, 1 );
fwrite( $fp, "xFFxFFxFFxFFgetstatusx00" );

if( $fp &amp;&amp; strpos( fgets( $fp, 2048 ), "statusResponse" ) ) {
        echo( 'Server alive' );
} else {
        echo( 'Server died' );
        system( "C:/gameservers/UrbanTerror/ForceRestart.bat &amp;&amp; exit", $output );
        echo( 'Attempting restart...' );
}
?>


...and thats the C:/gameservers/UrbanTerror/ForceRestart.bat
Code:
taskkill /F /IM ioUrTded.exe
taskkill /F /IM python.exe
C:gameserversUrbanTerror22222.bat
sendemail -f gameserver@dswp.de -s xxx.xxx.xxx.xxx:225 -t lol@huhu -t spam@me.com -u huhu -m omg i did it again.


ah 2 notes:
-allways be sure to remember the save mode before use exec(), passthru() or system()
-sendemail.exe command line mail client can be found free at http://www.caspian.dotconf.net/menu/Software/SendEmail/
-be patient for the case our little "sylvesterknaller" has a littel "new-years-eve-backfire-issues"

gg :D

Author:  wurst [ 12.31.08 ]
Post subject:  Re: automatic server restart

oki heres new version of the thing. xtj7 built some test repeating in since some times rcon dont answer.

the script test several times before its going to restart serwer :)


Code:
<?php
$check_attempts = 5;
$check_ip = '192.168.9.1';
$check_port = 22222;
$check_timeout = 1;
$check_wait = 1;
$check_call = "START C:/gameservers/UrbanTerror/ForceRestart.bat &amp;&amp; exit";

// Code
$failed = true;
$attempts = $check_attempts;
while( $attempts > 0 ) {
        if( checkUrTServer( $check_ip, $check_port, $check_timeout ) ) {
                $attempts = 0;
                $failed = false;
        } else {
                sleep( $check_wait );
                $attempts --;
        }
}

// Actions to perform on success / fail
if( $failed == true ) {
        echo( 'Server died...' );
        system( $check_call, $output );
} else {
        echo( 'Server alive' );
}

// Functions
function checkUrTServer( $ip, $port = 22222, $timeout = 1 ) {
        $fp = fsockopen( 'udp://' . $ip, $port, $errno, $error, $timeout );  
        fwrite( $fp, "xFFxFFxFFxFFgetstatusx00" );
        if( $fp &amp;&amp; strpos( fgets( $fp, 2048 ), "statusResponse" ) ) {
                return( true );
        } else {
                return( false );
        }
}
?>

Author:  XTJ7 [ 01.01.09 ]
Post subject:  Re: automatic server restart

Aww, if I had known you wanted to publish it, I had made the code look pretty and not some ugly scribbling like that... :D Well, too late. It's only a simple and dirty solution for a problem that isn't supposed to exist in the first place.
So guys, if the server doesn't respond, visit the forum and it's supposed to restart.

Author:  wurst [ 01.03.09 ]
Post subject:  Re: automatic server restart

its a problem that dont exist anylonger thx supi code :)

Author:  wurst [ 01.10.09 ]
Post subject:  Re: automatic server restart

ah btw, for our "windows users"

:D :lol: :? :) ;) :( :shock:

if u have the same prob like me:
(the batch stops when starting the gameserver, it will just continue when the urt console window closes)

use hstart with /NOCONSOLE to start the iourtded.exe
very nice progi, it keeps the promise that bill gave with the "start" command

heres site:
http://www.ntwind.com/software/utilities/hstart.html

heres its capabilities:

Attachment:
hstart_help21.png
hstart_help21.png [ 31.69 KiB | Viewed 3391 times ]


it means that the gameserver will be restarted again and again and again, no matter how long im in holiday.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/