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




