Darcy Buskermolen darcy
Mon Jun 21 20:53:37 PDT 2004

On June 21, 2004 11:32 am, Christopher Browne wrote:
> The attached patch does several things to make the script cleaner:
>
>  1.  Centralizes /tmp filename variables to be set up in one spot;
>
>  2.  Exclusively references those variables from 1), rather than using
>      literal values;
>
>  3.  Fixes a misspelling or two;
>
>  4.  Introduces the function generate_abend($message), which indicates
>      what was being worked on so that the gentle user knows where to
>      look in the log for what failed.
>
>      This is reasonably verbose about explaining what was being done.


I'll look at incorporating these changes into our new(er) version of the setup 
script over the next 48 hours.  

Once again, thank you -- Slony-I development group


>
> Index: slony_setup.pl
> ===================================================================
> RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/slony_setup.pl,v
> retrieving revision 1.5
> diff -c -u -r1.5 slony_setup.pl
> --- slony_setup.pl	10 Jun 2004 01:56:20 -0000	1.5
> +++ slony_setup.pl	21 Jun 2004 18:28:19 -0000
> @@ -114,6 +114,8 @@
>  my $pgpassfile = $ENV{"HOME"} . "/.pgpass";
>  my $pgpassbackup = "$tmpdir/.pgpass.backup";
>  my $dump_file = "/tmp/slony_dump";
> +my $setup_log = "/tmp/slony_setup.log";
> +my $setup_script = "/tmp/slony_master_setup.sh";
>
>  #
>  # Make sure we have the correct version
> @@ -251,7 +253,7 @@
>  		print "\n\nConnection to $which failed. Try again? (Answering NO will
> abort) (Y|n) "; &clean_up if ! &get_one_bool;
>  	} else {
> -		print "\n\n$which connection successfull\n";
> +		print "\n\n$which connection successful\n";
>  		&get_databases ($which);
>  		$slavenumber++;
>  		$which = "slave_$slavenumber";
> @@ -392,7 +394,7 @@
>  	#
>  	# Make this a variable!! FIXME!!
>  	#
> -  open F, ">/tmp/slony_master_setup.sh" or death ("Can't open
> /tmp/slony_master_setup.sh: $!"); +  open F, ">$setup_script" or death
> ("Can't open $setup_script: $!"); print F "#/bin/bash\n\n";
>
>  	#
> @@ -405,7 +407,7 @@
>  	$data{"master"}{"coninfo"} .= " password=" . $data{"master"}{"password"}
> if $data{"master"}{"password"} !~ /(\s+|\*)/; $data{"master"}{"coninfo"} .=
> "'";
>
> -	my $all_conn = "slonik <<_EOF_ 2>> /tmp/slony_setup.log 1>>
> /tmp/slony_setup.log\n\tcluster name = T1; +	my $all_conn = "slonik <<_EOF_
> 2>> $setup_log 1>> $setup_log\n\tcluster name = T1; node 1 admin conninfo =
> " . $data{"master"}{"coninfo"} . ";\n";
>
>  	foreach my $slave (sort keys %{$data{"slaves"}}) {
> @@ -447,7 +449,7 @@
>
>  if [ \$? -ne 0 ]
>  then
> -	echo Errors were detected. Please review /tmp/slony_setup.log.  Uninstall
> halted. +	echo Errors were detected. Please review $setup_log.  Uninstall
> halted. exit -1
>  fi
>
> @@ -459,7 +461,7 @@
>  fi
>
>  rm -f ~/.pgpass
> -rm -f /tmp/slony_setup.log
> +rm -f $setup_log
>
>  ";
>
> @@ -495,12 +497,8 @@
>  				"'" . $data{"master"}{"users"}{$user}{"passwd"} . "'," .
>  				(($data{"master"}{"users"}{$user}{"valuntil"}) ? "'" .
> $data{"master"}{"users"}{$user}{"valuntil"} . "'": "null") . "," .
> (($data{"master"}{"users"}{$user}{"useconfig"}) ? "'" .
> $data{"master"}{"users"}{$user}{"useconfig"} . "'": "null") . ")\"" .
> -				" 2>> /tmp/slony_setup.log 1>> /tmp/slony_setup.log\n";
> -			print F "\nif [ \$? -ne 0 ]\n";
> -			print F "then\n";
> -			print F "\techo Errors were detected. Please review
> /tmp/slony_setup.log and fix the errors.\n"; -			print F "\texit -1\n";
> -			print F "fi\n\n";
> +				" 2>> $setup_log 1>> $setup_log\n";
> +                        generate_abend("Adding user $user on slave
> $slave"); }
>  		#
>  		# Create all the groups that exist on the master database on each slave
> @@ -515,12 +513,8 @@
>  				"'" . $data{"master"}{"groups"}{$group}{"groname"} . "'," .
>  				"'" . $data{"master"}{"groups"}{$group}{"grosysid"} . "'," .
>  				"'" . $data{"master"}{"groups"}{$group}{"grolist"} . "')\"" .
> -				" 2>> /tmp/slony_setup.log 1>> /tmp/slony_setup.log\n";
> -			print F "\nif [ \$? -ne 0 ]\n";
> -			print F "then\n";
> -			print F "\techo Errors were detected. Please review
> /tmp/slony_setup.log and fix the errors.\n"; -			print F "\texit -1\n";
> -			print F "fi\n\n";
> +				" 2>> $setup_log 1>> $setup_log\n";
> +                        generate_abend("Creating group $group on slave
> $slave"); }
>  		#
>  		# Make sure plpgsql is created in template1 on all slaves
> @@ -530,12 +524,8 @@
>  			" -p " . $data{"slaves"}{$slave}{"port"} .
>  			" -U " . $data{"slaves"}{$slave}{"username"} .
>  			" plpgsql template1" .
> -			" 2>> /tmp/slony_setup.log 1>> /tmp/slony_setup.log\n";
> -		print F "\nif [ \$? -ne 0 ]\n";
> -		print F "then\n";
> -		print F "\techo Errors were detected. Please review /tmp/slony_setup.log
> and fix the errors.\n"; -		print F "\texit -1\n";
> -		print F "fi\n\n";
> +			" 2>> $setup_log 1>> $setup_log\n";
> +                generate_abend("Creating language plpgsql on slave
> $slave"); foreach my $database (keys %{$data{"master"}{"databases"}}) {
>  			#
>  			# Create the databases to be replicated on all slaves
> @@ -545,12 +535,8 @@
>  				" -p " . $data{"slaves"}{$slave}{"port"} .
>  				" -U " . $data{"slaves"}{$slave}{"username"} .
>  				" -O " . $data{"master"}{"databases"}{$database}{"owner"} .
> -				" $database 2>> /tmp/slony_setup.log 1>> /tmp/slony_setup.log\n";
> -			print F "\nif [ \$? -ne 0 ]\n";
> -			print F "then\n";
> -			print F "\techo Errors were detected. Please review
> /tmp/slony_setup.log and fix the errors.\n"; -			print F "\texit -1\n";
> -			print F "fi\n\n";
> +				" $database 2>> $setup_log 1>> $setup_log\n";
> +                        generate_abend("Create database $database on slave
> $slave"); #
>  			# Use the command that copies the entire schema at once, as this
> assures us # that dependencies will be done in order
> @@ -561,18 +547,14 @@
>  					" -p " . $data{"master"}{"port"} .
>  					" -U " . $data{"master"}{"username"} .
>  					" -s " . $database .
> -					" 2>> /tmp/slony_setup.log | \\\n" .
> +					" 2>> $setup_log | \\\n" .
>  					"psql" .
>  					" -h " . $data{"slaves"}{$slave}{"hostname"} .
>  					" -p " . $data{"slaves"}{$slave}{"port"} .
>  					" -U " . $data{"slaves"}{$slave}{"username"} .
>  					" -d " . $database .
> -					" 2>> /tmp/slony_setup.log 1>> /tmp/slony_setup.log\n";
> -				print F "\nif [ \$? -ne 0 ]\n";
> -				print F "then\n";
> -				print F "\techo Errors were detected. Please review
> /tmp/slony_setup.log and fix the errors.\n"; -				print F "\texit -1\n";
> -				print F "fi\n\n";
> +					" 2>> $setup_log 1>> $setup_log\n";
> +                                generate_abend("Create schema for
> $database on slave $slave"); #
>  			# Else, do it the hard way, and hope no dependencies are broken
>  			#
> @@ -586,18 +568,14 @@
>  						" -n " . $schema .
>  						" -t " . $tablename .
>  						" -s " . $database .
> -						" 2>> /tmp/slony_setup.log | \\\n" .
> +						" 2>> $setup_log | \\\n" .
>  						"psql" .
>  						" -h " . $data{"slaves"}{$slave}{"hostname"} .
>  						" -p " . $data{"slaves"}{$slave}{"port"} .
>  						" -U " . $data{"slaves"}{$slave}{"username"} .
>  						" -d " . $database .
> -						" 2>> /tmp/slony_setup.log 1>> /tmp/slony_setup.log\n";
> -					print F "\nif [ \$? -ne 0 ]\n";
> -					print F "then\n";
> -					print F "\techo Errors were detected. Please review
> /tmp/slony_setup.log and fix the errors.\n"; -					print F "\texit -1\n";
> -					print F "fi\n\n";
> +						" 2>> $setup_log 1>> $setup_log\n";
> +                                        generate_abend("Create table
> $table in schema $schema on slave $slave"); }
>  			}
>  		}
> @@ -724,7 +702,8 @@
>
>  if [ \$? -ne 0 ]
>  then
> -	echo Errors were detected. Please review /tmp/slony_setup.log and fix the
> errors. +        echo slonik failed to build subscription set for tables
> and sequences. +	echo Errors were detected. Please review $setup_log and
> fix the errors. exit -1
>  else
>  ";
> @@ -762,7 +741,8 @@
>
>  if [ \$? -ne 0 ]
>  then
> -	echo Errors were detected. Please review /tmp/slony_setup.log and fix the
> errors. +        echo Attempt to subscribe set to the slaves failed.
> +	echo Errors were detected. Please review $setup_log and fix the errors.
>  	exit -1
>  fi\n";
>
> @@ -776,14 +756,14 @@
>  close F;
>
>  my $end = "
> -The setup script was saved as /tmp/slony_master_setup.sh.  This script
> must +The setup script was saved as $setup_script.  This script must
>  be executed on the master as the slony system user.  If all goes well,
> slony -will be setup.  If not, errors should be reported in
> /tmp/slony_setup.log. +will be setup.  If not, errors should be reported in
> $setup_log.
>
>  Additionally, a data dump of all data collected by this script has been
> stored -in the file /tmp/slony_dump. You might want to save this file if
> you want to +in the file $dump_file. You might want to save this file if
> you want to run this script again with many of the same values.  A
> subsequent run of -slony_setup.pl looks for slony_dump in /tmp.
> +slony_setup.pl looks for $dump_file.
>
>  You must also run the following command(s) on each slave as the slony
> system user.  These commands should be also set to start and stop when
> postgres starts @@ -828,9 +808,10 @@
>  	if (-x $psql) {
>  		open P, "$psql --version |";
>  		while (<P>) {
> -			$_ =~ m/\s+(\d+)\.(\d+)((\w+)||(\.(\d+)))?\s+/;
> -			$pgversion_major = $1;
> -			$pgversion_minor = $2;
> +			if ($_ =~ m/\s+(\d+)\.(\d+)((\w+)||(\.(\d+)))?\s+/) {
> +			    $pgversion_major = $1;
> +			    $pgversion_minor = $2;
> +			}
>  		}
>  		close P;
>  		if ($pgversion_major == 7 && $pgversion_minor >= 3) {
> @@ -1088,4 +1069,18 @@
>  	my $message = shift;
>  	print "$message\n";
>  	&clean_up;
> +}
> +
> +
> +sub generate_abend {
> +  my ($descr) = @_;
> +  print F "if [ \$? -ne 0 ]\n";
> +  print F "then\n";
> +  if ($descr) {
> +    print F "\techo \"$descr\"\n";
> +  }
> +  print F "\techo Errors were detected. Please review $setup_log and fix
> the errors.\n"; +  print F "\texit -1;\n";
> +  print F "fi\n\n";
> +
>  }

-- 
Darcy Buskermolen
Wavefire Technologies Corp.
ph: 250.717.0200
fx:  250.763.1759
http://www.wavefire.com


More information about the Slony1-general mailing list