Bug#492843: Patch against postgresql-common to allow passing pg_ctl options from cli and conf file

2009-03-17 Thread Cyril Bouthors
Martin,

Here's patch that fixes multiple arguments to pg_ctl and stops
redirecting STDOUT and STDERR to /dev/null in order for the errors to be
seen.
-- 
 ,''`.
: :' :  Cyril Bouthors
`. `' Debian.org
  `-
=== modified file 'PgCommon.pm'
--- PgCommon.pm	2009-02-15 12:54:33 +
+++ PgCommon.pm	2009-03-17 11:42:32 +
@@ -11,7 +11,7 @@
 our @ISA = ('Exporter');
 our @EXPORT = qw/error user_cluster_map get_cluster_port set_cluster_port
 get_cluster_socketdir set_cluster_socketdir cluster_port_running
-get_cluster_start_conf set_cluster_start_conf
+get_cluster_start_conf set_cluster_start_conf set_cluster_pg_ctl_conf
 get_program_path cluster_info get_versions get_newest_version version_exists
 get_version_clusters next_free_port cluster_exists install_file
 change_ugid config_bool get_db_encoding get_cluster_locales
@@ -408,6 +408,29 @@
 close F;
 }
 
+# Change pg_ctl.conf setting.
+# Arguments:  
+#  = options passed to pg_ctl(1)
+sub set_cluster_pg_ctl_conf {
+my ($v, $c, $val) = @_;
+
+my $perms = 0644;
+
+# pg_ctl.conf setting
+my $pg_ctl_conf = "$confroot/$v/$c/pg_ctl.conf";
+my $text = "# Automatic pg_ctl configuration
+# This configuration file contains cluster specific options to be passed to
+# pg_ctl(1).
+
+pg_ctl_options = '$val'
+";
+
+open F, '>' . $pg_ctl_conf or error "Could not open $pg_ctl_conf for writing: $!";
+chmod $perms, $pg_ctl_conf;
+print F $text;
+close F;
+}
+
 # Return a hash with information about a specific cluster.
 # Arguments:  
 # Returns: information hash (keys: pgdata, port, running, logfile [unless it

=== modified file 'architecture.html'
--- architecture.html	2009-02-15 12:55:03 +
+++ architecture.html	2009-03-13 10:42:15 +
@@ -93,6 +93,7 @@
 manual (do not start/stop in init script, but manual
 control with pg_ctlcluster is possible), disabled
 (pg_ctlcluster is not allowed).
+  optionally pg_ctl.conf: options to be passed to pg_ctl.
   optionally a symbolic link log which points to
   the postmaster log file. Defaults to
   /var/log/postgresql/postgresql-version-cluster.conf.  

=== modified file 'debian/changelog'
--- debian/changelog	2009-02-28 12:45:39 +
+++ debian/changelog	2009-03-13 11:25:52 +
@@ -2,6 +2,8 @@
 
   * t/030_errors.t: Fix "no space left on device" test for non-English
 locales.
+  * Added support for pg_ctl.conf by Cyril Bouthors 
+(Closes: #492843)
 
  -- Martin Pitt   Sat, 28 Feb 2009 13:45:13 +0100
 

=== modified file 'pg_createcluster'
--- pg_createcluster	2009-02-15 12:55:03 +
+++ pg_createcluster	2009-03-13 15:24:29 +
@@ -270,11 +270,15 @@
 # create default "start" file
 set_cluster_start_conf $version, $cluster, $startconf;
 
+# create default pg_ctl.conf file
+set_cluster_pg_ctl_conf $version, $cluster, '';
+
 # move conffiles, setup permissions
 move_conffile "$datadir/postgresql.conf", $confdir, $owneruid, $ownergid, '644';
 move_conffile "$datadir/pg_hba.conf", $confdir, $owneruid, $ownergid, '640', 'hba_file';
 move_conffile "$datadir/pg_ident.conf", $confdir, $owneruid, $ownergid, '640', 'ident_file';
 chown $owneruid, $ownergid, $datadir, $confdir, "$confdir/start.conf" or die "chown: $!";
+chown $owneruid, $ownergid, $datadir, $confdir, "$confdir/pg_ctl.conf" or die "chown: $!";
 
 PgCommon::set_conf_value $version, $cluster, 'postgresql.conf', 'data_directory', $datadir;
 
@@ -422,9 +426,9 @@
 I, it creates the necessary configuration files in
 CICIC; in particular these are
 C, C, C, a postgresql-common
-specific configuration file C (see B below), and a
-symbolic link C which points to the log file (by default,
-CIC<->IC<.log>).
+specific configuration file C (see B below),
+C and a symbolic link C which points to the log file (by
+default, CIC<->IC<.log>).
 
 C is automatically adapted to use the next available port, i.
 e. the first port (starting from 5432) which is not yet used by an already
@@ -569,6 +573,9 @@
 lower level tools to control the postmaster process; this option is only meant
 to prevent accidents during maintenance, not more.
 
+The C file in the cluster configuration directory controls the
+options passed to pg_ctl of that cluster.
+
 =back
 
 =head1 SEE ALSO

=== modified file 'pg_ctlcluster'
--- pg_ctlcluster	2009-02-15 13:53:59 +
+++ pg_ctlcluster	2009-03-17 15:58:34 +
@@ -5,6 +5,7 @@
 # stops on 'stop'.
 #
 # (C) 2005 Martin Pitt 
+# (C) 2009 Cyril Bouthors 
 
 use lib '/usr/share/postgresql-common';
 use Getopt::Long;
@@ -210,6 +211,13 @@
 }
 $logsize = (stat $info{'logfile'})[7];
 }
+
+push @options, @pg_ctl_opts_from_cli if @pg_ctl_opts_from_cli;
+
+my %pg_ctl_opts_from_file = read_cluster_conf_file $version, $cluster, 'pg_ctl.conf';
+push @options, split(' ', $pg_ctl_opts_from_file{'pg_ctl_options'})
+	if defined $pg_ctl_opts_from_file{'pg_ctl_options'} and $pg_ctl_opts_from_file{'pg_ctl_options'} ne '';
+
 p

Bug#492843: Patch against postgresql-common to allow passing pg_ctl options from cli and conf file

2009-03-17 Thread Cyril Bouthors
Martin,

According to our conversation on IRC, here's the patch against latest
BZR version of postgresql-common to allow passing pg_ctl options from
command line and configuration file to pg_ctlcluster.

The syntax is:
pg_ctlcluster version cluster -- pg_ctl_option

This is useful for run-time options like '-m smart" when doing
maintenance.


This patch also introduces a new configuration file called
/etc/postgresql/version/cluster/pg_ctl.conf in which you can pass
default arguments that will be called at boot time from initscripts.

The syntax is:
pg_ctl_options = 'OPTIONS'

This is quite useful when you want to activate options on the long term
run, like '-c'.


I updated the documentation accordingly [1], wrote tests for the new
features [2] and modified the other tools for coherence [3].

My patch also ships a test to ensure that the user postgres in the UNIX
group ssl-sert because tests will silently fail otherwise and fixes a
small issue in t/TestLib.pm regarding open files.

Regards,

[1] architecture.html, debian/changelog, pg_ctlcluster(8)
[2] t/085_pg_ctl.conf.t
[3] pg_createcluster, pg_dropcluster, pg_upgradecluster
-- 
 ,''`.
: :' :  Cyril Bouthors
`. `' Debian.org
  `-
=== modified file 'PgCommon.pm'
--- PgCommon.pm	2009-02-15 12:54:33 +
+++ PgCommon.pm	2009-03-17 11:42:32 +
@@ -11,7 +11,7 @@
 our @ISA = ('Exporter');
 our @EXPORT = qw/error user_cluster_map get_cluster_port set_cluster_port
 get_cluster_socketdir set_cluster_socketdir cluster_port_running
-get_cluster_start_conf set_cluster_start_conf
+get_cluster_start_conf set_cluster_start_conf set_cluster_pg_ctl_conf
 get_program_path cluster_info get_versions get_newest_version version_exists
 get_version_clusters next_free_port cluster_exists install_file
 change_ugid config_bool get_db_encoding get_cluster_locales
@@ -408,6 +408,29 @@
 close F;
 }
 
+# Change pg_ctl.conf setting.
+# Arguments:  
+#  = options passed to pg_ctl(1)
+sub set_cluster_pg_ctl_conf {
+my ($v, $c, $val) = @_;
+
+my $perms = 0644;
+
+# pg_ctl.conf setting
+my $pg_ctl_conf = "$confroot/$v/$c/pg_ctl.conf";
+my $text = "# Automatic pg_ctl configuration
+# This configuration file contains cluster specific options to be passed to
+# pg_ctl(1).
+
+pg_ctl_options = '$val'
+";
+
+open F, '>' . $pg_ctl_conf or error "Could not open $pg_ctl_conf for writing: $!";
+chmod $perms, $pg_ctl_conf;
+print F $text;
+close F;
+}
+
 # Return a hash with information about a specific cluster.
 # Arguments:  
 # Returns: information hash (keys: pgdata, port, running, logfile [unless it

=== modified file 'architecture.html'
--- architecture.html	2009-02-15 12:55:03 +
+++ architecture.html	2009-03-13 10:42:15 +
@@ -93,6 +93,7 @@
 manual (do not start/stop in init script, but manual
 control with pg_ctlcluster is possible), disabled
 (pg_ctlcluster is not allowed).
+  optionally pg_ctl.conf: options to be passed to pg_ctl.
   optionally a symbolic link log which points to
   the postmaster log file. Defaults to
   /var/log/postgresql/postgresql-version-cluster.conf.  

=== modified file 'debian/changelog'
--- debian/changelog	2009-02-28 12:45:39 +
+++ debian/changelog	2009-03-13 11:25:52 +
@@ -2,6 +2,8 @@
 
   * t/030_errors.t: Fix "no space left on device" test for non-English
 locales.
+  * Added support for pg_ctl.conf by Cyril Bouthors 
+(Closes: #492843)
 
  -- Martin Pitt   Sat, 28 Feb 2009 13:45:13 +0100
 

=== modified file 'pg_createcluster'
--- pg_createcluster	2009-02-15 12:55:03 +
+++ pg_createcluster	2009-03-13 15:24:29 +
@@ -270,11 +270,15 @@
 # create default "start" file
 set_cluster_start_conf $version, $cluster, $startconf;
 
+# create default pg_ctl.conf file
+set_cluster_pg_ctl_conf $version, $cluster, '';
+
 # move conffiles, setup permissions
 move_conffile "$datadir/postgresql.conf", $confdir, $owneruid, $ownergid, '644';
 move_conffile "$datadir/pg_hba.conf", $confdir, $owneruid, $ownergid, '640', 'hba_file';
 move_conffile "$datadir/pg_ident.conf", $confdir, $owneruid, $ownergid, '640', 'ident_file';
 chown $owneruid, $ownergid, $datadir, $confdir, "$confdir/start.conf" or die "chown: $!";
+chown $owneruid, $ownergid, $datadir, $confdir, "$confdir/pg_ctl.conf" or die "chown: $!";
 
 PgCommon::set_conf_value $version, $cluster, 'postgresql.conf', 'data_directory', $datadir;
 
@@ -422,9 +426,9 @@
 I, it creates the necessary configuration files in
 CICIC; in particular these are
 C, C, C, a postgresql-common
-specific configuration file C (see B below), and a
-symbolic link C which points to the log file (by default,
-CIC<->IC<.log>).
+specific configuration file C (see B below),
+C and a symbolic link C which points to the log file (by
+default, CIC<->IC<.log>).
 
 C is automatically adapted to use the next available port, i.
 e. the first port (starting from 5432) which is not yet used by an already
@@ -569,6