Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce the parameter datadir in the RA #35

Merged
merged 1 commit into from Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -58,6 +58,9 @@ can set:
* `bindir`: location of the PostgreSQL binaries (default: `/usr/bin`)
* `pgdata`: location of the PGDATA of your instance (default:
`/var/lib/pgsql/data`)
* `datadir`: Path to the directory set in `data_directory` from your postgresql.conf file
(same default than PostgreSQL itself: the `pgdata` parameter value). Unless you have a
special PostgreSQL setup and you understand this parameter, __ignore it__.
* `pghost`: the socket directory or IP address to use to connect to the
local instance (default: `/tmp`)
* `pgport`: the port to connect to the local instance (default: `5432`)
Expand Down
41 changes: 29 additions & 12 deletions script/pgsqlms
Expand Up @@ -49,6 +49,7 @@ my $start_opts_default = "";
my $system_user = $ENV{'OCF_RESKEY_system_user'} || $system_user_default;
my $bindir = $ENV{'OCF_RESKEY_bindir'} || $bindir_default;
my $pgdata = $ENV{'OCF_RESKEY_pgdata'} || $pgdata_default;
my $datadir = $ENV{'OCF_RESKEY_datadir'} || $pgdata;
my $pghost = $ENV{'OCF_RESKEY_pghost'} || $pghost_default;
my $pgport = $ENV{'OCF_RESKEY_pgport'} || $pgport_default;
my $start_opts = $ENV{'OCF_RESKEY_start_opts'} || $start_opts_default;
Expand Down Expand Up @@ -395,14 +396,14 @@ sub _pg_ctl_start {
# WARNING: the status is NOT updated in case of crash.
#
sub _controldata_state {
my $status = qx{$PGCTRLDATA "$pgdata" 2>/dev/null};
my $status = qx{$PGCTRLDATA "$datadir" 2>/dev/null};

$status =~ /^Database cluster state:\s+(.*?)\s*$/m;

unless ( defined $1 ) {
ocf_log( 'crit', sprintf
'_controldata_state: could not read state from controldata file for "%s"',
$pgdata );
$datadir );
exit $OCF_ERR_CONFIGURED;
}

Expand All @@ -419,7 +420,7 @@ sub _create_recovery_conf {
my $fh;
my (undef, undef, $uid, $gid) = getpwnam($system_user);
my $recovery_conf = '';
my $recovery_file = "$pgdata/recovery.conf";
my $recovery_file = "$datadir/recovery.conf";

ocf_log( 'debug', sprintf
'_create_recovery_conf: get replication configuration from the template file "%s"',
Expand Down Expand Up @@ -821,7 +822,7 @@ sub _confirm_stopped {
'_confirm_stopped: no postmaster process found for instance "%s"',
$OCF_RESOURCE_INSTANCE );

if ( -f "$pgdata/backup_label" ) {
if ( -f "$datadir/backup_label" ) {
# We are probably on a freshly built secondary that was not started yet.
ocf_log( 'debug', sprintf
'_confirm_stopped: backup_label file exists: probably on a never started secondary',
Expand Down Expand Up @@ -904,6 +905,16 @@ sub ocf_meta_data {
<content type="string" default="$pgdata_default" />
</parameter>

<parameter name="datadir" unique="1" required="0">
<longdesc lang="en">
Path to the directory set in data_directory from your postgresql.conf file (same default
than PostgreSQL itself: the pgdata parameter value). Unless you have a special
PostgreSQL setup and you understand this parameter, ignore it.
</longdesc>
<shortdesc lang="en">Path to the directory set in data_directory from your postgresql.conf file.</shortdesc>
<content type="string" default="PGDATA" />
</parameter>

<parameter name="pghost" unique="0" required="0">
<longdesc lang="en">
Host IP address or unix socket folder the instance is listening on.
Expand Down Expand Up @@ -996,10 +1007,16 @@ sub pgsql_validate_all {
exit $OCF_ERR_CONFIGURED;
}

# check datadir
if ( ! -d $datadir ) {
ocf_log( 'err', sprintf 'data_directory "%s" does not exists', $datadir );
exit $OCF_ERR_CONFIGURED;
}

# check PG_VERSION
if ( ! -s "$pgdata/PG_VERSION" ) {
if ( ! -s "$datadir/PG_VERSION" ) {
ocf_log( 'crit', sprintf 'PG_VERSION does not exists in "%s"',
$pgdata );
$datadir );
exit $OCF_ERR_CONFIGURED;
}

Expand Down Expand Up @@ -1051,9 +1068,9 @@ sub pgsql_validate_all {
}

# require 9.3 minimum
unless ( open( $fh, '<', "$pgdata/PG_VERSION" ) ) {
unless ( open( $fh, '<', "$datadir/PG_VERSION" ) ) {
ocf_log( 'crit', sprintf'Could not open file "%s"',
"$pgdata/PG_VERSION" );
"$datadir/PG_VERSION" );
exit $OCF_ERR_CONFIGURED;
}
read( $fh, $PGVERSION, 64 );
Expand All @@ -1072,19 +1089,19 @@ sub pgsql_validate_all {
}

# require wal_level >= hot_standby
my $status = qx{$PGCTRLDATA "$pgdata" 2>/dev/null};
my $status = qx{$PGCTRLDATA "$datadir" 2>/dev/null};
# NOTE: pg_controldata output changed with PostgreSQL 9.5, so we need to
# account for both syntaxes
$status =~ /^(?:Current )?wal_level setting:\s+(.*?)\s*$/m;
unless ( defined $1 ) {
ocf_log( 'crit', sprintf
'Could not read current wal_level setting "%s"', $pgdata );
'Could not read current wal_level setting "%s"', $datadir );
exit $OCF_ERR_INSTALLED;
}

unless ( $1 eq 'hot_standby' or $1 eq 'logical' ) {
ocf_log( 'crit', sprintf 'wal_level must be "hot_standby" or "logical"',
$pgdata );
$datadir );
exit $OCF_ERR_CONFIGURED;
}

Expand Down Expand Up @@ -1176,7 +1193,7 @@ sub pgsql_start {
sub pgsql_stop {
my $rc;
my $state;
my $pidfile = "$pgdata/postmaster.pid";
my $pidfile = "$datadir/postmaster.pid";

# Instance must be running as secondary or primary or being stopped.
# Anything else is an error.
Expand Down