Commit a181d627 authored by Evgeny's avatar Evgeny

use pg_ctl status after start instead of check with wrong password

parent e15279f5
Pipeline #43538 failed with stage
in 6 minutes and 52 seconds
......@@ -25,6 +25,7 @@ use POSIX qw/setsid dup2 :sys_wait_h/;
use PgCommon;
use Fcntl qw(SEEK_SET O_RDWR O_CREAT O_EXCL);
use POSIX qw(lchown);
use IPC::Cmd 'run_forked';
my ($version, $cluster, $pg_ctl, $force);
my (@postgres_auxoptions, @pg_ctl_opts_from_cli);
......@@ -72,38 +73,6 @@ sub stop_check_pid_file {
exit 2;
}
# check if a cluster reliably connects or fails
# Arguments: <version> <cluster> <port> <socket dir>
sub cluster_port_ready {
my ($v, $c, $p, $sd) = @_;
my $psql = get_program_path 'psql', $v;
error 'cluster_port_ready: could not find psql binary' unless $psql;
my $n = 0;
my $result = 0;
# probe until we get three successful or failed connections in a row
$ENV{'PGPASSWORD'} = 'foo'; # prevent hangs if superuser cannot connect without password
my $out;
while ($n < ($result ? 10 : 3)) {
select undef, undef, undef, 0.5;
$out = `$psql -h '$sd' --port $p -Xl 2>&1 >/dev/null`;
if ($? == $result) {
$n++;
} else {
$n = 0;
}
$result = $?;
}
if ($out =~ 'FATAL:') {
print STDERR "Warning: connection to the database failed, disabling startup checks:\n$out\n";
return cluster_port_running $v, $c, $p;
}
return !$result;
}
sub start {
start_check_pid_file;
......@@ -231,9 +200,10 @@ sub start {
last if ($currlogsize > $logsize && !PgCommon::check_pidfile_running $pidfile);
}
# OK, the server runs, now wait until it stabilized
# OK, the server runs, now check status by pg_ctl
if ($success) {
$success = cluster_port_ready $version, $cluster, $info{'port'}, $info{'socketdir'};
my $result = run_forked("$pg_ctl -D $info{'pgdata'} status");
$result->{'exit_code'} and $success = 0;
}
if (!$success) {
......
......@@ -6,7 +6,7 @@ require File::Temp;
use lib 't';
use TestLib;
use Test::More tests => 147;
use Test::More tests => 143;
use PgCommon;
my $version = $MAJORS[-1];
......@@ -195,17 +195,6 @@ if ($version < '8.4') {
"Cluster is not running.\n", 'stopping cluster';
}
# test check for pg_hba.conf with removed passwordless local superuser access
open F, ">/etc/postgresql/$version/main/pg_hba.conf" or die "could not create pg_hba.conf: $!";
print F "local all all md5\n";
close F;
chmod 0644, "/etc/postgresql/$version/main/pg_hba.conf" or die "chmod: $!";
like_program_out 'postgres', "pg_ctlcluster $version main start", 0,
qr/WARNING.*connection to the database failed.*postgres/is,
'pg_ctlcluster start warns about absence of passwordless superuser connection';
is_program_out 'postgres', "pg_ctlcluster $version main stop", 0, '', 'stopping cluster';
# restore pg_hba.conf
unlink "/etc/postgresql/$version/main/pg_hba.conf";
rename "/etc/postgresql/$version/main/pg_hba.conf.orig",
......
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