X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2Fcluster.pl;h=cc96ac59b0bf065e2bff69cdd9aa5ba0db5825fa;hb=770092d94f96b6d22a38fb33e0056b4779a8a1ab;hp=3336d077482f0114d2558b8cc696dbbede4f612f;hpb=9b65e70322b24190bb5f677ccedcc000ab4625d2;p=spider.git diff --git a/perl/cluster.pl b/perl/cluster.pl index 3336d077..cc96ac59 100755 --- a/perl/cluster.pl +++ b/perl/cluster.pl @@ -12,6 +12,17 @@ require 5.004; +package main; + +# set default paths, these should be overwritten by DXVars.pm +use vars qw($data $system $cmd $localcmd $userfn $clusteraddr $clusterport $yes $no $user_interval $lang); + +$lang = 'en'; # default language +$yes = 'Yes'; # visual representation of yes +$no = 'No'; # ditto for no +$user_interval = 11*60; # the interval between unsolicited prompts if no traffic + + # make sure that modules are searched in the order local then perl BEGIN { umask 002; @@ -30,6 +41,11 @@ BEGIN { mkdir "$root/local_cmd", 0777 unless -d "$root/local_cmd"; + $data = "$root/data"; + $system = "$root/sys"; + $cmd = "$root/cmd"; + $localcmd = "$root/local_cmd"; + $userfn = "$data/users"; # try to create and lock a lockfile (this isn't atomic but # should do for now @@ -105,12 +121,12 @@ use DXXml; use DXSql; use IsoTime; use BPQMsg; +use DXCIDR; use Data::Dumper; use IO::File; use Fcntl ':flock'; use POSIX ":sys_wait_h"; -use Version; use Local; @@ -118,12 +134,15 @@ package main; use strict; use vars qw(@inqueue $systime $starttime $lockfn @outstanding_connects - $zombies $root @listeners $lang $myalias @debug $userfn $clusteraddr - $clusterport $mycall $decease $is_win $routeroot $me $reqreg $bumpexisting + $zombies $root @listeners $lang $myalias @debug $userfn + $mycall $decease $is_win $routeroot $me $reqreg $bumpexisting $allowdxby $dbh $dsn $dbuser $dbpass $do_xml $systime_days $systime_daystart $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 @@ -137,6 +156,8 @@ $maxconnect_node = 0; # Ditto but for nodes. In either case if a new incoming # takes the no of references in the routing table above these numbers # then the connection is refused. This only affects INCOMING connections. +use vars qw($version $subversion $build $gitversion $gitbranch); + # send a message to call on conn and disconnect sub already_conn { @@ -251,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'; @@ -273,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(); @@ -289,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; @@ -300,12 +329,12 @@ sub cease $l->close_server; } - LogDbg('cluster', "DXSpider V$version, build $subversion.$build (git: $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); @@ -348,6 +377,8 @@ sub AGWrestart # ############################################################# +chdir $root; + $starttime = $systime = time; $systime_days = int ($systime / 86400); $systime_daystart = $systime_days * 86400; @@ -380,23 +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 - 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; + } } } } + $SIG{__DIE__} = $w; } @@ -406,8 +449,9 @@ DXXml::init(); # banner my ($year) = (gmtime)[5]; $year += 1900; -LogDbg('cluster', "DXSpider V$version, build $subversion.$build (git: $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 ..."); @@ -443,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); @@ -608,7 +655,12 @@ for (;;) { last if --$decease <= 0; } } -cease(0); +cease(0) unless $is_ceasing; exit(0); +# +sub END +{ + cease(0) unless $is_ceasing; +}