CVS User Account cvsuser
Tue Aug 10 20:56:03 PDT 2004
Log Message:
-----------
- Renamed scripts that try to touch all nodes to indicate as much

- Added a new function, run_slonik_script(), to centralize the
  invocation of all Slonik scripts.

  Output is written to the file (whose name is passed in).

  run_slonik_script then does the following:
    - Puts a timestamp in $LOGDIR/slonik_scripts.log
    - Puts the body of the Slonik script into the same log file
    - Runs the slonik script
    - Purges it (which should be fine since it's preserved in the
      log file).

This means that we can always go back and look at whatever scripts
got thrown at Slonik.  Good for debugging; good for auditing.

Modified Files:
--------------
    slony1-engine/tools/altperl:
        create_set.pl (r1.3 -> r1.4)
        drop_node.pl (r1.1 -> r1.2)
        drop_set.pl (r1.1 -> r1.2)
        failover.pl (r1.1 -> r1.2)
        init_cluster.pl (r1.1 -> r1.2)
        merge_sets.pl (r1.1 -> r1.2)
        move_set.pl (r1.1 -> r1.2)
        reset_cluster.pl (r1.1 -> r1.2)
        slon_kill.pl (r1.1 -> r1.2)
        slon_pushsql.pl (r1.1 -> r1.2)
        subscribe_set.pl (r1.1 -> r1.2)
        unsubscribe_set.pl (r1.1 -> r1.2)
        slon-tools.pm (r1.2 -> r1.3)

Added Files:
-----------
    slony1-engine/tools/altperl:
        restart_nodes.pl (r1.1)
        uninstall_nodes.pl (r1.1)
        update_nodes.pl (r1.1)

-------------- next part --------------
Index: merge_sets.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/merge_sets.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -Ltools/altperl/merge_sets.pl -Ltools/altperl/merge_sets.pl -u -w -r1.1 -r1.2
--- tools/altperl/merge_sets.pl
+++ tools/altperl/merge_sets.pl
@@ -15,13 +15,13 @@
   die "Usage: ./merge_sets.pl nodeN setOLD setNEW\n";
 }
 
-if ($set1 =~ /^node(\d+)$/) {
+if ($set1 =~ /^set(\d+)$/) {
   $set1 = $1;
 } else {
   print "Valid set names are set1, set2, ...\n\n";
   die "Usage: ./merge_sets.pl nodeN setOLD setNEW\n";
 }
-if ($set2 =~ /^node(\d+)$/) {
+if ($set2 =~ /^set(\d+)$/) {
   $set2 = $1;
 } else {
   print "Valid set names are set1, set2, ...\n\n";
@@ -43,5 +43,4 @@
 ];
 
 close SLONIK;
-`slonik < /tmp/slonik.$$`;
-unlink("/tmp/slonik.$$");
+run_slonik_script("/tmp/slonik.$$");
Index: create_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/create_set.pl,v
retrieving revision 1.3
retrieving revision 1.4
diff -Ltools/altperl/create_set.pl -Ltools/altperl/create_set.pl -u -w -r1.3 -r1.4
--- tools/altperl/create_set.pl
+++ tools/altperl/create_set.pl
@@ -29,7 +29,8 @@
 ";
 }
 close OUTFILE;
-print `slonik < $OUTPUTFILE`;
+run_slonik_script($OUTPUTFILE);
+
 
 open (OUTFILE, ">$OUTPUTFILE");
 print OUTFILE genheader();
@@ -45,7 +46,7 @@
 ";
 
 close OUTFILE;
-print `slonik < $OUTPUTFILE`;
+run_slonik_script($OUTPUTFILE);
 
 open (OUTFILE, ">$OUTPUTFILE");
 print OUTFILE genheader();
@@ -75,7 +76,7 @@
 }
 
 close OUTFILE;
-print `slonik < $OUTPUTFILE`;
+run_slonik_script($OUTPUTFILE);
 
 open (OUTFILE, ">$OUTPUTFILE");
 print OUTFILE genheader();
@@ -97,8 +98,7 @@
         echo 'All tables added';
 ";
 
-print `slonik < $OUTPUTFILE`;
-unlink($OUTPUTFILE);
+run_slonik_script($OUTPUTFILE);
 
 ### If object hasn't a namespace specified, assume it's in "public", and make it so...
 sub ensure_namespace {
Index: subscribe_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/subscribe_set.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -Ltools/altperl/subscribe_set.pl -Ltools/altperl/subscribe_set.pl -u -w -r1.1 -r1.2
--- tools/altperl/subscribe_set.pl
+++ tools/altperl/subscribe_set.pl
@@ -20,7 +20,8 @@
   die "subscribe_set setM nodeN\n";
 }
 
-open(SLONIK, ">/tmp/slonik-subscribe.$$");
+$FILE="/tmp/slonik-subscribe.$$";
+open(SLONIK, ">$FILE");
 print SLONIK genheader();
 print SLONIK "try {\n";
 
@@ -49,5 +50,4 @@
 };
 
 close SLONIK;
-print `slonik < /tmp/slonik-subscribe.$$`;
-unlink("/tmp/slonik-subscribe.$$");
+run_slonik_script($FILE);
Index: init_cluster.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/init_cluster.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -Ltools/altperl/init_cluster.pl -Ltools/altperl/init_cluster.pl -u -w -r1.1 -r1.2
--- tools/altperl/init_cluster.pl
+++ tools/altperl/init_cluster.pl
@@ -7,8 +7,8 @@
 
 require 'slon-tools.pm';
 require 'slon.env';
-my $FILE="init-cluster";
-open(SLONIK, ">/tmp/$FILE.$$");
+my $FILE="/tmp/init-cluster.$$";
+open(SLONIK, ">$FILE");
 
 print SLONIK genheader();
 
@@ -32,10 +32,9 @@
 echo 'Set up replication nodes';
 ";
 close SLONIK;
+run_slonik_script($FILE);
 
-`slonik < /tmp/$FILE.$$`;
-
-open(SLONIK, ">/tmp/$FILE.$$");
+open(SLONIK, ">$FILE");
 print SLONIK genheader();
 
 my @VIA ;
@@ -60,9 +59,9 @@
 
 close SLONIK;
 
-`slonik < /tmp/$FILE.$$`;
+run_slonik_script($FILE);
 
-open(SLONIK, ">/tmp/$FILE.$$");
+open(SLONIK, ">$FILE");
 print SLONIK genheader();
 
 foreach my $origin (@NODES) {
@@ -81,8 +80,7 @@
 ];
 
 close SLONIK;
-`slonik < /tmp/$FILE.$$`;
-unlink("/tmp/$FILE.$$");
+run_slonik_script($FILE);
 
 sub generate_listen_paths {
     my @COST;
Index: drop_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/drop_set.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -Ltools/altperl/drop_set.pl -Ltools/altperl/drop_set.pl -u -w -r1.1 -r1.2
--- tools/altperl/drop_set.pl
+++ tools/altperl/drop_set.pl
@@ -10,10 +10,10 @@
   $set = $1;
 } else {
   print "Need set identifier\n";
-  croak "drop_set.pl setN\n";
+  die "drop_set.pl setN\n";
 }
-
-open(SLONIK, "|slonik");
+$OUTFILE="/tmp/dropset.$$";
+open(SLONIK, ">>$OUTFILE");
 
 print SLONIK genheader();
 
@@ -26,3 +26,5 @@
         }
         echo 'Dropped set $set';
 };
+close SLONIK;
+run_slonik_script($OUTFILE);
Index: reset_cluster.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/reset_cluster.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -Ltools/altperl/reset_cluster.pl -Ltools/altperl/reset_cluster.pl -u -w -r1.1 -r1.2
--- tools/altperl/reset_cluster.pl
+++ tools/altperl/reset_cluster.pl
@@ -34,7 +34,7 @@
 	}
     }
 }
-}
+
 print SLONIK qq[
         }
         on error {
@@ -46,5 +46,4 @@
 ];
 
 close SLONIK;
-`slonik < /tmp/slonik.$$`;
-unlink("/tmp/slonik.$$");
+run_slonik_script("/tmp/slonik.$$");
Index: unsubscribe_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/unsubscribe_set.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -Ltools/altperl/unsubscribe_set.pl -Ltools/altperl/unsubscribe_set.pl -u -w -r1.1 -r1.2
--- tools/altperl/unsubscribe_set.pl
+++ tools/altperl/unsubscribe_set.pl
@@ -34,5 +34,4 @@
         echo 'unsubscribed node $node from set $set';
 };
 close SLONIK;
-print `slonik < /tmp/slonik-unsubscribe.$$`;
-unlink("/tmp/slonik-unsubscribe.$$");
+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.1
retrieving revision 1.2
diff -Ltools/altperl/failover.pl -Ltools/altperl/failover.pl -u -w -r1.1 -r1.2
--- tools/altperl/failover.pl
+++ tools/altperl/failover.pl
@@ -6,18 +6,24 @@
 require 'slon-tools.pm';
 require 'slon.env';
 
-my ($node1, $node2) = @ARGV;
+my ($node1, $set1, $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 setNEW\n";
+  die "Usage: ./failover.pl nodeN setOLD nodeNEW\n";
 }
 if ($node2 =~ /^node(\d+)$/) {
   $node2 = $1;
 } else {
-  print "Valid set names are set1, set2, ...\n\n";
-  die "Usage: ./failover.pl nodeN setOLD setNEW\n";
+  print "Valid node names are node1, node2, ...\n\n";
+  die "Usage: ./failover.pl nodeN setOLD nodeNEW\n";
 }
 
 open(SLONIK, ">/tmp/slonik.$$");
@@ -35,5 +41,4 @@
 ];
 
 close SLONIK;
-`slonik < /tmp/slonik.$$`;
-unlink("/tmp/slonik.$$");
+run_slonik_script("/tmp/slonik.$$");
Index: drop_node.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/drop_node.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -Ltools/altperl/drop_node.pl -Ltools/altperl/drop_node.pl -u -w -r1.1 -r1.2
--- tools/altperl/drop_node.pl
+++ tools/altperl/drop_node.pl
@@ -14,7 +14,8 @@
   die "drop_node nodeN\n";
 }
 
-open(SLONIK, ">/tmp/slonik-drop.$$");
+my $OUTPUTFILE="/tmp/slonik-drop.$$";
+open(SLONIK, ">$OUTPUTFILE");
 print SLONIK genheader();
 print SLONIK qq{
         try {
@@ -27,5 +28,4 @@
         echo 'dropped node $node cluster';
 };
 close SLONIK;
-print `slonik < /tmp/slonik-drop.$$`;
-unlink("/tmp/slonik-drop.$$");
+run_slonik_script($OUTPUTFILE);
Index: slon-tools.pm
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slon-tools.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -Ltools/altperl/slon-tools.pm -Ltools/altperl/slon-tools.pm -u -w -r1.2 -r1.3
--- tools/altperl/slon-tools.pm
+++ tools/altperl/slon-tools.pm
@@ -70,6 +70,22 @@
       $header .= " node $node admin conninfo='$dsn';\n";
     }
   }
-  return $header
+  return $header;
+}
+
+# Stores copy of slonik script in log file in $LOGDIR
+# then invokes it and deletes it
+sub run_slonik_script {
+  my ($script) = @_;
+  chomp $script;
+  open(OUT, ">>$LOGDIR/slonik_scripts.log");
+  my $now = `date`;
+  chomp $now;
+  print OUT "-- Script: $script submitted at $now\n";
+  print OUT "-------------------------------------------------------------\n";
+  close OUT;
+  `cat $script >> $LOGDIR/slonik_scripts.log`;
+  print `slonik < $script`;
+  unlink($script);
 }
 return 1;
--- /dev/null
+++ tools/altperl/restart_nodes.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+# $Id: restart_nodes.pl,v 1.1 2004/08/10 20:55:33 cbbrowne Exp $
+# Author: Christopher Browne
+# Copyright 2004 Afilias Canada
+
+require 'slon-tools.pm';
+require 'slon.env';
+
+my $FILE="/tmp/restart.$$";
+foreach my $node (@NODES) {
+  my $dsn = $DSN[$node];
+  open(SLONIK, ">$FILE");
+  print SLONIK qq{
+	cluster name = $SETNAME ;
+	node $node admin conninfo = '$dsn';
+	restart node $node;
+    };
+  close SLONIK;
+  run_slonik_script($FILE);
+}
--- /dev/null
+++ tools/altperl/uninstall_nodes.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+# $Id: uninstall_nodes.pl,v 1.1 2004/08/10 20:55:34 cbbrowne Exp $
+# Author: Christopher Browne
+# Copyright 2004 Afilias Canada
+
+require 'slon-tools.pm';
+require 'slon.env';
+
+$FILE="/tmp/slonik.$$";
+open(SLONIK, ">$FILE");
+print SLONIK genheader();
+print SLONIK qq{
+	uninstall node (id=1);
+};
+close SLONIK;
+run_slonik_script($FILE);
+
+foreach my $node (@NODES) {
+  foreach my $command ("drop schema _$SETNAME cascade;") {
+    print $command, "\n";
+    print `echo "$command" | psql -h $HOST[$node] -U $USER[$node] -d $DBNAME[$node] -p $PORT[$node]`;
+  }
+  foreach my $t (@SERIALTABLES) {
+    my $command = "alter table $t drop column \\\"_Slony-I_" . $SETNAME . "_rowID\\\";";
+    print $command, "\n";
+    print `echo "$command" | psql -h $HOST[$node] -U $USER[$node] -d $DBNAME[$node] -p $PORT[$node]`;
+  }
+}
Index: move_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/move_set.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -Ltools/altperl/move_set.pl -Ltools/altperl/move_set.pl -u -w -r1.1 -r1.2
--- tools/altperl/move_set.pl
+++ tools/altperl/move_set.pl
@@ -48,5 +48,4 @@
 ];
 
 close SLONIK;
-`slonik < /tmp/slonik.$$`;
-unlink("/tmp/slonik.$$");
+run_slonik_script("/tmp/slonik.$$");
Index: slon_pushsql.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slon_pushsql.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -Ltools/altperl/slon_pushsql.pl -Ltools/altperl/slon_pushsql.pl -u -w -r1.1 -r1.2
--- tools/altperl/slon_pushsql.pl
+++ tools/altperl/slon_pushsql.pl
@@ -19,7 +19,8 @@
     die "Usage: ./slon_pushsql.pl set[N] node[N] sql_script_file\n";
 }
 
-open(SLONIK, "|slonik");
+my $FILE="/tmp/gensql.$$";
+open(SLONIK, ">$FILE");
 print SLONIK genheader();
 
 print SLONIK qq{
@@ -29,3 +30,5 @@
     event node = $node
   );
 };
+close SLONIK;
+run_slonik_script($FILE);
Index: slon_kill.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slon_kill.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -Ltools/altperl/slon_kill.pl -Ltools/altperl/slon_kill.pl -u -w -r1.1 -r1.2
--- /dev/null
+++ tools/altperl/update_nodes.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+# $Id: update_nodes.pl,v 1.1 2004/08/10 20:55:35 cbbrowne Exp $
+# Author: Christopher Browne
+# Copyright 2004 Afilias Canada
+
+require 'slon-tools.pm';
+require 'slon.env';
+
+open(SLONIK, ">/tmp/update_nodes.$$");
+print SLONIK genheader();
+
+foreach my $node (@NODES) {
+  print SLONIK "update functions (id = $node);\n";
+};
+close SLONIK;
+run_slonik_script("/tmp/update_nodes.$$");


More information about the Slony1-commit mailing list