adding interlocks to protect against multiple runs -- only protects one machine!
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 4 Sep 2006 08:46:50 +0000 (08:46 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 4 Sep 2006 08:46:50 +0000 (08:46 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5916 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/support-scripts/fine_generator.pl
Open-ILS/src/support-scripts/hold_targeter.pl

index 5842944..a149187 100755 (executable)
@@ -11,6 +11,26 @@ use JSON;
 use OpenSRF::System;
 
 my $config = shift || die "bootstrap config required\n";
+my $lockfile = shift || "/tmp/generate_fines-LOCK";
+
+if (-e $lockfile) {
+        open(F,$lockfile);
+        my $pid = <F>;
+        close F;
+
+        open(F,'/bin/ps axo pid|');
+        while ( my $p = <F>) {
+                chomp($p);
+                if ($p =~ s/\s*(\d+)$/$1/o && $p == $pid) {
+                        die "I seem to be running already at pid $pid.  If not, try again\n";
+                }
+        }
+        close F;
+}
+
+open(F, ">$lockfile");
+print F $$;
+close F;
 
 OpenSRF::System->bootstrap_client( config_file => $config );
 
@@ -20,3 +40,4 @@ my $r = OpenSRF::AppSession
 
 while (!$r->complete) { $r->recv };
 
+unlink $lockfile;
index c828dc9..406c1be 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/perl
 # ---------------------------------------------------------------------
-# Generic databse object dumper.
-# ./object_dumper.pl <bootstrap_config> <type>, <type>, ...
-# ./object_dumper.pl /openils/conf/bootstrap.conf permission.grp_tree
+# Usage:
+#   hold_targeter.pl <config_file> <lock_file>
 # ---------------------------------------------------------------------
 
 use strict; 
@@ -11,6 +10,26 @@ use JSON;
 use OpenSRF::System;
 
 my $config = shift || die "bootstrap config required\n";
+my $lockfile = shift || "/tmp/hold_targeter-LOCK";
+
+if (-e $lockfile) {
+       open(F,$lockfile);
+       my $pid = <F>;
+       close F;
+
+       open(F,'/bin/ps axo pid|');
+       while ( my $p = <F>) {
+               chomp($p);
+               if ($p =~ s/\s*(\d+)$/$1/o && $p == $pid) {
+                       die "I seem to be running already at pid $pid.  If not, try again\n";
+               }
+       }
+       close F;
+}
+
+open(F, ">$lockfile");
+print F $$;
+close F;
 
 OpenSRF::System->bootstrap_client( config_file => $config );
 
@@ -20,3 +39,5 @@ my $r = OpenSRF::AppSession
 
 while (!$r->complete) { $r->recv };
 
+unlink $lockfile;
+