Jump to content

Home

Linux Server: Automatic Restart w/o program crash?


The Hunter

Recommended Posts

Hi. I've got my Linux server up and running quite nicely (check it out at 64.246.16.4:27966), but it crashes every few days (although without any seeming regularity). I've got my startup script set up to check if the program crashes and restart it if it does, but sometimes the server will crash but the program will not, and therefore the script doesn't restart it. I was wondering if there were anyway to restart the server automatically in this case.

 

Any ideas?

 

I'm running 1.03 on Redhat 7.1.

 

Thanks for any help you can offer.

Link to comment
Share on other sites

This may exactly what your looking for. your gonna have to change some of the varibles but it should work with jedi.

#!/usr/bin/perl -w
#
# assign the varibles for your setup here and run it from cron
#
use Socket;
$proto = getprotobyname('udp');
$server = sockaddr_in ($game_server_port, inet_aton($game_server_ip));
open (STDLOG, ">>$quake_check_log") || die "can't open $quake_check_log: $!";
print STDLOG `date`;
socket (QUAKE, PF_INET, SOCK_DGRAM, $proto) || die "problem opening socket: $!";
connect (QUAKE, $server) || die "problem connecting to server: $!";
$data = "\xff\xff\xff\xffgetstatus\x0a\x0b\x0c\x0d";
sleep(1);
send (QUAKE, $data, 0);
print STDLOG "Doing a Quick Status on Server at IP $game_server_ip port $game_server_port\n\n";
eval {
$SIG{ALRM} = sub { die };
alarm 3; # this should be plenty of time
$getstatus = recv(QUAKE, $GETSTATUS, 4096, 0) || die "There was a problem in recv(): $!";
alarm 0;
};
close (QUAKE);
if(!$getstatus)
{
print STDLOG "Failed to get Status of Server, retrying\n\n";
socket (QUAKE, PF_INET, SOCK_DGRAM, $proto) || die "problem opening socket: $!";
connect (QUAKE, $server) || die "problem connecting to server: $!";
sleep(1);
$data = "\xff\xff\xff\xffgetstatus\x0a\x0b\x0c\x0d";
send (QUAKE, $data, 0);
print STDLOG "Doing another Quick Status on Server at IP $game_server_ip port $game_server_port\n";
eval {
$SIG{ALRM} = sub { die };
alarm 3; # this should be plenty of time
$getstatus_retry = recv(QUAKE, $GETSTATUS, 4096, 0) || die "There was a problem in recv(): $!";
alarm 0;
};
close (QUAKE);
if(!$getstatus_retry)
{
print STDLOG "Server must be DOWN SECOND TRY FAILED, restarting server.\n";
system("killall $process_name");
system("$restart_script");
close(STDLOG);
exit;
}else{
@lines = split(/^/, $GETSTATUS); # only one packet for GetStatus, so we just split it on lines
$count = 0;
foreach $lines (@lines)
{
$count++;
if($count == 1)
{ # $challenge = $lines;
}elsif($count == 2)
{ # $serverinfo = $lines;
}else{ $player_count++;}
}
}
print STDLOG "$server_name server has $player_count Players \n\n\n";
}else{
@lines = split(/^/, $GETSTATUS); # only one packet for GetStatus, so we just split it on lines
$count = 0;
foreach $lines (@lines)
{
$count++;
if($count == 1)
{ # $challenge = $lines;
}elsif($count == 2)
{ # $serverinfo = $lines;
}else{
$player_count++;
}
}
print STDLOG "$server_name server has $player_count Players \n\n\n";
}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...