CVS User Account cvsuser
Tue Jan 25 23:13:55 PST 2005
Log Message:
-----------
slon_watchdog.pl.diff
- Added --config and --help options, as with other files
- Use a while loop instead of a recursive function for the watchdog process
- Allow node# to be given as just a number, as with other files

slon_start.pl.diff
- --help would fail if --config wasn't specified and slon.env wasn't in @INC
- Call slon_watchdog.pl using --config

-- 
Steve Simms

Modified Files:
--------------
    slony1-engine/tools/altperl:
        slon_watchdog.pl (r1.3 -> r1.4)
        slon_start.pl (r1.6 -> r1.7)

-------------- next part --------------
Index: slon_start.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slon_start.pl,v
retrieving revision 1.6
retrieving revision 1.7
diff -Ltools/altperl/slon_start.pl -Ltools/altperl/slon_start.pl -u -w -r1.6 -r1.7
--- tools/altperl/slon_start.pl
+++ tools/altperl/slon_start.pl
@@ -17,9 +17,6 @@
 	   "sleep=i"   => \$SLEEP_TIME,
 	   "help"      => \$SHOW_USAGE);
 
-require 'slon-tools.pm';
-require $SLON_ENV_FILE;
-
 my $USAGE =
 "Usage: slon_start.pl [--config file] [--watchdog|--nowatchdog]
        [--sleep seconds] node#
@@ -40,6 +37,9 @@
   die $USAGE;
 }
 
+require 'slon-tools.pm';
+require $SLON_ENV_FILE;
+
 $node = $ARGV[0];
 
 # Node can be passed either as "node1" or just "1"
@@ -67,6 +67,6 @@
   print "PID [$pid]\n";
   if ($START_WATCHDOG) {
     print "Start the watchdog process as well...\n";
-    system "perl slon_watchdog.pl $node $SLEEP_TIME &";
+    system "perl slon_watchdog.pl --config=$SLON_ENV_FILE $node $SLEEP_TIME &";
   }
 }
Index: slon_watchdog.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slon_watchdog.pl,v
retrieving revision 1.3
retrieving revision 1.4
diff -Ltools/altperl/slon_watchdog.pl -Ltools/altperl/slon_watchdog.pl -u -w -r1.3 -r1.4
--- tools/altperl/slon_watchdog.pl
+++ tools/altperl/slon_watchdog.pl
@@ -3,24 +3,43 @@
 # Author: Christopher Browne
 # Copyright 2004 Afilias Canada
 
+use Getopt::Long;
+
+# Defaults
+$SLON_ENV_FILE  = 'slon.env'; # Where to find the slon.env file
+$SHOW_USAGE     = 0;          # Show usage, then quit
+
+# Read command-line options
+GetOptions("config=s"  => \$SLON_ENV_FILE,
+	   "help"      => \$SHOW_USAGE);
+
+my $USAGE =
+"Usage: slon_watchdog.pl [--config file] node# sleep_seconds
+
+    --config file  Location of the slon.env file (default: Perl's \@INC)
+
+    sleep_seconds  Number of seconds for the watchdog process to sleep
+                   between checks
+
+";
+
+if ($SHOW_USAGE or scalar(@ARGV) != 2) {
+  die $USAGE;
+}
+
 require 'slon-tools.pm';
-require 'slon.env';
+require $SLON_ENV_FILE;
 
 $node =$ARGV[0];
 $sleep =$ARGV[1];
 
-if ( scalar(@ARGV) < 2 ) {
-  die "Usage: ./slon_watchdog node sleep-time\n";
-}
-
-if ($node =~/^node(\d+)$/) {
+if ($node =~/^(?:node)?(\d+)$/) {
   $nodenum = $1;
+} else {
+  die $USAGE;
 }
 
-slon_watchdog($node, $nodenum);
-
-sub slon_watchdog {
-  my ($node, $nodenum) = @_;
+while (1) {
   $pid = get_pid($node);
   if (!($pid)) {
     my ($dsn, $dbname) = ($DSN[$nodenum], $DBNAME[$nodenum]);
@@ -44,5 +63,4 @@
   }
   close(PSOUT);
   sleep $sleep;
-  slon_watchdog();
 }


More information about the Slony1-commit mailing list