Skip to content
Snippets Groups Projects
Commit fecbaad0 authored by Martin Pitt's avatar Martin Pitt
Browse files

merge changes from at-work branch

parent 34faa042
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,9 @@ sub init_db {
}
}
# move a file to a directory with defined permissions
# move a file to a directory with defined permissions; if $version is smaller
# than 8.0, put a symlink at the old location (PostgreSQL prior to 8.0 does not
# support configurable conffiles).
# Arguments: <source file> <target dir> <uid> <gid> <perms>
sub move_conffile {
($file, $target, $uid, $gid, $perms) = @_;
......@@ -42,6 +44,18 @@ sub move_conffile {
error "move_conffile: could not install $file";
}
unlink $file;
if ($version < 8) {
@pathcomps = split ('/', $file);
$target .= '/' . $pathcomps[-1];
$oldgid = $);
$olduid = $>;
$) = $gid;
$> = $uid;
symlink $target, $file;
$> = $olduid;
$) = $oldgid;
}
} else {
error "move_conffile: required configuration file $file does not exist";
}
......
......@@ -21,9 +21,14 @@ if ($#ARGV != 2) {
sub start {
my $cdir = $info{'configdir'};
exec $pg_ctl, '-D', $info{'pgdata'},'-l', $info{'logfile'}, '-s', '-o',
"-c config_file=\"$cdir/postgresql.conf\" -c hba_file=\"$cdir/pg_hba.conf\" -c ident_file=\"$cdir/pg_ident.conf\"",
'start';
@options = ('start', '-D', $info{'pgdata'},'-l', $info{'logfile'}, '-s', '-o');
# versions 8.0+ support configurable conffile locations
if ($version >= 8) {
push @options, "-c config_file=\"$cdir/postgresql.conf\" -c hba_file=\"$cdir/pg_hba.conf\" -c ident_file=\"$cdir/pg_ident.conf\"";
}
exec $pg_ctl, @options;
}
sub stop {
......@@ -65,7 +70,8 @@ sub reload {
# main
#
%info = cluster_info ($ARGV[0], $ARGV[1]);
$version = $ARGV[0];
%info = cluster_info ($version, $ARGV[1]);
error "specified cluster does not exist" unless $info{'pgdata'};
......
......@@ -14,8 +14,22 @@ use PgCommon;
$cmd = (split '/', $0)[-1];
grep { $cmd eq $_ } @commands or die "pg_wrapper: invalid command name $cmd";
# Determine $version, $cluster, $db, $port
($version, $cluster, $db) = user_cluster_map();
# Check for --cluster argument and filter it out
for ($i = 0; $i <= $#ARGV; ++$i) {
if ($ARGV[$i] eq '--cluster') {
error '--cluster option needs an argument (<version>/<cluster>)' if ($i >= $#ARGV);
($version, $cluster) = split ('/', $ARGV[$i+1], 2);
error 'No version specified with --cluster' unless $version;
error 'No cluster specified with --cluster' unless $cluster;
splice @ARGV, $i, 2;
last;
}
}
# Determine $version, $cluster, $db, $port from map files
($version, $cluster, $db) = user_cluster_map() unless $cluster;
if ($cluster) {
$port = (get_conf_value $version, $cluster, 'port');
}
......@@ -24,6 +38,7 @@ $ENV{'PGPORT'} = "$port" if $port;
$ENV{'PGDATABASE'} = $db if $db;
@args = (get_program_path ($cmd, $version));
error 'Invalid PostgreSQL cluster version' unless $args[0];
push @args, @ARGV;
exec @args;
......@@ -33,13 +48,25 @@ __END__
pg_wrapper - wrapper for PostgreSQL client commands
=head1 SYNOPSIS
B<psql> [B<--cluster> I<version>/I<cluster>] [...]
B<createdb> [B<--cluster> I<version>/I<cluster>] [...]
B<dropdb> [B<--cluster> I<version>/I<cluster>] [...]
=head1 DESCRIPTION
This program is run only as a link to names which correspond to PostgreSQL
programs in B</usr/lib/postgresql/>I<version>B</bin>. It finds the correct
cluster and database for the user and calls the correct version of the desired
program to connect to that cluster and database, supplying any specifed options
to that command.
programs in B</usr/lib/postgresql/>I<version>B</bin>. It determines the
configured cluster and database for the user and calls the appropriate version
of the desired program to connect to that cluster and database, supplying any
specifed options to that command.
By default, the cluster is determined from the configuration files
L<user_clusters(5)> and L<postgresqlrc(5)>. However, this can be overriden by
specifying the B<--cluster> I<version>/I<cluster> option.
=head1 FILES
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment