X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2Fcluster.pl;h=cc96ac59b0bf065e2bff69cdd9aa5ba0db5825fa;hb=770092d94f96b6d22a38fb33e0056b4779a8a1ab;hp=9c47042b396ac0e13d12a6f3d02b82a7e093bd18;hpb=4b7dbe2c98c3694692b28584f096ae0c479a3174;p=spider.git diff --git a/perl/cluster.pl b/perl/cluster.pl index 9c47042b..cc96ac59 100755 --- a/perl/cluster.pl +++ b/perl/cluster.pl @@ -18,8 +18,6 @@ package main; use vars qw($data $system $cmd $localcmd $userfn $clusteraddr $clusterport $yes $no $user_interval $lang); $lang = 'en'; # default language -$clusteraddr = '127.0.0.1'; # cluster tcp host address - used for things like console.pl -$clusterport = 27754; # cluster tcp port $yes = 'Yes'; # visual representation of yes $no = 'No'; # ditto for no $user_interval = 11*60; # the interval between unsolicited prompts if no traffic @@ -123,6 +121,7 @@ use DXXml; use DXSql; use IsoTime; use BPQMsg; +use DXCIDR; use Data::Dumper; use IO::File; @@ -141,6 +140,9 @@ use vars qw(@inqueue $systime $starttime $lockfn @outstanding_connects $can_encode $maxconnect_user $maxconnect_node ); + +$clusteraddr ||= '127.0.0.1'; # cluster tcp host address - used for things like console.pl +$clusterport ||= 27754; # cluster tcp port @inqueue = (); # the main input queue, an array of hashes $systime = 0; # the time now (in seconds) $starttime = 0; # the starting time of the cluster @@ -270,10 +272,16 @@ sub login } # cease running this program, close down all the connections nicely +our $is_ceasing; + sub cease { my $dxchan; + cluck("ceasing") if $is_ceasing; + + return if $is_ceasing++; + unless ($is_win) { $SIG{'TERM'} = 'IGNORE'; $SIG{'INT'} = 'IGNORE'; @@ -292,13 +300,14 @@ sub cease foreach $dxchan (DXChannel::get_all_nodes) { $dxchan->disconnect(2) unless $dxchan == $main::me; } - Msg->event_loop(100, 0.01); # disconnect users foreach $dxchan (DXChannel::get_all_users) { $dxchan->disconnect; } + Msg->event_loop(100, 0.01); + # disconnect AGW AGWMsg::finish(); BPQMsg::finish(); @@ -308,8 +317,9 @@ sub cease # end everything else Msg->event_loop(100, 0.01); - DXUser::finish(); DXDupe::finish(); + QSL::finish(); + DXUser::finish(); # close all databases DXDb::closeall; @@ -319,12 +329,12 @@ sub cease $l->close_server; } - LogDbg('cluster', "DXSpider V$version, build $subversion.$build (git: $gitbranch/$gitversion) ended"); + $dbh->finish if $dbh; + + LogDbg("DXSpider v$version build $build (git: $gitbranch/$gitversion) using perl $^V on $^O ended"); dbgclose(); Logclose(); - $dbh->finish if $dbh; - unlink $lockfn; # $SIG{__WARN__} = $SIG{__DIE__} = sub {my $a = shift; cluck($a); }; exit(0); @@ -367,6 +377,8 @@ sub AGWrestart # ############################################################# +chdir $root; + $starttime = $systime = time; $systime_days = int ($systime / 86400); $systime_daystart = $systime_days * 86400; @@ -399,34 +411,35 @@ if (DXSql::init($dsn)) { import Encode; $can_encode = 1; } - eval { require Git; }; - unless ($@) { - import Git; + + $gitbranch = 'none'; + $gitversion = 'none'; + + # determine the real Git build number and branch + my $desc; + eval {$desc = `git --git-dir=$root/.git describe --long`}; + if (!$@ && $desc) { + my ($v, $s, $b, $g) = $desc =~ /^([\d\.]+)(?:\.(\d+))?-(\d+)-g([0-9a-f]+)/; + $version = $v; + $subversion = $s || 0; + $build = $b || 0; + $gitversion = "$g\[r]"; + } + if (!$@) { + my @branch; - # determine the real version number - $gitbranch = 'none'; - $gitversion = 'none'; - my $repo = Git->repository(Directory => "$root/.git"); - if ($repo) { - my $desc = $repo->command_oneline(['describe'], STDERR => 0); - if ($desc) { - my ($v, $s, $b, $g) = $desc =~ /^([\d.]+)(?:\.(\d+))?-(\d+)-g([0-9a-f]+)/; - $version = $v; - $subversion = $s || 0; - $build = $b || 0; - $gitversion = "$g\[r]"; + eval {@branch = `git --git-dir=$root/.git branch`}; + unless ($@) { + for (@branch) { + my ($star, $b) = split /\s+/; + if ($star eq '*') { + $gitbranch = $b; + last; + } } } - my @branch = $repo->command([qw{branch}], STDERR=>0); - for (@branch) { - my ($star, $b) = split /\s+/; - if ($star eq '*') { - $gitbranch = $b; - last; - } - } - } + $SIG{__DIE__} = $w; } @@ -436,8 +449,9 @@ DXXml::init(); # banner my ($year) = (gmtime)[5]; $year += 1900; -LogDbg('cluster', "DXSpider V$version, build $subversion.$build (git: $gitbranch/$gitversion) started"); -dbg("Copyright (c) 1998-$year Dirk Koopman G1TLH"); +LogDbg('cluster', "DXSpider v$version build $build (git: $gitbranch/$gitversion) using perl $^V on $^O started"); +LogDbg('cluster', "Copyright (c) 1998-$year Dirk Koopman G1TLH"); +LogDbg('cluster', "Capabilities: ve7cc rbn"); # load Prefixes dbg("loading prefixes ..."); @@ -473,6 +487,9 @@ DXUser->init($userfn, 1); } } +# get any bad IPs +DXCIDR::init(); + # start listening for incoming messages/connects dbg("starting listeners ..."); my $conn = IntMsg->new_server($clusteraddr, $clusterport, \&login); @@ -638,7 +655,12 @@ for (;;) { last if --$decease <= 0; } } -cease(0); +cease(0) unless $is_ceasing; exit(0); +# +sub END +{ + cease(0) unless $is_ceasing; +}