CVS User Account cvsuser
Tue Feb 22 16:51:16 PST 2005
Log Message:
-----------
Removed the "set#" argument from failover.pl since it doesn't use it.

Added --config and --help options to nearly all of the remaining
scripts that didn't have them.

Combined restart_nodes.pl and restart_node.pl by adding an "--all"
switch to restart_node.pl and allowing it to accept multiple
nodes as arguments.

Added a "does file exist" check to slon_pushsql.pl.

Removed a few unused declarations and made some minor stylistic
changes.

Modified Files:
--------------
    slony1-engine/tools/altperl:
        drop_node.pl (r1.8 -> r1.9)
        failover.pl (r1.7 -> r1.8)
        move_set.pl (r1.7 -> r1.8)
        restart_node.pl (r1.6 -> r1.7)
        show_configuration.pl (r1.5 -> r1.6)
        unsubscribe_set.pl (r1.6 -> r1.7)
        slon_pushsql.pl (r1.8 -> r1.9)
        update_nodes.pl (r1.5 -> r1.6)

Removed Files:
-------------
    slony1-engine/tools/altperl:
        restart_nodes.pl

-------------- next part --------------
Index: drop_node.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/drop_node.pl,v
retrieving revision 1.8
retrieving revision 1.9
diff -Ltools/altperl/drop_node.pl -Ltools/altperl/drop_node.pl -u -w -r1.8 -r1.9
--- tools/altperl/drop_node.pl
+++ tools/altperl/drop_node.pl
@@ -3,28 +3,47 @@
 # Author: Christopher Browne
 # Copyright 2004 Afilias Canada
 
+use Getopt::Long;
+
+# Defaults
+$CONFIG_FILE = '@@SYSCONFDIR@@/slon_tools.conf';
+$SHOW_USAGE  = 0;
+
+# Read command-line options
+GetOptions("config=s" => \$CONFIG_FILE,
+	   "help"     => \$SHOW_USAGE);
+
+my $USAGE =
+"Usage: drop_node [--config file] node#
+
+    Drops a node.
+
+";
+
+if ($SHOW_USAGE) {
+  print $USAGE;
+  exit 0;
+}
+
 require '@@PGLIBDIR@@/slon-tools.pm';
-require '@@SYSCONFDIR@@/slon_tools.conf';
+require $CONFIG_FILE;
 
 my ($node) = @ARGV;
-if ($node =~ /^node(\d+)$/) {
+if ($node =~ /^(?:node)?(\d+)$/) {
   $node = $1;
 } else {
-  print "Need to specify node!\n";
-  die "drop_node nodeN\n";
+  die $USAGE;
 }
 
-my $OUTPUTFILE="/tmp/slonik-drop.$$";
-open(SLONIK, ">$OUTPUTFILE");
+my $FILE="/tmp/slonik-drop.$$";
+open(SLONIK, ">", $FILE);
 print SLONIK genheader();
-print SLONIK qq{
-try {
-      drop node (id = $node, event node = $MASTERNODE);
-} on error {
-      echo 'Failed to drop node $node from cluster';
-      exit 1;
-}
-echo 'dropped node $node cluster';
-};
+print SLONIK "  try {\n";
+print SLONIK "      drop node (id = $node, event node = $MASTERNODE);\n";
+print SLONIK "  } on error {\n";
+print SLONIK "      echo 'Failed to drop node $node from cluster';\n";
+print SLONIK "      exit 1;\n";
+print SLONIK "  }\n";
+print SLONIK "  echo 'dropped node $node cluster';\n";
 close SLONIK;
-run_slonik_script($OUTPUTFILE);
+run_slonik_script($FILE);
--- tools/altperl/restart_nodes.pl
+++ /dev/null
@@ -1,20 +0,0 @@
-#!@@PERL@@
-# $Id: restart_nodes.pl,v 1.6 2005/02/10 06:22:41 smsimms Exp $
-# Author: Christopher Browne
-# Copyright 2004 Afilias Canada
-
-require '@@PGLIBDIR@@/slon-tools.pm';
-require '@@SYSCONFDIR@@/slon_tools.conf';
-
-my $FILE="/tmp/restart.$$";
-foreach my $node (@NODES) {
-  my $dsn = $DSN[$node];
-  open(SLONIK, ">$FILE");
-  print SLONIK qq{
-	cluster name = $CLUSTER_NAME ;
-	node $node admin conninfo = '$dsn';
-	restart node $node;
-    };
-  close SLONIK;
-  run_slonik_script($FILE);
-}
Index: move_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/move_set.pl,v
retrieving revision 1.7
retrieving revision 1.8
diff -Ltools/altperl/move_set.pl -Ltools/altperl/move_set.pl -u -w -r1.7 -r1.8
--- tools/altperl/move_set.pl
+++ tools/altperl/move_set.pl
@@ -3,48 +3,67 @@
 # Author: Christopher Browne
 # Copyright 2004 Afilias Canada
 
+use Getopt::Long;
+
+# Defaults
+$CONFIG_FILE = '@@SYSCONFDIR@@/slon_tools.conf';
+$SHOW_USAGE  = 0;
+
+# Read command-line options
+GetOptions("config=s" => \$CONFIG_FILE,
+	   "help"     => \$SHOW_USAGE);
+
+my $USAGE =
+"Usage: move_set [--config file] set# from_node# to_node#
+
+    Change a set's origin.
+
+";
+
+if ($SHOW_USAGE) {
+  print $USAGE;
+  exit 0;
+}
+
 require '@@PGLIBDIR@@/slon-tools.pm';
-require '@@SYSCONFDIR@@/slon_tools.conf';
+require $CONFIG_FILE;
 
 my ($set, $node1, $node2) = @ARGV;
-if ($set =~ /^set(\d+)$/) {
+if ($set =~ /^(?:set)?(\d+)$/) {
   # Node name is in proper form
   $set = $1;
 } else {
   print "Valid set names are set1, set2, ...\n\n";
-  die "Usage: ./move_set.pl setN nodeOLD nodeNEW\n";
+  die $USAGE;
 }
 
-if ($node1 =~ /^node(\d+)$/) {
+if ($node1 =~ /^(?:node)?(\d+)$/) {
   $node1 = $1;
 } else {
   print "Valid node names are node1, node2, ...\n\n";
-  die "Usage: ./move_set.pl setN nodeOLD nodeNEW\n";
+  die $USAGE;
 }
-if ($node2 =~ /^node(\d+)$/) {
+
+if ($node2 =~ /^(?:node)?(\d+)$/) {
   $node2 = $1;
 } else {
   print "Valid node names are node1, node2, ...\n\n";
-  die "Usage: ./move_set.pl setN nodeOLD nodeNEW\n";
+  die $USAGE;
 }
 
-open(SLONIK, ">/tmp/slonik.$$");
+open(SLONIK, ">", "/tmp/slonik.$$");
 print SLONIK genheader();
-my ($dbname, $dbhost)=($DBNAME[1], $HOST[1]);
-print SLONIK qq[
-        try {
-                echo 'Locking down set $set on node $node1';
-                lock set (id = $set, origin = $node1);
-                echo 'Locked down - moving it';
-                move set (id = $set, old origin = $node1, new origin = $node2);
-        }
-        on error {
-                echo 'Failure to move set $set from $node1 to $node2';
-                unlock set (id = $set, origin = $node1);
-                exit 1;
-        }
-        echo 'Replication set $set moved from node $node1 to $node2';
-];
-
+print SLONIK "  try {\n";
+print SLONIK "      echo 'Locking down set $set on node $node1';\n";
+print SLONIK "      lock set (id = $set, origin = $node1);\n";
+print SLONIK "      echo 'Locked down - moving it';\n";
+print SLONIK "      move set (id = $set, old origin = $node1, new origin = $node2);\n";
+print SLONIK "  }\n";
+print SLONIK "  on error {\n";
+print SLONIK "      echo 'Failure to move set $set from $node1 to $node2';\n";
+print SLONIK "      unlock set (id = $set, origin = $node1);\n";
+print SLONIK "      exit 1;\n";
+print SLONIK "  }\n";
+print SLONIK "  echo 'Replication set $set moved from node $node1 to $node2';\n";
 close SLONIK;
 run_slonik_script("/tmp/slonik.$$");
Index: show_configuration.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/show_configuration.pl,v
retrieving revision 1.5
retrieving revision 1.6
diff -Ltools/altperl/show_configuration.pl -Ltools/altperl/show_configuration.pl -u -w -r1.5 -r1.6
--- tools/altperl/show_configuration.pl
+++ tools/altperl/show_configuration.pl
@@ -6,8 +6,28 @@
 # This script simply displays an overview of node configuration
 # for a given SLONY node set
 
+use Getopt::Long;
+
+# Defaults
+$CONFIG_FILE = '@@SYSCONFDIR@@/slon_tools.conf';
+$SHOW_USAGE  = 0;
+
+# Read command-line options
+GetOptions("config=s" => \$CONFIG_FILE,
+	   "help"     => \$SHOW_USAGE);
+
+my $USAGE =
+"Usage: show_configuration [--config file]
+
+";
+
+if ($SHOW_USAGE) {
+  print $USAGE;
+  exit 0;
+}
+
 require '@@PGLIBDIR@@/slon-tools.pm';
-require '@@SYSCONFDIR@@/slon_tools.conf';
+require $CONFIG_FILE;
 
 print "Slony Configuration\n-------------------------------------\n";
 if ($ENV{"SLONYNODES"}) {
@@ -29,10 +49,8 @@
 Node information
 --------------------------------
 };
-foreach $node (0..100) {
-  if ($DSN[$node]) {
+foreach $node (@NODES) {
     printf("Node: %2d Host: %15s User: %8s Port: %4d Forwarding? %4s Parent: %2d Database: %10s\n         DSN: %s\n",
 	   $node, $HOST[$node], $USER[$node], $PORT[$node], $NOFORWARD[$node],
 	   $PARENT[$node], $DBNAME[$node], $DSN[$node]);
   }
-}
Index: slon_pushsql.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slon_pushsql.pl,v
retrieving revision 1.8
retrieving revision 1.9
diff -Ltools/altperl/slon_pushsql.pl -Ltools/altperl/slon_pushsql.pl -u -w -r1.8 -r1.9
--- tools/altperl/slon_pushsql.pl
+++ tools/altperl/slon_pushsql.pl
@@ -3,38 +3,60 @@
 # Author: Christopher Browne
 # Copyright 2004 Afilias Canada
 
+use Getopt::Long;
+
+# Defaults
+$CONFIG_FILE = '@@SYSCONFDIR@@/slon_tools.conf';
+$SHOW_USAGE  = 0;
+
+# Read command-line options
+GetOptions("config=s" => \$CONFIG_FILE,
+	   "help"     => \$SHOW_USAGE);
+
+my $USAGE =
+"Usage: slon_pushsql [--config file] set# node# full_path_to_sql_script_file
+
+    Executes the contents of a SQL script file on the specified set and node.
+
+    The script only needs to exist on the machine running the slon daemon.
+
+";
+
+if ($SHOW_USAGE) {
+  print $USAGE;
+  exit 0;
+}
+
 require '@@PGLIBDIR@@/slon-tools.pm';
-require '@@SYSCONFDIR@@/slon_tools.conf';
+require $CONFIG_FILE;
+
 my ($set, $node, $file) = @ARGV;
-if ($set =~ /^set(\d+)$/) {
+if ($set =~ /^(?:set)?(\d+)$/) {
   $set = $1;
 } else {
-  print "Invalid set identifier";
-  die "Usage: ./slon_pushsql.pl set[N] node[N] full_path_to_sql_script_file\n";
+  print "Invalid set identifier\n\n";
+  die $USAGE;
 }
-if ($node =~ /^node(\d+)$/) {
+
+if ($node =~ /^(?:node)?(\d+)$/) {
   $node = $1;
 } else {
-  print "Invalid node identifier";
-  die "Usage: ./slon_pushsql.pl set[N] node[N] full_path_to_sql_script_file\n";
+  print "Invalid node identifier\n\n";
+  die $USAGE;
 }
 
-if ($file =~ /^\//) {
-} else {
-  print "SQL script path needs to be a full path, i.e. /tmp/my_script.sql\n";
-  die "Usage: ./slon_pushsql.pl set[N] node[N] full_path_to_sql_script_file\n";
+unless ($file =~ /^\// and -f $file) {
+  print "SQL script path needs to be a full path, e.g. /tmp/my_script.sql\n\n";
+  die $USAGE;
 }
 
 my $FILE="/tmp/gensql.$$";
-open(SLONIK, ">$FILE");
+open(SLONIK, ">", $FILE);
 print SLONIK genheader();
-
-print SLONIK qq{
-  execute script (
-    set id=$set,
-    filename='$file',
-    event node = $node
-  );
-};
+print SLONIK "  execute script (\n";
+print SLONIK "    set id = $set,\n";
+print SLONIK "    filename = '$file',\n";
+print SLONIK "    event node = $node\n";
+print SLONIK "  );\n";
 close SLONIK;
 run_slonik_script($FILE);
Index: unsubscribe_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/unsubscribe_set.pl,v
retrieving revision 1.6
retrieving revision 1.7
diff -Ltools/altperl/unsubscribe_set.pl -Ltools/altperl/unsubscribe_set.pl -u -w -r1.6 -r1.7
--- tools/altperl/unsubscribe_set.pl
+++ tools/altperl/unsubscribe_set.pl
@@ -3,35 +3,55 @@
 # Author: Christopher Browne
 # Copyright 2004 Afilias Canada
 
+use Getopt::Long;
+
+# Defaults
+$CONFIG_FILE = '@@SYSCONFDIR@@/slon_tools.conf';
+$SHOW_USAGE  = 0;
+
+# Read command-line options
+GetOptions("config=s" => \$CONFIG_FILE,
+	   "help"     => \$SHOW_USAGE);
+
+my $USAGE =
+"Usage: unsubscribe_set [--config file] set# node#
+
+    Stops replicating a set on the specified node.
+
+";
+
+if ($SHOW_USAGE) {
+  print $USAGE;
+  exit 0;
+}
+
 require '@@PGLIBDIR@@/slon-tools.pm';
-require '@@SYSCONFDIR@@/slon_tools.conf';
+require $CONFIG_FILE;
 
 my ($set, $node) = @ARGV;
-if ($node =~ /^node(\d+)$/) {
+if ($node =~ /^(?:node)?(\d+)$/) {
   $node = $1;
 } else {
-  print "Need to specify node!\n";
-  die "unsubscribe_set setM nodeN\n";
+  print "Need to specify node!\n\n";
+  die $USAGE;
 }
 
-if ($set =~ /^set(\d+)$/) {
+if ($set =~ /^(?:set)?(\d+)$/) {
   $set = $1;
 } else {
-  print "Need to specify set!\n";
-  die "unsubscribe_set setM nodeN\n";
+  print "Need to specify set!\n\n";
+  die $USAGE;
 }
 
-open(SLONIK, ">/tmp/slonik-unsubscribe.$$");
+open(SLONIK, ">", "/tmp/slonik-unsubscribe.$$");
 print SLONIK genheader();
-print SLONIK qq{
-        try {
-                unsubscribe set (id = $set, receiver = $node);
-        }
-        on error {
-                echo 'Failed to unsubscribe node $node from set $set';
-                exit 1;
-        }
-        echo 'unsubscribed node $node from set $set';
-};
+print SLONIK "  try {\n";
+print SLONIK "      unsubscribe set (id = $set, receiver = $node);\n";
+print SLONIK "  }\n";
+print SLONIK "  on error {\n";
+print SLONIK "      echo 'Failed to unsubscribe node $node from set $set';\n";
+print SLONIK "      exit 1;\n";
+print SLONIK "  }\n";
+print SLONIK "  echo 'unsubscribed node $node from set $set';\n";
 close SLONIK;
 run_slonik_script("/tmp/slonik-unsubscribe.$$");
Index: failover.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/failover.pl,v
retrieving revision 1.7
retrieving revision 1.8
diff -Ltools/altperl/failover.pl -Ltools/altperl/failover.pl -u -w -r1.7 -r1.8
--- tools/altperl/failover.pl
+++ tools/altperl/failover.pl
@@ -3,41 +3,56 @@
 # Author: Christopher Browne
 # Copyright 2004 Afilias Canada
 
+use Getopt::Long;
+
+# Defaults
+$CONFIG_FILE = '@@SYSCONFDIR@@/slon_tools.conf';
+$SHOW_USAGE  = 0;
+
+# Read command-line options
+GetOptions("config=s" => \$CONFIG_FILE,
+	   "help"     => \$SHOW_USAGE);
+
+my $USAGE =
+"Usage: failover [--config file] dead_node backup_node
+
+    Abandons dead_node, making backup_node the origin for all sets on
+    dead_node.
+
+    move_set should be used if dead_node is still available, so that
+    transactions are not lost.
+
+";
+
+if ($SHOW_USAGE) {
+  print $USAGE;
+  exit 0;
+}
+
 require '@@PGLIBDIR@@/slon-tools.pm';
-require '@@SYSCONFDIR@@/slon_tools.conf';
+require $CONFIG_FILE;
 
-my ($node1, $set1, $node2) = @ARGV;
-if ($node1 =~ /^node(\d+)$/) {
+my ($node1, $node2) = @ARGV;
+if ($node1 =~ /^(?:node)?(\d+)$/) {
   $node1 = $1;
 } else {
-  print "Valid node names are node1, node2, ...\n\n";
-  die "Usage: ./failover.pl nodeN setOLD nodeNEW\n";
-}
-if ($set1 =~ /^set(\d+)$/) {
-  $set1 = $1;
-} else {
-  print "Valid set names are set1, set2, ...\n\n";
-  die "Usage: ./failover.pl nodeN setOLD nodeNEW\n";
+  die $USAGE;
 }
-if ($node2 =~ /^node(\d+)$/) {
+
+if ($node2 =~ /^(?:node)?(\d+)$/) {
   $node2 = $1;
 } else {
-  print "Valid node names are node1, node2, ...\n\n";
-  die "Usage: ./failover.pl nodeN setOLD nodeNEW\n";
+  die $USAGE;
 }
 
-open(SLONIK, ">/tmp/slonik.$$");
+open(SLONIK, ">", "/tmp/slonik.$$");
 print SLONIK genheader();
-my ($dbname, $dbhost)=($DBNAME[1], $HOST[1]);
-print SLONIK qq[
-try {
-      failover (id = $node1, backup node = $node2);
-} on error {
-      echo 'Failure to fail node $node1 over to $node2';
-      exit 1;
-}
-      echo 'Replication sets originating on $node1 failed over to $node2';
-];
-
+print SLONIK "  try {\n";
+print SLONIK "      failover (id = $node1, backup node = $node2);\n";
+print SLONIK "  } on error {\n";
+print SLONIK "      echo 'Failure to fail node $node1 over to $node2';\n";
+print SLONIK "      exit 1;\n";
+print SLONIK "  }\n";
+print SLONIK "  echo 'Replication sets originating on $node1 failed over to $node2';\n";
 close SLONIK;
 run_slonik_script("/tmp/slonik.$$");
Index: restart_node.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/restart_node.pl,v
retrieving revision 1.6
retrieving revision 1.7
diff -Ltools/altperl/restart_node.pl -Ltools/altperl/restart_node.pl -u -w -r1.6 -r1.7
--- tools/altperl/restart_node.pl
+++ tools/altperl/restart_node.pl
@@ -1,21 +1,57 @@
-#!@@PERL@@
+#!/usr/bin/perl
 # $Id$
 # Author: Christopher Browne
 # Copyright 2004 Afilias Canada
 
+use Getopt::Long;
+
+# Defaults
+$CONFIG_FILE = '@@SYSCONFDIR@@/slon_tools.conf';
+$SHOW_USAGE  = 0;
+$ALL_NODES   = 0;
+
+# Read command-line options
+GetOptions("config=s" => \$CONFIG_FILE,
+	   "help"     => \$SHOW_USAGE,
+	   "all"      => \$ALL_NODES);
+
+my $USAGE =
+"Usage: restart_node [--config file] [--all] [node# ...]
+
+    Restart one or more nodes
+
+";
+
+if ($SHOW_USAGE) {
+  print $USAGE;
+  exit 0;
+}
+
 require '@@PGLIBDIR@@/slon-tools.pm';
-require '@@SYSCONFDIR@@/slon_tools.conf';
+require $CONFIG_FILE;
 
-my ($node) = @_;
-if ($node =~ /^node(\d+)$/) {
-  $nodenum = $node
-} else {
-  die "./restart_node nodeN\n";
+my @nodes;
+if ($ALL_NODES) {
+    @nodes = @NODES;
 } 
-my $FILE="/tmp/restart.$$";
+else {
+    foreach my $node (@ARGV) {
+	if ($node =~ /^(?:node)?(\d+)$/) {
+	    push @nodes, ($1);
+	}
+	else {
+	    die $USAGE;
+	}
+    }
+}
+
+die $USAGE unless scalar @nodes;
 
-open(SLONIK, ">$FILE");
+my $FILE="/tmp/restart.$$";
+open(SLONIK, ">", $FILE);
 print SLONIK genheader();
+foreach my $node (@nodes) {
 print SLONIK "restart node $node;\n";
+}
 close SLONIK;
 run_slonik_script($FILE);
Index: update_nodes.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/update_nodes.pl,v
retrieving revision 1.5
retrieving revision 1.6
diff -Ltools/altperl/update_nodes.pl -Ltools/altperl/update_nodes.pl -u -w -r1.5 -r1.6
--- tools/altperl/update_nodes.pl
+++ tools/altperl/update_nodes.pl
@@ -3,12 +3,33 @@
 # Author: Christopher Browne
 # Copyright 2004 Afilias Canada
 
+use Getopt::Long;
+
+# Defaults
+$CONFIG_FILE = '@@SYSCONFDIR@@/slon_tools.conf';
+$SHOW_USAGE  = 0;
+
+# Read command-line options
+GetOptions("config=s" => \$CONFIG_FILE,
+	   "help"     => \$SHOW_USAGE);
+
+my $USAGE =
+"Usage: update_nodes.pl [--config file]
+
+    Updates the functions on all nodes.
+
+";
+
+if ($SHOW_USAGE) {
+  print $USAGE;
+  exit 0;
+}
+
 require '@@PGLIBDIR@@/slon-tools.pm';
-require '@@SYSCONFDIR@@/slon_tools.conf';
+require $CONFIG_FILE;
 
-open(SLONIK, ">/tmp/update_nodes.$$");
+open(SLONIK, ">", "/tmp/update_nodes.$$");
 print SLONIK genheader();
-
 foreach my $node (@NODES) {
   print SLONIK "update functions (id = $node);\n";
 };


More information about the Slony1-commit mailing list