mega-merge of major parts of mojo
[spider.git] / perl / cluster.pl
index 3336d077482f0114d2558b8cc696dbbede4f612f..f1eade415bc263ae5778b03dec2fcf2e8c9ad4f8 100755 (executable)
 
 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
@@ -110,7 +126,6 @@ use Data::Dumper;
 use IO::File;
 use Fcntl ':flock';
 use POSIX ":sys_wait_h";
-use Version;
 
 use Local;
 
@@ -118,12 +133,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 +155,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
 {
@@ -300,7 +320,7 @@ sub cease
                $l->close_server;
        }
 
-       LogDbg('cluster', "DXSpider V$version, build $subversion.$build (git: $gitversion) ended");
+       LogDbg('cluster', "DXSpider v$version build $build (git: $gitbranch/$gitversion) using perl $^V on $^O ended");
        dbgclose();
        Logclose();
 
@@ -348,6 +368,8 @@ sub AGWrestart
 #
 #############################################################
 
+chdir $root;
+
 $starttime = $systime = time;
 $systime_days = int ($systime / 86400);
 $systime_daystart = $systime_days * 86400;
@@ -380,23 +402,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,7 +440,7 @@ DXXml::init();
 # banner
 my ($year) = (gmtime)[5];
 $year += 1900;
-LogDbg('cluster', "DXSpider V$version, build $subversion.$build (git: $gitversion) started");
+LogDbg('cluster', "DXSpider v$version build $build (git: $gitbranch/$gitversion) using perl $^V on $^O started");
 dbg("Copyright (c) 1998-$year Dirk Koopman G1TLH");
 
 # load Prefixes