X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2Fcluster.pl;h=a3e915a614ebb45e41686a7ef7162f1d4aff6738;hb=06a6935d583a684869129350fed170d467ad8acc;hp=059a24a929997f5ca5c8cb150490803d823b605d;hpb=e1d5c2a325cb6b8674eab55c23f12445aae01f52;p=spider.git diff --git a/perl/cluster.pl b/perl/cluster.pl index 059a24a9..a3e915a6 100755 --- a/perl/cluster.pl +++ b/perl/cluster.pl @@ -34,11 +34,14 @@ BEGIN { # try to create and lock a lockfile (this isn't atomic but # should do for now $lockfn = "$root/local/cluster.lck"; # lock file name - if (-e $lockfn) { + if (-w $lockfn) { open(CLLOCK, "$lockfn") or die "Can't open Lockfile ($lockfn) $!"; my $pid = ; - chomp $pid; - die "Lockfile ($lockfn) and process $pid exist, another cluster running?" if kill 0, $pid; + if ($pid) { + chomp $pid; + die "Lockfile ($lockfn) and process $pid exist, another cluster running?" if kill 0, $pid; + } + unlink $lockfn; close CLLOCK; } open(CLLOCK, ">$lockfn") or die "Can't open Lockfile ($lockfn) $!"; @@ -49,6 +52,8 @@ BEGIN { $systime = time; } +use Mojo::IOLoop; + use DXVars; use Msg; use IntMsg; @@ -118,7 +123,7 @@ 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 $allowdxby $dbh $dsn $dbuser $dbpass $do_xml $systime_days $systime_daystart - $can_encode $maxconnect_user $maxconnect_node + $can_encode $maxconnect_user $maxconnect_node $idle_interval ); @inqueue = (); # the main input queue, an array of hashes @@ -133,6 +138,7 @@ $maxconnect_user = 3; # the maximum no of concurrent connections a user can ha $maxconnect_node = 0; # Ditto but for nodes. In either case if a new incoming connection # takes the no of references in the routing table above these numbers # then the connection is refused. This only affects INCOMING connections. +$idle_interval = 0.100; # the wait between invocations of the main idle loop processing. # send a message to call on conn and disconnect sub already_conn @@ -270,7 +276,6 @@ 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) { @@ -285,7 +290,6 @@ sub cease UDPMsg::finish(); # end everything else - Msg->event_loop(100, 0.01); DXUser::finish(); DXDupe::finish(); @@ -297,7 +301,8 @@ sub cease $l->close_server; } - LogDbg('cluster', "DXSpider V$version, build $subversion.$build ended"); + LogDbg('cluster', "DXSpider V$version, build $subversion.$build (git: $gitversion) ended"); + dbg("bye bye everyone - bye bye"); dbgclose(); Logclose(); @@ -339,6 +344,60 @@ sub AGWrestart AGWMsg::init(\&new_channel); } +sub idle_loop +{ + my $timenow = time; + + DXChannel::process(); + + # $DB::trace = 0; + + # do timed stuff, ongoing processing happens one a second + if ($timenow != $systime) { + reap() if $zombies; + $systime = $timenow; + my $days = int ($systime / 86400); + if ($systime_days != $days) { + $systime_days = $days; + $systime_daystart = $days * 86400; + } + IsoTime::update($systime); + DXCron::process(); # do cron jobs + DXCommandmode::process(); # process ongoing command mode stuff + DXXml::process(); + DXProt::process(); # process ongoing ak1a pcxx stuff + DXConnect::process(); + DXMsg::process(); + DXDb::process(); + DXUser::process(); + DXDupe::process(); + $systime_days = $days; + $systime_daystart = $days * 86400; + } + IsoTime::update($systime); + DXCron::process(); # do cron jobs + DXCommandmode::process(); # process ongoing command mode stuff + DXXml::process(); + DXProt::process(); # process ongoing ak1a pcxx stuff + DXConnect::process(); + DXMsg::process(); + DXDb::process(); + DXUser::process(); + DXDupe::process(); + AGWMsg::process(); + BPQMsg::process(); + + Timer::handler(); + + if (defined &Local::process) { + eval { + Local::process(); # do any localised processing + }; + dbg("Local::process error $@") if $@; + } +} + + ############################################################# # # The start of the main line of code @@ -386,7 +445,7 @@ DXXml::init(); # banner my ($year) = (gmtime)[5]; $year += 1900; -LogDbg('cluster', "DXSpider V$version, build $subversion.$build started"); +LogDbg('cluster', "DXSpider V$version, build $subversion.$build (git: $gitversion) started"); dbg("Copyright (c) 1998-$year Dirk Koopman G1TLH"); # load Prefixes @@ -443,7 +502,7 @@ dbg("load badwords: " . (BadWords::load or "Ok")); # prime some signals unless ($DB::VERSION) { - $SIG{INT} = $SIG{TERM} = sub { $decease = 1 }; + $SIG{INT} = $SIG{TERM} = sub { Mojo::IOLoop->stop; }; } unless ($is_win) { @@ -532,49 +591,8 @@ $script->run($main::me) if $script; #open(DB::OUT, "|tee /tmp/aa"); -for (;;) { -# $DB::trace = 1; - - Msg->event_loop(10, 0.010); - my $timenow = time; - - DXChannel::process(); - -# $DB::trace = 0; +Mojo::IOLoop->start; - # do timed stuff, ongoing processing happens one a second - if ($timenow != $systime) { - reap() if $zombies; - $systime = $timenow; - my $days = int ($systime / 86400); - if ($systime_days != $days) { - $systime_days = $days; - $systime_daystart = $days * 86400; - } - IsoTime::update($systime); - DXCron::process(); # do cron jobs - DXCommandmode::process(); # process ongoing command mode stuff - DXXml::process(); - DXProt::process(); # process ongoing ak1a pcxx stuff - DXConnect::process(); - DXMsg::process(); - DXDb::process(); - DXUser::process(); - DXDupe::process(); - AGWMsg::process(); - BPQMsg::process(); - - if (defined &Local::process) { - eval { - Local::process(); # do any localised processing - }; - dbg("Local::process error $@") if $@; - } - } - if ($decease) { - last if --$decease <= 0; - } -} cease(0); exit(0);