History | Edit | Delete | raw

Wiki → Public | Page index

 1 #!/usr/bin/perl
 2 
 3 # Florian Unglaub <flo@btw23.de>
 4 
 5 use strict;
 6 use warnings;
 7 
 8 use POSIX ":sys_wait_h";
 9 
10 $SIG{CHLD} = \&handle_child;
11 $SIG{KILL} = \&handle_kill;
12 
13 our $chld_received = 1; 
14 # initialize with 1 so we don't do a infinite
15 # loop without ever forking the first child
16 our $childpid;
17 
18 # Random Map at startup
19 
20 my %maplist = (
21         0 => 'RO-Kaukasus.rom',
22         1 => 'RO-Krasnyioktyabr.rom',
23         2 => 'RO-Stalingradkessel.rom',
24         3 => 'RO-Odessa.rom',
25         4 => 'RO-Ogledow.rom',
26         5 => 'RO-Basovka.rom',
27         );
28 
29 my $pidfile="~/pids/public.pid";
30 
31 while ()
32         {
33         if ( $chld_received )
34                 {
35                 unless ( $childpid = fork() )
36                         {
37                         chdir("$ENV{'HOME'}/system");
38                         my $map=$maplist{int(rand(6))}; 
39                         my $startup_options=
40                                 "$map -nohomedir -log=~/logs/public.log 
41                                  -ini=redorchestra_public.ini 
42                                  -XAdminConfigIni=XAdmin_public.ini";
43                         exec("./ucc-bin server $startup_options") or die $!;
44                         }
45                 $chld_received = 0;
46                 }
47                 system("echo $childpid > $pidfile");
48                 sleep(); 
49         }
50 
51 sub handle_child
52 {
53         waitpid($childpid, WNOHANG);
54         $chld_received = 1;
55         unlink $pidfile or warn $!;
56 }
57 
58 sub handle_kill
59 {
60         unlink $pidfile or warn $!;
61         return;
62 }
63 

Last Edit: July 06, 2009 08:57 by ueber