Commit 15d37e9d authored by Christoph Berg's avatar Christoph Berg

pg_lsclusters, postgresql-generator, get_version_clusters, cluster_info,...

pg_lsclusters, postgresql-generator, get_version_clusters, cluster_info, read_conf_file: Accept dead postgresql.conf symlinks, filesystem might not be mounted yet.
parent 74040459
......@@ -127,8 +127,6 @@ sub read_conf_file {
return "$parent_path/$path";
}
return %conf unless (-e $config_path);
if (open F, $config_path) {
while (<F>) {
if (/^\s*(?:#.*)?$/) {
......@@ -177,8 +175,6 @@ sub read_conf_file {
}
}
close F;
} else {
error "could not read $config_path: $!";
}
return %conf;
......@@ -616,13 +612,12 @@ sub cluster_info {
my %result;
$result{'configdir'} = "$confroot/$v/$c";
error "cluster_info called on non-existing cluster $v $c"
unless (-e "$result{configdir}/postgresql.conf");
$result{'configuid'} = (stat "$result{configdir}/postgresql.conf")[4];
my %postgresql_conf = read_cluster_conf_file $v, $c, 'postgresql.conf';
$result{'config'} = \%postgresql_conf;
$result{'pgdata'} = cluster_data_directory $v, $c, \%postgresql_conf;
return %result unless (keys %postgresql_conf);
$result{'port'} = $postgresql_conf{'port'} || $defaultport;
$result{'socketdir'} = get_cluster_socketdir $v, $c;
......@@ -701,7 +696,8 @@ sub get_version_clusters {
while (defined ($entry = readdir D)) {
next if $entry eq '.' || $entry eq '..';
($entry) = $entry =~ /^(.*)$/; # untaint
if (-r $vdir.$entry.'/postgresql.conf') {
my $conf = "$vdir$entry/postgresql.conf";
if (-e $conf or -l $conf) { # existing file, or dead symlink
push @clusters, $entry;
}
}
......
......@@ -8,6 +8,9 @@ postgresql-common (187) UNRELEASED; urgency=medium
fails.
* pg_createcluster: If not running as postgres or root, don't attempt to
install config and data parent directories with owner postgres.
* pg_lsclusters, postgresql-generator, get_version_clusters, cluster_info,
read_conf_file: Accept dead postgresql.conf symlinks, filesystem might not
be mounted yet.
-- Christoph Berg <myon@debian.org> Sun, 08 Oct 2017 17:15:21 +0200
......
......@@ -58,7 +58,7 @@ foreach my $v (@versions) {
$status .= ",recovery" if ($info{'recovery'});
$status .= ",$info{start}" if ($start_conf);
my $logfile = $info{logfile}; # default logfile in /var/log/postgresql
my $logfile = $info{logfile} // '<unknown>'; # default logfile in /var/log/postgresql
if (config_bool ($info{config}->{logging_collector})) {
my $path = $info{config}->{log_directory} || $pg_log;
my $file = $info{config}->{log_filename} || 'postgresql-%Y-%m-%d_%H%M%S.log';
......@@ -70,9 +70,9 @@ foreach my $v (@versions) {
$csvlog =~ s/(?:\.log)?$/.csv/;
$destination =~ s/csvlog/$csvlog/;
push @lines, [$v, $c, $info{'port'}, $status,
push @lines, [$v, $c, $info{'port'} // '<unknown>', $status,
defined $info{'owneruid'} ? (getpwuid $info{'owneruid'})[0] : '<unknown>',
$info{'pgdata'} || '<not set>', $destination];
$info{'pgdata'} || '<unknown>', $destination];
$info{version} = $v;
$info{cluster} = $c;
push @$jsoninfo, \%info;
......
......@@ -13,7 +13,9 @@ pgservice="/lib/systemd/system/postgresql@.service"
mkdir -p "$wantdir"
for conf in /etc/postgresql/*/*/postgresql.conf; do
test -e "$conf" || continue
# abort loop if glob was not expanded (but accept dead symlinks)
if ! test -e "$conf" && ! test -L "$conf"; then continue; fi
dir="${conf%/*}"
# evaluate start.conf
......
......@@ -309,8 +309,8 @@ mkdir "/etc/postgresql/$MAJORS[-1]/broken";
mkdir "/var/lib/postgresql/$MAJORS[-1]";
mkdir "/var/lib/postgresql/$MAJORS[-1]/broken";
mkdir "/var/lib/postgresql/$MAJORS[-1]/broken/base" or die "mkdir: $!";
symlink "/var/lib/postgresql/$MAJORS[-1]/broken", "/etc/postgresql/$MAJORS[-1]/broken/pgdata" or die "symlink: $!";
open F, ">/etc/postgresql/$MAJORS[-1]/broken/postgresql.conf" or die "open: $!";
print F "data_directory = '/var/lib/postgresql/$MAJORS[-1]/broken'\n";
close F;
open F, ">/var/lib/postgresql/$MAJORS[-1]/broken/PG_VERSION" or die "open: $!";
close F;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment