remove --long from git describe call
[spider.git] / perl / cluster.pl
index a33e6da5f1a8e76b2907cf8547791702a146cdd9..3b931a0fba1b8407ee37592d65cd16013e462b27 100755 (executable)
@@ -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 = <CLLOCK>;
-               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) $!";
@@ -367,7 +370,7 @@ if (DXSql::init($dsn)) {
        $dbh = $dbh->connect($dsn, $dbuser, $dbpass) if $dbh;
 }
 
-# try to load Encode
+# try to load Encode and Git
 {
        local $^W = 0;
        my $w = $SIG{__DIE__};
@@ -377,6 +380,23 @@ if (DXSql::init($dsn)) {
                import Encode;
                $can_encode = 1;
        }
+       eval { require Git; };
+       unless ($@) {
+               import Git;
+               
+               # 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]";
+                       }
+               }
+       }
        $SIG{__DIE__} = $w;
 }
 
@@ -564,6 +584,8 @@ for (;;) {
                AGWMsg::process();
                BPQMsg::process();
 
+               DXLog::flushall();
+               
                if (defined &Local::process) {
                        eval {
                                Local::process();       # do any localised processing