Index: tools/altperl/slon-tools.pm
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slon-tools.pm,v
retrieving revision 1.26
diff -c -r1.26 slon-tools.pm
*** tools/altperl/slon-tools.pm	15 Nov 2005 18:09:59 -0000	1.26
--- tools/altperl/slon-tools.pm	27 Oct 2006 14:00:01 -0000
***************
*** 82,100 ****
  # 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 "# -------------------------------------------------------------\n";
!   print OUT "# Script: $script submitted at $now \n";
    print OUT "# -------------------------------------------------------------\n";
    close OUT;
!   `cat $script >> $LOGDIR/slonik_scripts.log`;
!   #print `slonik < $script`;
!   print `cat $script`;
!   unlink($script);
  }
  
  sub ps_args {
--- 82,102 ----
  # Stores copy of slonik script in log file in $LOGDIR
  # then invokes it and deletes it
  sub run_slonik_script {
!   my ($script, $type) = @_;
    chomp $script;
+   chomp $type;
    open(OUT, ">>$LOGDIR/slonik_scripts.log");
    my $now = `date`;
    chomp $now;
+   # make sure logfile is well-formatted...
+   print OUT "\n";
    print OUT "# -------------------------------------------------------------\n";
!   print OUT "# $type script submitted at $now \n";
    print OUT "# -------------------------------------------------------------\n";
+   print OUT "\n";
+   print OUT $script;
    close OUT;
!   print STDOUT $script;
  }
  
  sub ps_args {
Index: tools/altperl/slonik_create_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_create_set.pl,v
retrieving revision 1.3
diff -c -r1.3 slonik_create_set.pl
*** tools/altperl/slonik_create_set.pl	15 Nov 2005 18:09:59 -0000	1.3
--- tools/altperl/slonik_create_set.pl	27 Oct 2006 14:00:01 -0000
***************
*** 20,25 ****
--- 20,27 ----
  
  ";
  
+ my $slonik = ''; 
+ 
  if ($SHOW_USAGE) {
      print $USAGE;
      exit 0;
***************
*** 34,91 ****
      die $USAGE;
  }
  
! $FILE="/tmp/add_tables.$$";
! open (SLONIK, ">", $FILE);
! print SLONIK genheader();
  
  # Tables without primary keys
! print SLONIK "\n";
! print SLONIK "# TABLE ADD KEY\n";
  foreach my $table (@SERIALTABLES) {
      $table = ensure_namespace($table);
      $table = lc($table) if $FOLD_CASE;
!     print SLONIK "  echo '  Adding unique key to table $table...';\n";
!     print SLONIK "  table add key (\n";
!     print SLONIK "    node id = $SET_ORIGIN,\n";
!     print SLONIK "    full qualified name='$table'\n";
!     print SLONIK "  );\n";
  }
  
  # CREATE SET
! print SLONIK "\n";
! print SLONIK "# CREATE SET\n";
! print SLONIK "  try {\n";
! print SLONIK "    create set (id = $SET_ID, origin = $SET_ORIGIN, comment = 'Set $SET_ID for $CLUSTER_NAME');\n";
! print SLONIK "  } on error {\n";
! print SLONIK "    echo 'Could not create subscription set $SET_ID for $CLUSTER_NAME!';\n";
! print SLONIK "    exit -1;\n";
! print SLONIK "  }\n";
  
  # SET ADD TABLE
! print SLONIK "\n";
! print SLONIK "# SET ADD TABLE\n";
! print SLONIK "  echo 'Subscription set $SET_ID created';\n";
! print SLONIK "  echo 'Adding tables to the subscription set';\n";
  
  $TABLE_ID = 1 if $TABLE_ID < 1;
  
  foreach my $table (@SERIALTABLES) {
      $table = ensure_namespace($table);
  	$table = lc($table) if $FOLD_CASE;
!     print SLONIK "  set add table (set id = $SET_ID, origin = $SET_ORIGIN, id = $TABLE_ID,\n";
!     print SLONIK "                 full qualified name = '$table', key=serial,\n";
!     print SLONIK "                 comment = 'Table $table without primary key');\n";
!     print SLONIK "  echo 'Add unkeyed table $table';\n";
      $TABLE_ID++;
  }
  
  foreach my $table (@PKEYEDTABLES) {
      $table = ensure_namespace($table);
  	$table = lc($table) if $FOLD_CASE;
!     print SLONIK "  set add table (set id = $SET_ID, origin = $SET_ORIGIN, id = $TABLE_ID,\n";
!     print SLONIK "                 full qualified name = '$table',\n";
!     print SLONIK "                 comment = 'Table $table with primary key');\n";
!     print SLONIK "  echo 'Add primary keyed table $table';\n";
      $TABLE_ID++;
  }
  
--- 36,91 ----
      die $USAGE;
  }
  
! $slonik .= genheader();
  
  # Tables without primary keys
! $slonik .= "\n";
! $slonik .= "# TABLE ADD KEY\n";
  foreach my $table (@SERIALTABLES) {
      $table = ensure_namespace($table);
      $table = lc($table) if $FOLD_CASE;
!     $slonik .= "  echo '  Adding unique key to table $table...';\n";
!     $slonik .= "  table add key (\n";
!     $slonik .= "    node id = $SET_ORIGIN,\n";
!     $slonik .= "    full qualified name='$table'\n";
!     $slonik .= "  );\n";
  }
  
  # CREATE SET
! $slonik .= "\n";
! $slonik .= "# CREATE SET\n";
! $slonik .= "  try {\n";
! $slonik .= "    create set (id = $SET_ID, origin = $SET_ORIGIN, comment = 'Set $SET_ID for $CLUSTER_NAME');\n";
! $slonik .= "  } on error {\n";
! $slonik .= "    echo 'Could not create subscription set $SET_ID for $CLUSTER_NAME!';\n";
! $slonik .= "    exit -1;\n";
! $slonik .= "  }\n";
  
  # SET ADD TABLE
! $slonik .= "\n";
! $slonik .= "# SET ADD TABLE\n";
! $slonik .= "  echo 'Subscription set $SET_ID created';\n";
! $slonik .= "  echo 'Adding tables to the subscription set';\n";
  
  $TABLE_ID = 1 if $TABLE_ID < 1;
  
  foreach my $table (@SERIALTABLES) {
      $table = ensure_namespace($table);
  	$table = lc($table) if $FOLD_CASE;
!     $slonik .= "  set add table (set id = $SET_ID, origin = $SET_ORIGIN, id = $TABLE_ID,\n";
!     $slonik .= "                 full qualified name = '$table', key=serial,\n";
!     $slonik .= "                 comment = 'Table $table without primary key');\n";
!     $slonik .= "  echo 'Add unkeyed table $table';\n";
      $TABLE_ID++;
  }
  
  foreach my $table (@PKEYEDTABLES) {
      $table = ensure_namespace($table);
  	$table = lc($table) if $FOLD_CASE;
!     $slonik .= "  set add table (set id = $SET_ID, origin = $SET_ORIGIN, id = $TABLE_ID,\n";
!     $slonik .= "                 full qualified name = '$table',\n";
!     $slonik .= "                 comment = 'Table $table with primary key');\n";
!     $slonik .= "  echo 'Add primary keyed table $table';\n";
      $TABLE_ID++;
  }
  
***************
*** 93,124 ****
      my $key = $KEYEDTABLES{$table};
      $table = ensure_namespace($table);
  	$table = lc($table) if $FOLD_CASE;
!     print SLONIK "  set add table (set id = $SET_ID, origin = $SET_ORIGIN, id = $TABLE_ID,\n";
!     print SLONIK "                 full qualified name = '$table', key='$key',\n";
!     print SLONIK "                 comment = 'Table $table with candidate primary key $key');\n";
!     print SLONIK "  echo 'Add candidate primary keyed table $table';\n";
      $TABLE_ID++;
  }
  
  # SET ADD SEQUENCE
! print SLONIK "\n";
! print SLONIK "# SET ADD SEQUENCE\n";
! print SLONIK "  echo 'Adding sequences to the subscription set';\n";
  
  $SEQUENCE_ID = 1 if $SEQUENCE_ID < 1;
  foreach my $seq (@SEQUENCES) {
      $seq = ensure_namespace($seq);
  	$seq = lc($seq) if $FOLD_CASE;
!     print SLONIK "  set add sequence (set id = $SET_ID, origin = $SET_ORIGIN, id = $SEQUENCE_ID,\n";
!     print SLONIK "                    full qualified name = '$seq',\n";
!     print SLONIK "                    comment = 'Sequence $seq');\n";
!     print SLONIK "  echo 'Add sequence $seq';\n";
      $SEQUENCE_ID++;
  }
! print SLONIK "  echo 'All tables added';\n";
  
! close SLONIK;
! run_slonik_script($FILE);
  
  ### If object hasn't a namespace specified, assume it's in "public", and make it so...
  sub ensure_namespace {
--- 93,123 ----
      my $key = $KEYEDTABLES{$table};
      $table = ensure_namespace($table);
  	$table = lc($table) if $FOLD_CASE;
!     $slonik .= "  set add table (set id = $SET_ID, origin = $SET_ORIGIN, id = $TABLE_ID,\n";
!     $slonik .= "                 full qualified name = '$table', key='$key',\n";
!     $slonik .= "                 comment = 'Table $table with candidate primary key $key');\n";
!     $slonik .= "  echo 'Add candidate primary keyed table $table';\n";
      $TABLE_ID++;
  }
  
  # SET ADD SEQUENCE
! $slonik .= "\n";
! $slonik .= "# SET ADD SEQUENCE\n";
! $slonik .= "  echo 'Adding sequences to the subscription set';\n";
  
  $SEQUENCE_ID = 1 if $SEQUENCE_ID < 1;
  foreach my $seq (@SEQUENCES) {
      $seq = ensure_namespace($seq);
  	$seq = lc($seq) if $FOLD_CASE;
!     $slonik .= "  set add sequence (set id = $SET_ID, origin = $SET_ORIGIN, id = $SEQUENCE_ID,\n";
!     $slonik .= "                    full qualified name = '$seq',\n";
!     $slonik .= "                    comment = 'Sequence $seq');\n";
!     $slonik .= "  echo 'Add sequence $seq';\n";
      $SEQUENCE_ID++;
  }
! $slonik .= "  echo 'All tables added';\n";
  
! run_slonik_script($slonik, 'CREATE SET');
  
  ### If object hasn't a namespace specified, assume it's in "public", and make it so...
  sub ensure_namespace {
Index: tools/altperl/slonik_drop_node.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_drop_node.pl,v
retrieving revision 1.1
diff -c -r1.1 slonik_drop_node.pl
*** tools/altperl/slonik_drop_node.pl	31 May 2005 16:11:05 -0000	1.1
--- tools/altperl/slonik_drop_node.pl	27 Oct 2006 14:00:01 -0000
***************
*** 35,49 ****
    die $USAGE;
  }
  
! my $FILE="/tmp/slonik-drop.$$";
! open(SLONIK, ">", $FILE);
! print SLONIK genheader();
! 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($FILE);
--- 35,49 ----
    die $USAGE;
  }
  
! my $slonik = '';
! 
! $slonik .= genheader();
! $slonik .= "  try {\n";
! $slonik .= "      drop node (id = $node, event node = $MASTERNODE);\n";
! $slonik .= "  } on error {\n";
! $slonik .= "      echo 'Failed to drop node $node from cluster';\n";
! $slonik .= "      exit 1;\n";
! $slonik .= "  }\n";
! $slonik .= "  echo 'dropped node $node cluster';\n";
! 
! run_slonik_script($slonik, 'DROP NODE');
Index: tools/altperl/slonik_drop_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_drop_set.pl,v
retrieving revision 1.1
diff -c -r1.1 slonik_drop_set.pl
*** tools/altperl/slonik_drop_set.pl	31 May 2005 16:11:05 -0000	1.1
--- tools/altperl/slonik_drop_set.pl	27 Oct 2006 14:00:01 -0000
***************
*** 38,51 ****
  
  get_set($set) or die "Non-existent set specified.\n";
  
! $FILE = "/tmp/dropset.$$";
! open(SLONIK, ">", $FILE);
! print SLONIK genheader();
! print SLONIK "  try {\n";
! print SLONIK "        drop set (id = $set, origin = $SET_ORIGIN);\n";
! print SLONIK "  } on error {\n";
! print SLONIK "        exit 1;\n";
! print SLONIK "  }\n";
! print SLONIK "  echo 'Dropped set $set';\n";
! close SLONIK;
! run_slonik_script($FILE);
--- 38,51 ----
  
  get_set($set) or die "Non-existent set specified.\n";
  
! my $slonik = '';
! 
! $slonik .= genheader();
! $slonik .= "  try {\n";
! $slonik .= "        drop set (id = $set, origin = $SET_ORIGIN);\n";
! $slonik .= "  } on error {\n";
! $slonik .= "        exit 1;\n";
! $slonik .= "  }\n";
! $slonik .= "  echo 'Dropped set $set';\n";
! 
! run_slonik_script($slonik, 'DROP SET');
Index: tools/altperl/slonik_drop_table.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_drop_table.pl,v
retrieving revision 1.1
diff -c -r1.1 slonik_drop_table.pl
*** tools/altperl/slonik_drop_table.pl	30 May 2006 14:52:35 -0000	1.1
--- tools/altperl/slonik_drop_table.pl	27 Oct 2006 14:00:01 -0000
***************
*** 40,59 ****
      die $USAGE;
  }
  
! $FILE="/tmp/drop_table.$$";
! open (SLONIK, ">", $FILE);
! print SLONIK genheader();
  
! # DROP TABLE
! print SLONIK "\n";
! print SLONIK "# DROP TABLE \n";
! print SLONIK "  try {\n";
! print SLONIK "    SET DROP TABLE (id = $TABLE_ID, origin = $SET_ORIGIN);\n";
! print SLONIK "  } on error {\n";
! print SLONIK "    echo 'Could not drop table $TABLE_ID for $CLUSTER_NAME!';\n";
! print SLONIK "    exit -1;\n";
! print SLONIK "  }\n";
  
  
! close SLONIK;
! run_slonik_script($FILE);
--- 40,57 ----
      die $USAGE;
  }
  
! my $slonik = '';
  
! $slonik .= genheader();
  
+ # DROP TABLE
+ $slonik .= "\n";
+ $slonik .= "# DROP TABLE \n";
+ $slonik .= "  try {\n";
+ $slonik .= "    SET DROP TABLE (id = $TABLE_ID, origin = $SET_ORIGIN);\n";
+ $slonik .= "  } on error {\n";
+ $slonik .= "    echo 'Could not drop table $TABLE_ID for $CLUSTER_NAME!';\n";
+ $slonik .= "    exit -1;\n";
+ $slonik .= "  }\n";
  
! run_slonik_script($slonik, 'DROP TABLE');
Index: tools/altperl/slonik_execute_script.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_execute_script.pl,v
retrieving revision 1.1
diff -c -r1.1 slonik_execute_script.pl
*** tools/altperl/slonik_execute_script.pl	31 May 2005 16:11:05 -0000	1.1
--- tools/altperl/slonik_execute_script.pl	27 Oct 2006 14:00:01 -0000
***************
*** 4,9 ****
--- 4,10 ----
  # Copyright 2004 Afilias Canada
  
  use Getopt::Long;
+ use File::Temp qw(tempfile);
  
  # Defaults
  $CONFIG_FILE = '@@SYSCONFDIR@@/slon_tools.conf';
***************
*** 14,19 ****
--- 15,24 ----
  # the get_set function.
  $node = 0;
  
+ # temp file variable for script handling
+ my $filename = '';
+ my $fh       = undef;
+ 
  # Read command-line options
  GetOptions("config=s" => \$CONFIG_FILE,
  	   "help"     => \$SHOW_USAGE,
***************
*** 69,77 ****
  }
  elsif ($SCRIPT_ARG) {
      # Put the script into a file
!     $file = "/tmp/execute_script.sql.$$";
!     my $fh;
!     open $fh, ">", $file;
      print $fh $SCRIPT_ARG;
      close $fh;
  }
--- 74,80 ----
  }
  elsif ($SCRIPT_ARG) {
      # Put the script into a file
!     ($fh, $filename) = tempfile();
      print $fh $SCRIPT_ARG;
      close $fh;
  }
***************
*** 80,92 ****
      die $USAGE;
  }
  
! my $FILE="/tmp/gensql.$$";
! open(SLONIK, ">", $FILE);
! print SLONIK genheader();
! 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);
--- 83,95 ----
      die $USAGE;
  }
  
! my $slonik = '';
! 
! $slonik .= genheader();
! $slonik .= "  execute script (\n";
! $slonik .= "    set id = $set,\n";
! $slonik .= "    filename = '$filename',\n";
! $slonik .= "    event node = $node\n";
! $slonik .= "  );\n";
! 
! run_slonik_script($slonik, 'EXECUTE SCRIPT');
Index: tools/altperl/slonik_failover.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_failover.pl,v
retrieving revision 1.1
diff -c -r1.1 slonik_failover.pl
*** tools/altperl/slonik_failover.pl	31 May 2005 16:11:05 -0000	1.1
--- tools/altperl/slonik_failover.pl	27 Oct 2006 14:00:01 -0000
***************
*** 45,58 ****
    die $USAGE;
  }
  
! open(SLONIK, ">", "/tmp/slonik.$$");
! print SLONIK genheader();
! 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.$$");
--- 45,58 ----
    die $USAGE;
  }
  
! my $slonik = '';
! $slonik .= genheader();
! $slonik .= "  try {\n";
! $slonik .= "      failover (id = $node1, backup node = $node2);\n";
! $slonik .= "  } on error {\n";
! $slonik .= "      echo 'Failure to fail node $node1 over to $node2';\n";
! $slonik .= "      exit 1;\n";
! $slonik .= "  }\n";
! $slonik .= "  echo 'Replication sets originating on $node1 failed over to $node2';\n";
! 
! run_slonik_script($slonik, 'FAILOVER');
Index: tools/altperl/slonik_init_cluster.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_init_cluster.pl,v
retrieving revision 1.1
diff -c -r1.1 slonik_init_cluster.pl
*** tools/altperl/slonik_init_cluster.pl	31 May 2005 16:11:05 -0000	1.1
--- tools/altperl/slonik_init_cluster.pl	27 Oct 2006 14:00:01 -0000
***************
*** 30,63 ****
  require '@@PGLIBDIR@@/slon-tools.pm';
  require $CONFIG_FILE;
  
- my $FILE="/tmp/init-cluster.$$";
- 
  # INIT CLUSTER
! open(SLONIK, ">", $FILE);
! print SLONIK "\n# INIT CLUSTER\n";
! print SLONIK genheader();
  my ($dbname, $dbhost) = ($DBNAME[$MASTERNODE], $HOST[$MASTERNODE]);
! print SLONIK "  init cluster (id = $MASTERNODE, comment = 'Node $MASTERNODE - $dbname\@$dbhost');\n";
  
  # STORE NODE
! print SLONIK "\n# STORE NODE\n";
  foreach my $node (@NODES) {
    if ($node != $MASTERNODE) {		# skip the master node; it's already initialized!
      my ($dbname, $dbhost) = ($DBNAME[$node], $HOST[$node]);
!     print SLONIK "  store node (id = $node, event node = $MASTERNODE, comment = 'Node $node - $dbname\@$dbhost');\n";
    }
  }
! print SLONIK "  echo 'Set up replication nodes';\n";
  
  # STORE PATH
! print SLONIK "\n# STORE PATH\n";
  
  my @COST;
  my @VIA;
  my @PATH;
  generate_listen_paths();
  
! print SLONIK "  echo 'Next: configure paths for each node/origin';\n";
  foreach my $nodea (@NODES) {
    my $dsna = $DSN[$nodea];
    foreach my $nodeb (@NODES) {
--- 30,62 ----
  require '@@PGLIBDIR@@/slon-tools.pm';
  require $CONFIG_FILE;
  
  # INIT CLUSTER
! my $slonik = '';
! 
! $slonik .= "\n# INIT CLUSTER\n";
! $slonik .= genheader();
  my ($dbname, $dbhost) = ($DBNAME[$MASTERNODE], $HOST[$MASTERNODE]);
! $slonik .= "  init cluster (id = $MASTERNODE, comment = 'Node $MASTERNODE - $dbname\@$dbhost');\n";
  
  # STORE NODE
! $slonik .= "\n# STORE NODE\n";
  foreach my $node (@NODES) {
    if ($node != $MASTERNODE) {		# skip the master node; it's already initialized!
      my ($dbname, $dbhost) = ($DBNAME[$node], $HOST[$node]);
!     $slonik .= "  store node (id = $node, event node = $MASTERNODE, comment = 'Node $node - $dbname\@$dbhost');\n";
    }
  }
! $slonik .= "  echo 'Set up replication nodes';\n";
  
  # STORE PATH
! $slonik .= "\n# STORE PATH\n";
  
  my @COST;
  my @VIA;
  my @PATH;
  generate_listen_paths();
  
! $slonik .= "  echo 'Next: configure paths for each node/origin';\n";
  foreach my $nodea (@NODES) {
    my $dsna = $DSN[$nodea];
    foreach my $nodeb (@NODES) {
***************
*** 66,76 ****
        my $providerba = $VIA[$nodea][$nodeb];
        my $providerab = $VIA[$nodeb][$nodea];
        if (!$printed[$nodea][$nodeb] and $providerab == $nodea) {
! 	print SLONIK "  store path (server = $nodea, client = $nodeb, conninfo = '$dsna');\n";
  	$printed[$nodea][$nodeb] = "done";
        }
        if (!$printed[$nodeb][$nodea] and $providerba == $nodea) {
! 	print SLONIK "  store path (server = $nodeb, client = $nodea, conninfo = '$dsnb');\n";
  	$printed[$nodeb][$nodea] = "done";
        }
      }
--- 65,75 ----
        my $providerba = $VIA[$nodea][$nodeb];
        my $providerab = $VIA[$nodeb][$nodea];
        if (!$printed[$nodea][$nodeb] and $providerab == $nodea) {
! 	$slonik .= "  store path (server = $nodea, client = $nodeb, conninfo = '$dsna');\n";
  	$printed[$nodea][$nodeb] = "done";
        }
        if (!$printed[$nodeb][$nodea] and $providerba == $nodea) {
! 	$slonik .= "  store path (server = $nodeb, client = $nodea, conninfo = '$dsnb');\n";
  	$printed[$nodeb][$nodea] = "done";
        }
      }
***************
*** 78,97 ****
  }
  
  # STORE LISTEN
! print SLONIK "\n# STORE LISTEN\n";
  foreach my $origin (@NODES) {
    my $dsna = $DSN[$origin];
    foreach my $receiver (@NODES) {
      if ($origin != $receiver) {
        my $provider = $VIA[$origin][$receiver];
!       print SLONIK "  store listen (origin = $origin, receiver = $receiver, provider = $provider);\n";
      }
    }
  }
! print SLONIK "  echo 'Replication nodes prepared';\n";
! print SLONIK "  echo 'Please start a slon replication daemon for each node';\n";
! close SLONIK;
! run_slonik_script($FILE);
  report_on_paths();
  
  sub generate_listen_paths {
--- 77,96 ----
  }
  
  # STORE LISTEN
! $slonik .= "\n# STORE LISTEN\n";
  foreach my $origin (@NODES) {
    my $dsna = $DSN[$origin];
    foreach my $receiver (@NODES) {
      if ($origin != $receiver) {
        my $provider = $VIA[$origin][$receiver];
!       $slonik .= "  store listen (origin = $origin, receiver = $receiver, provider = $provider);\n";
      }
    }
  }
! $slonik .= "  echo 'Replication nodes prepared';\n";
! $slonik .= "  echo 'Please start a slon replication daemon for each node';\n";
! 
! run_slonik_script($slonik, 'INIT CLUSTER');
  report_on_paths();
  
  sub generate_listen_paths {
Index: tools/altperl/slonik_merge_sets.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_merge_sets.pl,v
retrieving revision 1.1
diff -c -r1.1 slonik_merge_sets.pl
*** tools/altperl/slonik_merge_sets.pl	31 May 2005 16:11:05 -0000	1.1
--- tools/altperl/slonik_merge_sets.pl	27 Oct 2006 14:00:01 -0000
***************
*** 53,66 ****
  
  my ($dbname, $dbhost) = ($DBNAME[$MASTERNODE], $HOST[$MASTERNODE]);
  
! open(SLONIK, ">", "/tmp/slonik.$$");
! print SLONIK genheader();
! print SLONIK "  try {\n";
! print SLONIK "    merge set (id = $set1, add id = $set2, origin = $node);\n";
! print SLONIK "  } on error {\n";
! print SLONIK "    echo 'Failure to merge sets $set1 and $set2 with origin $node';\n";
! print SLONIK "    exit 1;\n";
! print SLONIK "  }\n";
! print SLONIK "  echo 'Replication set $set2 merged in with $set1 on origin $node';\n";
! close SLONIK;
! run_slonik_script("/tmp/slonik.$$");
--- 53,67 ----
  
  my ($dbname, $dbhost) = ($DBNAME[$MASTERNODE], $HOST[$MASTERNODE]);
  
! my $slonik = '';
! 
! $slonik .= genheader();
! $slonik .= "  try {\n";
! $slonik .= "    merge set (id = $set1, add id = $set2, origin = $node);\n";
! $slonik .= "  } on error {\n";
! $slonik .= "    echo 'Failure to merge sets $set1 and $set2 with origin $node';\n";
! $slonik .= "    exit 1;\n";
! $slonik .= "  }\n";
! $slonik .= "  echo 'Replication set $set2 merged in with $set1 on origin $node';\n";
! 
! run_slonik_script($slonik, 'MERGE SET');
Index: tools/altperl/slonik_move_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_move_set.pl,v
retrieving revision 1.1
diff -c -r1.1 slonik_move_set.pl
*** tools/altperl/slonik_move_set.pl	31 May 2005 16:11:05 -0000	1.1
--- tools/altperl/slonik_move_set.pl	27 Oct 2006 14:00:01 -0000
***************
*** 51,64 ****
    die $USAGE;
  }
  
! open(SLONIK, ">", "/tmp/slonik.$$");
! print SLONIK genheader();
! 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 "  echo 'Replication set $set moved from node $node1 to $node2.  Remember to';\n";
! print SLONIK "  echo 'update your configuration file, if necessary, to note the new location';\n";
! print SLONIK "  echo 'for the set.';\n";
! close SLONIK;
! run_slonik_script("/tmp/slonik.$$");
--- 51,65 ----
    die $USAGE;
  }
  
! my $slonik = '';
! 
! $slonik .= genheader();
! $slonik .= "  echo 'Locking down set $set on node $node1';\n";
! $slonik .= "  lock set (id = $set, origin = $node1);\n";
! $slonik .= "  echo 'Locked down - moving it';\n";
! $slonik .= "  move set (id = $set, old origin = $node1, new origin = $node2);\n";
! $slonik .= "  echo 'Replication set $set moved from node $node1 to $node2.  Remember to';\n";
! $slonik .= "  echo 'update your configuration file, if necessary, to note the new location';\n";
! $slonik .= "  echo 'for the set.';\n";
! 
! run_slonik_script($slonik, 'MOVE SET');
Index: tools/altperl/slonik_print_preamble.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_print_preamble.pl,v
retrieving revision 1.1
diff -c -r1.1 slonik_print_preamble.pl
*** tools/altperl/slonik_print_preamble.pl	30 May 2006 14:52:35 -0000	1.1
--- tools/altperl/slonik_print_preamble.pl	27 Oct 2006 14:00:01 -0000
***************
*** 32,39 ****
  require '/usr/local/pgsql/lib//slon-tools.pm';
  require $CONFIG_FILE;
  
! $FILE="/tmp/print_preamble.$$";
! open (SLONIK, ">", $FILE);
! print SLONIK genheader();
! close SLONIK;
! run_slonik_script($FILE);
--- 32,38 ----
  require '/usr/local/pgsql/lib//slon-tools.pm';
  require $CONFIG_FILE;
  
! my $slonik = '';
! $slonik .= genheader();
! 
! run_slonik_script($slonik, 'PRINT PREAMBLE');
Index: tools/altperl/slonik_restart_node.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_restart_node.pl,v
retrieving revision 1.1
diff -c -r1.1 slonik_restart_node.pl
*** tools/altperl/slonik_restart_node.pl	31 May 2005 16:11:05 -0000	1.1
--- tools/altperl/slonik_restart_node.pl	27 Oct 2006 14:00:01 -0000
***************
*** 47,57 ****
  
  die $USAGE unless scalar @nodes;
  
! 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);
--- 47,56 ----
  
  die $USAGE unless scalar @nodes;
  
! my $slonik = '';
! $slonik .= genheader();
  foreach my $node (@nodes) {
!     $slonik .= "  restart node $node;\n";
  }
! 
! run_slonik_script($slonik, 'RESTART NODE');
Index: tools/altperl/slonik_store_node.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_store_node.pl,v
retrieving revision 1.2
diff -c -r1.2 slonik_store_node.pl
*** tools/altperl/slonik_store_node.pl	30 May 2006 14:50:52 -0000	1.2
--- tools/altperl/slonik_store_node.pl	27 Oct 2006 14:00:01 -0000
***************
*** 39,64 ****
    die $USAGE;
  }
  
! my $FILE="/tmp/store_node.$$";
  
! open(SLONIK, ">", $FILE);
! print SLONIK genheader();
  
  # STORE NODE
! print SLONIK "\n# STORE NODE\n";
  my ($dbname, $dbhost) = ($DBNAME[$node], $HOST[$node]);
! print SLONIK "  store node (id = $node, event node = $MASTERNODE, comment = 'Node $node - $dbname\@$dbhost');\n";
! print SLONIK "  echo 'Set up replication nodes';\n";
  
  # STORE PATH
! print SLONIK "\n# STORE PATH\n";
  
  my @COST;
  my @VIA;
  my @PATH;
  generate_listen_paths();
  
! print SLONIK "  echo 'Next: configure paths for each node/origin';\n";
  foreach my $nodea (@NODES) {
      my $dsna = $DSN[$nodea];
      foreach my $nodeb (@NODES) {
--- 39,63 ----
    die $USAGE;
  }
  
! my $slonik = '';
  
! $slonik .= genheader();
  
  # STORE NODE
! $slonik .= "\n# STORE NODE\n";
  my ($dbname, $dbhost) = ($DBNAME[$node], $HOST[$node]);
! $slonik .= "  store node (id = $node, event node = $MASTERNODE, comment = 'Node $node - $dbname\@$dbhost');\n";
! $slonik .= "  echo 'Set up replication nodes';\n";
  
  # STORE PATH
! $slonik .= "\n# STORE PATH\n";
  
  my @COST;
  my @VIA;
  my @PATH;
  generate_listen_paths();
  
! $slonik .= "  echo 'Next: configure paths for each node/origin';\n";
  foreach my $nodea (@NODES) {
      my $dsna = $DSN[$nodea];
      foreach my $nodeb (@NODES) {
***************
*** 68,88 ****
  	    my $providerba = $VIA[$nodea][$nodeb];
  	    my $providerab = $VIA[$nodeb][$nodea];
  	    if (!$printed[$nodea][$nodeb] and $providerab == $nodea) {
! 		print SLONIK "  store path (server = $nodea, client = $nodeb, conninfo = '$dsna');\n";
  		$printed[$nodea][$nodeb] = "done";
  	    }
  	    if (!$printed[$nodeb][$nodea] and $providerba == $nodea) {
! 		print SLONIK "  store path (server = $nodeb, client = $nodea, conninfo = '$dsnb');\n";
  		$printed[$nodeb][$nodea] = "done";
  	    }
  	}
      }
  }
  
! print SLONIK "  echo 'Replication nodes prepared';\n";
! print SLONIK "  echo 'Please start a slon replication daemon for each node';\n";
! close SLONIK;
! run_slonik_script($FILE);
  report_on_paths();
  
  sub generate_listen_paths {
--- 67,87 ----
  	    my $providerba = $VIA[$nodea][$nodeb];
  	    my $providerab = $VIA[$nodeb][$nodea];
  	    if (!$printed[$nodea][$nodeb] and $providerab == $nodea) {
! 		$slonik .= "  store path (server = $nodea, client = $nodeb, conninfo = '$dsna');\n";
  		$printed[$nodea][$nodeb] = "done";
  	    }
  	    if (!$printed[$nodeb][$nodea] and $providerba == $nodea) {
! 		$slonik .= "  store path (server = $nodeb, client = $nodea, conninfo = '$dsnb');\n";
  		$printed[$nodeb][$nodea] = "done";
  	    }
  	}
      }
  }
  
! $slonik .= "  echo 'Replication nodes prepared';\n";
! $slonik .= "  echo 'Please start a slon replication daemon for each node';\n";
! 
! run_slonik_script($slonik, 'STORE NODE');
  report_on_paths();
  
  sub generate_listen_paths {
Index: tools/altperl/slonik_subscribe_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_subscribe_set.pl,v
retrieving revision 1.1
diff -c -r1.1 slonik_subscribe_set.pl
*** tools/altperl/slonik_subscribe_set.pl	31 May 2005 16:11:05 -0000	1.1
--- tools/altperl/slonik_subscribe_set.pl	27 Oct 2006 14:00:01 -0000
***************
*** 45,54 ****
  
  get_set($set) or die "Non-existent set specified.\n";
  
! $FILE="/tmp/slonik-subscribe.$$";
! open(SLONIK, ">$FILE");
! print SLONIK genheader();
! print SLONIK "  try {\n";
  
  if ($DSN[$node]) {
    my $provider = $SET_ORIGIN;
--- 45,54 ----
  
  get_set($set) or die "Non-existent set specified.\n";
  
! my $slonik = '';
! 
! $slonik .= genheader();
! $slonik .= "  try {\n";
  
  if ($DSN[$node]) {
    my $provider = $SET_ORIGIN;
***************
*** 61,75 ****
    } else {
      $forward = "yes";
    }
!   print SLONIK "    subscribe set (id = $set, provider = $provider, receiver = $node, forward = $forward);\n";
  } else {
    die "Node $node not found\n";
  }
  
! print SLONIK "  }\n";
! print SLONIK "  on error {\n";
! print SLONIK "    exit 1;\n";
! print SLONIK "  }\n";
! print SLONIK "  echo 'Subscribed nodes to set $set';\n";
! close SLONIK;
! run_slonik_script($FILE);
--- 61,75 ----
    } else {
      $forward = "yes";
    }
!   $slonik .= "    subscribe set (id = $set, provider = $provider, receiver = $node, forward = $forward);\n";
  } else {
    die "Node $node not found\n";
  }
  
! $slonik .= "  }\n";
! $slonik .= "  on error {\n";
! $slonik .= "    exit 1;\n";
! $slonik .= "  }\n";
! $slonik .= "  echo 'Subscribed nodes to set $set';\n";
! 
! run_slonik_script($slonik, 'SUBSCRIBE SET');
Index: tools/altperl/slonik_uninstall_nodes.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_uninstall_nodes.pl,v
retrieving revision 1.1
diff -c -r1.1 slonik_uninstall_nodes.pl
*** tools/altperl/slonik_uninstall_nodes.pl	31 May 2005 16:11:05 -0000	1.1
--- tools/altperl/slonik_uninstall_nodes.pl	27 Oct 2006 14:00:01 -0000
***************
*** 28,40 ****
  require '@@PGLIBDIR@@/slon-tools.pm';
  require $CONFIG_FILE;
  
! $FILE="/tmp/slonik.$$";
! open(SLONIK, ">$FILE");
! print SLONIK genheader();
  foreach my $node (@NODES) {
      next if $node == $MASTERNODE; # Do this one last
!     print SLONIK "  uninstall node (id=$node);\n";
  }
! print SLONIK "  uninstall node (id=$MASTERNODE);\n";
! close SLONIK;
! run_slonik_script($FILE);
--- 28,39 ----
  require '@@PGLIBDIR@@/slon-tools.pm';
  require $CONFIG_FILE;
  
! my $slonik = '';
! $slonik .= genheader();
  foreach my $node (@NODES) {
      next if $node == $MASTERNODE; # Do this one last
!     $slonik .= "  uninstall node (id=$node);\n";
  }
! $slonik .= "  uninstall node (id=$MASTERNODE);\n";
! 
! run_slonik_script($slonik, 'UNINSTALL NODE');
Index: tools/altperl/slonik_unsubscribe_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_unsubscribe_set.pl,v
retrieving revision 1.1
diff -c -r1.1 slonik_unsubscribe_set.pl
*** tools/altperl/slonik_unsubscribe_set.pl	31 May 2005 16:11:05 -0000	1.1
--- tools/altperl/slonik_unsubscribe_set.pl	27 Oct 2006 14:00:01 -0000
***************
*** 43,57 ****
    die $USAGE;
  }
  
! open(SLONIK, ">", "/tmp/slonik-unsubscribe.$$");
! print SLONIK genheader();
! 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.$$");
--- 43,57 ----
    die $USAGE;
  }
  
! my $slonik = '';
! $slonik .= genheader();
! $slonik .= "  try {\n";
! $slonik .= "      unsubscribe set (id = $set, receiver = $node);\n";
! $slonik .= "  }\n";
! $slonik .= "  on error {\n";
! $slonik .= "      echo 'Failed to unsubscribe node $node from set $set';\n";
! $slonik .= "      exit 1;\n";
! $slonik .= "  }\n";
! $slonik .= "  echo 'unsubscribed node $node from set $set';\n";
! 
! run_slonik_script($slonik, 'UNSUBSCRIBE SET');
Index: tools/altperl/slonik_update_nodes.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slonik_update_nodes.pl,v
retrieving revision 1.1
diff -c -r1.1 slonik_update_nodes.pl
*** tools/altperl/slonik_update_nodes.pl	31 May 2005 16:11:05 -0000	1.1
--- tools/altperl/slonik_update_nodes.pl	27 Oct 2006 14:00:01 -0000
***************
*** 28,37 ****
  require '@@PGLIBDIR@@/slon-tools.pm';
  require $CONFIG_FILE;
  
! 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.$$");
--- 28,37 ----
  require '@@PGLIBDIR@@/slon-tools.pm';
  require $CONFIG_FILE;
  
! my $slonik = '';
! $slonik .= genheader();
  foreach my $node (@NODES) {
!   $slonik .= "  update functions (id = $node);\n";
  };
! 
! run_slonik_script($slonik, 'UPDATE FUNCTIONS');
