Reporter: Allow "graceful" shutdowns user/tsbere/kryptonite
authorThomas Berezansky <tsbere@mvlc.org>
Wed, 16 May 2012 18:46:36 +0000 (14:46 -0400)
committerThomas Berezansky <tsbere@mvlc.org>
Wed, 16 May 2012 18:46:36 +0000 (14:46 -0400)
Allow touching of a "kill" file to cause the reporter to stop itself.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Open-ILS/src/reporter/clark-kent.pl

index 29b067d..9898823 100755 (executable)
@@ -29,7 +29,7 @@ use Email::Send;
 use open ':utf8';
 
 
-my ($count, $config, $sleep_interval, $lockfile, $daemon) = (1, 'SYSCONFDIR/opensrf_core.xml', 10, '/tmp/reporter-LOCK');
+my ($count, $config, $sleep_interval, $lockfile, $killfile, $daemon) = (1, 'SYSCONFDIR/opensrf_core.xml', 10, '/tmp/reporter-LOCK', '/tmp/reporter-KILL');
 
 GetOptions(
        "daemon"        => \$daemon,
@@ -37,12 +37,17 @@ GetOptions(
        "concurrency=i" => \$count,
        "bootstrap|boostrap=s"  => \$config,
        "lockfile=s"    => \$lockfile,
+       "killfile=s"    => \$killfile
 );
 
 if (-e $lockfile) {
        die "I seem to be running already. If not, remove $lockfile and try again\n";
 }
 
+if (-e $killfile) {
+       die "I am being told to stop running before starting. Please remove $killfile and try again\n";
+}
+
 OpenSRF::System->bootstrap_client( config_file => $config );
 
 my (%data_db, %state_db);
@@ -120,6 +125,17 @@ SELECT     count(*)
   WHERE        start_time IS NOT NULL AND complete_time IS NULL;
 SQL
 
+if (-e $killfile) {
+       if ($running == 0) {
+               print "Applying Kryptonite.\n";
+               unlink($lockfile);
+               unlink($killfile);
+               exit 0;
+       }
+       # This should stop us from running any more.
+       $count = 0;
+}
+
 if ($count <= $running) {
        if ($daemon) {
                $dbh->disconnect;