diff --git a/specs/postgresql-10/SOURCES/postgresql.init b/specs/postgresql-10/SOURCES/postgresql.init index 3419011fd..dea4cb9de 100644 --- a/specs/postgresql-10/SOURCES/postgresql.init +++ b/specs/postgresql-10/SOURCES/postgresql.init @@ -43,17 +43,14 @@ pg_engine="${PG_ENGINE:-/usr/${short_name}-${MAJOR_VERSION}/bin}" pg_postmaster="${PG_POSTMASTER:-${pg_engine}/postmaster}" pg_data="${PG_DATA:-/var/lib/${short_name}/${MAJOR_VERSION}/data}" pg_log="${PG_LOG:-/var/lib/${short_name}/${MAJOR_VERSION}/pgstartup.log}" -pg_uplog="${PG_UPLOG:-/var/lib/${short_name}/${MAJOR_VERSION}/pgupgrade.log}" pg_socket_dir="${PG_SOCKET_DIR:-/var/run/postgresql}" timeout="${TIMEOUT:-300}" disable_auto_numa="${DISABLE_AUTO_NUMA}" pg_ctl="$pg_engine/pg_ctl" -pg_upgrade="$pg_engine/pg_upgrade" pg_initdb="$pg_engine/initdb" export pg_data -export pg_port kv[user]="$USER_NAME" kv[search_pattern]="$pg_engine" @@ -63,9 +60,7 @@ kv[oom_adj]="$OOM_DISABLE" ############################################################################### kv.addCommand "initdb" "Init new database" "initdb" -kv.addCommand "upgrade" "Upgrade data" "upgrade" kv.addCommand "reload" "Reload configuration files" "reload" -kv.addCommand "promote" "Trigger failover" "promote" kv.addHandler "start" "startServiceHandler" kv.addHandler "start" "preStartServiceHandler" "pre" @@ -73,7 +68,6 @@ kv.addHandler "stop" "stopServiceHandler" kv.addCommandArgs "stop" "force" kv.addCommandArgs "initdb" "locale" -kv.addCommandArgs "upgrade" "current-version" "prev-version" kv.disableOutputRedirect "start" "pre" @@ -148,66 +142,8 @@ initdb() { return $status } -upgrade() { - kv[log]="$pg_uplog" - - local cur_version="${1-$MAJOR_VERSION}" - local prev_version="${2-$PREV_VERSION}" - local cur_init="postgresql-$cur_version" - local prev_init="postgresql-$prev_version" - - if [[ ! -f "$INIT_DIR/$cur_init" ]] ; then - kv.error "Couldn't find init script $INIT_DIR/$cur_init" $ACTION_ERROR - fi - - if [[ ! -f "$INIT_DIR/$prev_init" ]] ; then - kv.error "Couldn't find init script $INIT_DIR/$prev_init" - kv.error "Please install ${PROG_NAME}${prev_version/./}-server RPM first." - return $ACTION_ERROR - fi - - if [[ ! -x "$pg_engine/pg_upgrade" ]] ; then - kv.show "Please install the ${PROG_NAME}${PKG_VERSION}-contrib RPM for pg_upgrade command." - return $ACTION_ERROR - fi - - local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version") - local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version") - local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version") - local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version") - - /sbin/service "${PROG_NAME}${PKG_VERSION}" initdb - - if [[ $? -ne 0 ]] ; then - kv.error "Initialization failed!" $ACTION_ERROR - fi - - kv.run "$pg_upgrade" -b "/usr/${SHORT_NAME}-${prev_version}/bin/" -B $pg_engine/ -d "$old_data" -D "$new_data" -p "$old_port" -P "$new_port" -c - - if [[ $? -ne 0 ]] ; then - kv.error "Cluster check failed. Please see the output above." $ACTION_ERROR - fi - - kv.show "Clusters checked successfully, proceeding with upgrade from $prev_version to $cur_version..." - - /sbin/service "$prev_init" stop - - rm -f "$pg_uplog" &> /dev/null - touch "$pg_uplog" || return 1 - kv.chown "$USER_NAME:$GROUP_NAME" "$pg_uplog" - kv.chmod go-rwx "$PGUPLOG" - - kv.restoreSEContext "$pg_uplog" - - kv.show "Performing upgrade..." - - kv.run "$pg_upgrade" -b "/usr/${SHORT_NAME}-${prev_version}/bin/" -B "$pg_engine/" -d "$old_data" -D "$new_data" -p "$old_port" -P "$new_port" - - kv.show "Upgrade complete" $GREEN -} - reload() { - kv.showProcessMessage "Reloading configs" + kv.showProcessMessage "Reloading configuration" kv.run "$pg_ctl" reload -D "$pg_data" -s @@ -218,18 +154,6 @@ reload() { return $status } -promote() { - kv.showProcessMessage "Promoting" - - kv.run "$pg_ctl" promote -D "$pg_data" -s - - local status=$? - - kv.showStatusMessage "$status" - - return $status -} - ############################################################################### initNewDB() { diff --git a/specs/postgresql-11/SOURCES/postgresql.init b/specs/postgresql-11/SOURCES/postgresql.init index 3419011fd..dea4cb9de 100644 --- a/specs/postgresql-11/SOURCES/postgresql.init +++ b/specs/postgresql-11/SOURCES/postgresql.init @@ -43,17 +43,14 @@ pg_engine="${PG_ENGINE:-/usr/${short_name}-${MAJOR_VERSION}/bin}" pg_postmaster="${PG_POSTMASTER:-${pg_engine}/postmaster}" pg_data="${PG_DATA:-/var/lib/${short_name}/${MAJOR_VERSION}/data}" pg_log="${PG_LOG:-/var/lib/${short_name}/${MAJOR_VERSION}/pgstartup.log}" -pg_uplog="${PG_UPLOG:-/var/lib/${short_name}/${MAJOR_VERSION}/pgupgrade.log}" pg_socket_dir="${PG_SOCKET_DIR:-/var/run/postgresql}" timeout="${TIMEOUT:-300}" disable_auto_numa="${DISABLE_AUTO_NUMA}" pg_ctl="$pg_engine/pg_ctl" -pg_upgrade="$pg_engine/pg_upgrade" pg_initdb="$pg_engine/initdb" export pg_data -export pg_port kv[user]="$USER_NAME" kv[search_pattern]="$pg_engine" @@ -63,9 +60,7 @@ kv[oom_adj]="$OOM_DISABLE" ############################################################################### kv.addCommand "initdb" "Init new database" "initdb" -kv.addCommand "upgrade" "Upgrade data" "upgrade" kv.addCommand "reload" "Reload configuration files" "reload" -kv.addCommand "promote" "Trigger failover" "promote" kv.addHandler "start" "startServiceHandler" kv.addHandler "start" "preStartServiceHandler" "pre" @@ -73,7 +68,6 @@ kv.addHandler "stop" "stopServiceHandler" kv.addCommandArgs "stop" "force" kv.addCommandArgs "initdb" "locale" -kv.addCommandArgs "upgrade" "current-version" "prev-version" kv.disableOutputRedirect "start" "pre" @@ -148,66 +142,8 @@ initdb() { return $status } -upgrade() { - kv[log]="$pg_uplog" - - local cur_version="${1-$MAJOR_VERSION}" - local prev_version="${2-$PREV_VERSION}" - local cur_init="postgresql-$cur_version" - local prev_init="postgresql-$prev_version" - - if [[ ! -f "$INIT_DIR/$cur_init" ]] ; then - kv.error "Couldn't find init script $INIT_DIR/$cur_init" $ACTION_ERROR - fi - - if [[ ! -f "$INIT_DIR/$prev_init" ]] ; then - kv.error "Couldn't find init script $INIT_DIR/$prev_init" - kv.error "Please install ${PROG_NAME}${prev_version/./}-server RPM first." - return $ACTION_ERROR - fi - - if [[ ! -x "$pg_engine/pg_upgrade" ]] ; then - kv.show "Please install the ${PROG_NAME}${PKG_VERSION}-contrib RPM for pg_upgrade command." - return $ACTION_ERROR - fi - - local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version") - local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version") - local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version") - local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version") - - /sbin/service "${PROG_NAME}${PKG_VERSION}" initdb - - if [[ $? -ne 0 ]] ; then - kv.error "Initialization failed!" $ACTION_ERROR - fi - - kv.run "$pg_upgrade" -b "/usr/${SHORT_NAME}-${prev_version}/bin/" -B $pg_engine/ -d "$old_data" -D "$new_data" -p "$old_port" -P "$new_port" -c - - if [[ $? -ne 0 ]] ; then - kv.error "Cluster check failed. Please see the output above." $ACTION_ERROR - fi - - kv.show "Clusters checked successfully, proceeding with upgrade from $prev_version to $cur_version..." - - /sbin/service "$prev_init" stop - - rm -f "$pg_uplog" &> /dev/null - touch "$pg_uplog" || return 1 - kv.chown "$USER_NAME:$GROUP_NAME" "$pg_uplog" - kv.chmod go-rwx "$PGUPLOG" - - kv.restoreSEContext "$pg_uplog" - - kv.show "Performing upgrade..." - - kv.run "$pg_upgrade" -b "/usr/${SHORT_NAME}-${prev_version}/bin/" -B "$pg_engine/" -d "$old_data" -D "$new_data" -p "$old_port" -P "$new_port" - - kv.show "Upgrade complete" $GREEN -} - reload() { - kv.showProcessMessage "Reloading configs" + kv.showProcessMessage "Reloading configuration" kv.run "$pg_ctl" reload -D "$pg_data" -s @@ -218,18 +154,6 @@ reload() { return $status } -promote() { - kv.showProcessMessage "Promoting" - - kv.run "$pg_ctl" promote -D "$pg_data" -s - - local status=$? - - kv.showStatusMessage "$status" - - return $status -} - ############################################################################### initNewDB() { diff --git a/specs/postgresql-12/SOURCES/postgresql.init b/specs/postgresql-12/SOURCES/postgresql.init index 3419011fd..dea4cb9de 100644 --- a/specs/postgresql-12/SOURCES/postgresql.init +++ b/specs/postgresql-12/SOURCES/postgresql.init @@ -43,17 +43,14 @@ pg_engine="${PG_ENGINE:-/usr/${short_name}-${MAJOR_VERSION}/bin}" pg_postmaster="${PG_POSTMASTER:-${pg_engine}/postmaster}" pg_data="${PG_DATA:-/var/lib/${short_name}/${MAJOR_VERSION}/data}" pg_log="${PG_LOG:-/var/lib/${short_name}/${MAJOR_VERSION}/pgstartup.log}" -pg_uplog="${PG_UPLOG:-/var/lib/${short_name}/${MAJOR_VERSION}/pgupgrade.log}" pg_socket_dir="${PG_SOCKET_DIR:-/var/run/postgresql}" timeout="${TIMEOUT:-300}" disable_auto_numa="${DISABLE_AUTO_NUMA}" pg_ctl="$pg_engine/pg_ctl" -pg_upgrade="$pg_engine/pg_upgrade" pg_initdb="$pg_engine/initdb" export pg_data -export pg_port kv[user]="$USER_NAME" kv[search_pattern]="$pg_engine" @@ -63,9 +60,7 @@ kv[oom_adj]="$OOM_DISABLE" ############################################################################### kv.addCommand "initdb" "Init new database" "initdb" -kv.addCommand "upgrade" "Upgrade data" "upgrade" kv.addCommand "reload" "Reload configuration files" "reload" -kv.addCommand "promote" "Trigger failover" "promote" kv.addHandler "start" "startServiceHandler" kv.addHandler "start" "preStartServiceHandler" "pre" @@ -73,7 +68,6 @@ kv.addHandler "stop" "stopServiceHandler" kv.addCommandArgs "stop" "force" kv.addCommandArgs "initdb" "locale" -kv.addCommandArgs "upgrade" "current-version" "prev-version" kv.disableOutputRedirect "start" "pre" @@ -148,66 +142,8 @@ initdb() { return $status } -upgrade() { - kv[log]="$pg_uplog" - - local cur_version="${1-$MAJOR_VERSION}" - local prev_version="${2-$PREV_VERSION}" - local cur_init="postgresql-$cur_version" - local prev_init="postgresql-$prev_version" - - if [[ ! -f "$INIT_DIR/$cur_init" ]] ; then - kv.error "Couldn't find init script $INIT_DIR/$cur_init" $ACTION_ERROR - fi - - if [[ ! -f "$INIT_DIR/$prev_init" ]] ; then - kv.error "Couldn't find init script $INIT_DIR/$prev_init" - kv.error "Please install ${PROG_NAME}${prev_version/./}-server RPM first." - return $ACTION_ERROR - fi - - if [[ ! -x "$pg_engine/pg_upgrade" ]] ; then - kv.show "Please install the ${PROG_NAME}${PKG_VERSION}-contrib RPM for pg_upgrade command." - return $ACTION_ERROR - fi - - local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version") - local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version") - local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version") - local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version") - - /sbin/service "${PROG_NAME}${PKG_VERSION}" initdb - - if [[ $? -ne 0 ]] ; then - kv.error "Initialization failed!" $ACTION_ERROR - fi - - kv.run "$pg_upgrade" -b "/usr/${SHORT_NAME}-${prev_version}/bin/" -B $pg_engine/ -d "$old_data" -D "$new_data" -p "$old_port" -P "$new_port" -c - - if [[ $? -ne 0 ]] ; then - kv.error "Cluster check failed. Please see the output above." $ACTION_ERROR - fi - - kv.show "Clusters checked successfully, proceeding with upgrade from $prev_version to $cur_version..." - - /sbin/service "$prev_init" stop - - rm -f "$pg_uplog" &> /dev/null - touch "$pg_uplog" || return 1 - kv.chown "$USER_NAME:$GROUP_NAME" "$pg_uplog" - kv.chmod go-rwx "$PGUPLOG" - - kv.restoreSEContext "$pg_uplog" - - kv.show "Performing upgrade..." - - kv.run "$pg_upgrade" -b "/usr/${SHORT_NAME}-${prev_version}/bin/" -B "$pg_engine/" -d "$old_data" -D "$new_data" -p "$old_port" -P "$new_port" - - kv.show "Upgrade complete" $GREEN -} - reload() { - kv.showProcessMessage "Reloading configs" + kv.showProcessMessage "Reloading configuration" kv.run "$pg_ctl" reload -D "$pg_data" -s @@ -218,18 +154,6 @@ reload() { return $status } -promote() { - kv.showProcessMessage "Promoting" - - kv.run "$pg_ctl" promote -D "$pg_data" -s - - local status=$? - - kv.showStatusMessage "$status" - - return $status -} - ############################################################################### initNewDB() { diff --git a/specs/postgresql-13/SOURCES/postgresql.init b/specs/postgresql-13/SOURCES/postgresql.init index 3419011fd..dea4cb9de 100644 --- a/specs/postgresql-13/SOURCES/postgresql.init +++ b/specs/postgresql-13/SOURCES/postgresql.init @@ -43,17 +43,14 @@ pg_engine="${PG_ENGINE:-/usr/${short_name}-${MAJOR_VERSION}/bin}" pg_postmaster="${PG_POSTMASTER:-${pg_engine}/postmaster}" pg_data="${PG_DATA:-/var/lib/${short_name}/${MAJOR_VERSION}/data}" pg_log="${PG_LOG:-/var/lib/${short_name}/${MAJOR_VERSION}/pgstartup.log}" -pg_uplog="${PG_UPLOG:-/var/lib/${short_name}/${MAJOR_VERSION}/pgupgrade.log}" pg_socket_dir="${PG_SOCKET_DIR:-/var/run/postgresql}" timeout="${TIMEOUT:-300}" disable_auto_numa="${DISABLE_AUTO_NUMA}" pg_ctl="$pg_engine/pg_ctl" -pg_upgrade="$pg_engine/pg_upgrade" pg_initdb="$pg_engine/initdb" export pg_data -export pg_port kv[user]="$USER_NAME" kv[search_pattern]="$pg_engine" @@ -63,9 +60,7 @@ kv[oom_adj]="$OOM_DISABLE" ############################################################################### kv.addCommand "initdb" "Init new database" "initdb" -kv.addCommand "upgrade" "Upgrade data" "upgrade" kv.addCommand "reload" "Reload configuration files" "reload" -kv.addCommand "promote" "Trigger failover" "promote" kv.addHandler "start" "startServiceHandler" kv.addHandler "start" "preStartServiceHandler" "pre" @@ -73,7 +68,6 @@ kv.addHandler "stop" "stopServiceHandler" kv.addCommandArgs "stop" "force" kv.addCommandArgs "initdb" "locale" -kv.addCommandArgs "upgrade" "current-version" "prev-version" kv.disableOutputRedirect "start" "pre" @@ -148,66 +142,8 @@ initdb() { return $status } -upgrade() { - kv[log]="$pg_uplog" - - local cur_version="${1-$MAJOR_VERSION}" - local prev_version="${2-$PREV_VERSION}" - local cur_init="postgresql-$cur_version" - local prev_init="postgresql-$prev_version" - - if [[ ! -f "$INIT_DIR/$cur_init" ]] ; then - kv.error "Couldn't find init script $INIT_DIR/$cur_init" $ACTION_ERROR - fi - - if [[ ! -f "$INIT_DIR/$prev_init" ]] ; then - kv.error "Couldn't find init script $INIT_DIR/$prev_init" - kv.error "Please install ${PROG_NAME}${prev_version/./}-server RPM first." - return $ACTION_ERROR - fi - - if [[ ! -x "$pg_engine/pg_upgrade" ]] ; then - kv.show "Please install the ${PROG_NAME}${PKG_VERSION}-contrib RPM for pg_upgrade command." - return $ACTION_ERROR - fi - - local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version") - local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version") - local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version") - local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version") - - /sbin/service "${PROG_NAME}${PKG_VERSION}" initdb - - if [[ $? -ne 0 ]] ; then - kv.error "Initialization failed!" $ACTION_ERROR - fi - - kv.run "$pg_upgrade" -b "/usr/${SHORT_NAME}-${prev_version}/bin/" -B $pg_engine/ -d "$old_data" -D "$new_data" -p "$old_port" -P "$new_port" -c - - if [[ $? -ne 0 ]] ; then - kv.error "Cluster check failed. Please see the output above." $ACTION_ERROR - fi - - kv.show "Clusters checked successfully, proceeding with upgrade from $prev_version to $cur_version..." - - /sbin/service "$prev_init" stop - - rm -f "$pg_uplog" &> /dev/null - touch "$pg_uplog" || return 1 - kv.chown "$USER_NAME:$GROUP_NAME" "$pg_uplog" - kv.chmod go-rwx "$PGUPLOG" - - kv.restoreSEContext "$pg_uplog" - - kv.show "Performing upgrade..." - - kv.run "$pg_upgrade" -b "/usr/${SHORT_NAME}-${prev_version}/bin/" -B "$pg_engine/" -d "$old_data" -D "$new_data" -p "$old_port" -P "$new_port" - - kv.show "Upgrade complete" $GREEN -} - reload() { - kv.showProcessMessage "Reloading configs" + kv.showProcessMessage "Reloading configuration" kv.run "$pg_ctl" reload -D "$pg_data" -s @@ -218,18 +154,6 @@ reload() { return $status } -promote() { - kv.showProcessMessage "Promoting" - - kv.run "$pg_ctl" promote -D "$pg_data" -s - - local status=$? - - kv.showStatusMessage "$status" - - return $status -} - ############################################################################### initNewDB() { diff --git a/specs/postgresql-14/SOURCES/postgresql.init b/specs/postgresql-14/SOURCES/postgresql.init index 3419011fd..dea4cb9de 100644 --- a/specs/postgresql-14/SOURCES/postgresql.init +++ b/specs/postgresql-14/SOURCES/postgresql.init @@ -43,17 +43,14 @@ pg_engine="${PG_ENGINE:-/usr/${short_name}-${MAJOR_VERSION}/bin}" pg_postmaster="${PG_POSTMASTER:-${pg_engine}/postmaster}" pg_data="${PG_DATA:-/var/lib/${short_name}/${MAJOR_VERSION}/data}" pg_log="${PG_LOG:-/var/lib/${short_name}/${MAJOR_VERSION}/pgstartup.log}" -pg_uplog="${PG_UPLOG:-/var/lib/${short_name}/${MAJOR_VERSION}/pgupgrade.log}" pg_socket_dir="${PG_SOCKET_DIR:-/var/run/postgresql}" timeout="${TIMEOUT:-300}" disable_auto_numa="${DISABLE_AUTO_NUMA}" pg_ctl="$pg_engine/pg_ctl" -pg_upgrade="$pg_engine/pg_upgrade" pg_initdb="$pg_engine/initdb" export pg_data -export pg_port kv[user]="$USER_NAME" kv[search_pattern]="$pg_engine" @@ -63,9 +60,7 @@ kv[oom_adj]="$OOM_DISABLE" ############################################################################### kv.addCommand "initdb" "Init new database" "initdb" -kv.addCommand "upgrade" "Upgrade data" "upgrade" kv.addCommand "reload" "Reload configuration files" "reload" -kv.addCommand "promote" "Trigger failover" "promote" kv.addHandler "start" "startServiceHandler" kv.addHandler "start" "preStartServiceHandler" "pre" @@ -73,7 +68,6 @@ kv.addHandler "stop" "stopServiceHandler" kv.addCommandArgs "stop" "force" kv.addCommandArgs "initdb" "locale" -kv.addCommandArgs "upgrade" "current-version" "prev-version" kv.disableOutputRedirect "start" "pre" @@ -148,66 +142,8 @@ initdb() { return $status } -upgrade() { - kv[log]="$pg_uplog" - - local cur_version="${1-$MAJOR_VERSION}" - local prev_version="${2-$PREV_VERSION}" - local cur_init="postgresql-$cur_version" - local prev_init="postgresql-$prev_version" - - if [[ ! -f "$INIT_DIR/$cur_init" ]] ; then - kv.error "Couldn't find init script $INIT_DIR/$cur_init" $ACTION_ERROR - fi - - if [[ ! -f "$INIT_DIR/$prev_init" ]] ; then - kv.error "Couldn't find init script $INIT_DIR/$prev_init" - kv.error "Please install ${PROG_NAME}${prev_version/./}-server RPM first." - return $ACTION_ERROR - fi - - if [[ ! -x "$pg_engine/pg_upgrade" ]] ; then - kv.show "Please install the ${PROG_NAME}${PKG_VERSION}-contrib RPM for pg_upgrade command." - return $ACTION_ERROR - fi - - local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version") - local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version") - local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version") - local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version") - - /sbin/service "${PROG_NAME}${PKG_VERSION}" initdb - - if [[ $? -ne 0 ]] ; then - kv.error "Initialization failed!" $ACTION_ERROR - fi - - kv.run "$pg_upgrade" -b "/usr/${SHORT_NAME}-${prev_version}/bin/" -B $pg_engine/ -d "$old_data" -D "$new_data" -p "$old_port" -P "$new_port" -c - - if [[ $? -ne 0 ]] ; then - kv.error "Cluster check failed. Please see the output above." $ACTION_ERROR - fi - - kv.show "Clusters checked successfully, proceeding with upgrade from $prev_version to $cur_version..." - - /sbin/service "$prev_init" stop - - rm -f "$pg_uplog" &> /dev/null - touch "$pg_uplog" || return 1 - kv.chown "$USER_NAME:$GROUP_NAME" "$pg_uplog" - kv.chmod go-rwx "$PGUPLOG" - - kv.restoreSEContext "$pg_uplog" - - kv.show "Performing upgrade..." - - kv.run "$pg_upgrade" -b "/usr/${SHORT_NAME}-${prev_version}/bin/" -B "$pg_engine/" -d "$old_data" -D "$new_data" -p "$old_port" -P "$new_port" - - kv.show "Upgrade complete" $GREEN -} - reload() { - kv.showProcessMessage "Reloading configs" + kv.showProcessMessage "Reloading configuration" kv.run "$pg_ctl" reload -D "$pg_data" -s @@ -218,18 +154,6 @@ reload() { return $status } -promote() { - kv.showProcessMessage "Promoting" - - kv.run "$pg_ctl" promote -D "$pg_data" -s - - local status=$? - - kv.showStatusMessage "$status" - - return $status -} - ############################################################################### initNewDB() { diff --git a/specs/postgresql-15/SOURCES/postgresql.init b/specs/postgresql-15/SOURCES/postgresql.init index 3419011fd..dea4cb9de 100644 --- a/specs/postgresql-15/SOURCES/postgresql.init +++ b/specs/postgresql-15/SOURCES/postgresql.init @@ -43,17 +43,14 @@ pg_engine="${PG_ENGINE:-/usr/${short_name}-${MAJOR_VERSION}/bin}" pg_postmaster="${PG_POSTMASTER:-${pg_engine}/postmaster}" pg_data="${PG_DATA:-/var/lib/${short_name}/${MAJOR_VERSION}/data}" pg_log="${PG_LOG:-/var/lib/${short_name}/${MAJOR_VERSION}/pgstartup.log}" -pg_uplog="${PG_UPLOG:-/var/lib/${short_name}/${MAJOR_VERSION}/pgupgrade.log}" pg_socket_dir="${PG_SOCKET_DIR:-/var/run/postgresql}" timeout="${TIMEOUT:-300}" disable_auto_numa="${DISABLE_AUTO_NUMA}" pg_ctl="$pg_engine/pg_ctl" -pg_upgrade="$pg_engine/pg_upgrade" pg_initdb="$pg_engine/initdb" export pg_data -export pg_port kv[user]="$USER_NAME" kv[search_pattern]="$pg_engine" @@ -63,9 +60,7 @@ kv[oom_adj]="$OOM_DISABLE" ############################################################################### kv.addCommand "initdb" "Init new database" "initdb" -kv.addCommand "upgrade" "Upgrade data" "upgrade" kv.addCommand "reload" "Reload configuration files" "reload" -kv.addCommand "promote" "Trigger failover" "promote" kv.addHandler "start" "startServiceHandler" kv.addHandler "start" "preStartServiceHandler" "pre" @@ -73,7 +68,6 @@ kv.addHandler "stop" "stopServiceHandler" kv.addCommandArgs "stop" "force" kv.addCommandArgs "initdb" "locale" -kv.addCommandArgs "upgrade" "current-version" "prev-version" kv.disableOutputRedirect "start" "pre" @@ -148,66 +142,8 @@ initdb() { return $status } -upgrade() { - kv[log]="$pg_uplog" - - local cur_version="${1-$MAJOR_VERSION}" - local prev_version="${2-$PREV_VERSION}" - local cur_init="postgresql-$cur_version" - local prev_init="postgresql-$prev_version" - - if [[ ! -f "$INIT_DIR/$cur_init" ]] ; then - kv.error "Couldn't find init script $INIT_DIR/$cur_init" $ACTION_ERROR - fi - - if [[ ! -f "$INIT_DIR/$prev_init" ]] ; then - kv.error "Couldn't find init script $INIT_DIR/$prev_init" - kv.error "Please install ${PROG_NAME}${prev_version/./}-server RPM first." - return $ACTION_ERROR - fi - - if [[ ! -x "$pg_engine/pg_upgrade" ]] ; then - kv.show "Please install the ${PROG_NAME}${PKG_VERSION}-contrib RPM for pg_upgrade command." - return $ACTION_ERROR - fi - - local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version") - local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version") - local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version") - local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version") - - /sbin/service "${PROG_NAME}${PKG_VERSION}" initdb - - if [[ $? -ne 0 ]] ; then - kv.error "Initialization failed!" $ACTION_ERROR - fi - - kv.run "$pg_upgrade" -b "/usr/${SHORT_NAME}-${prev_version}/bin/" -B $pg_engine/ -d "$old_data" -D "$new_data" -p "$old_port" -P "$new_port" -c - - if [[ $? -ne 0 ]] ; then - kv.error "Cluster check failed. Please see the output above." $ACTION_ERROR - fi - - kv.show "Clusters checked successfully, proceeding with upgrade from $prev_version to $cur_version..." - - /sbin/service "$prev_init" stop - - rm -f "$pg_uplog" &> /dev/null - touch "$pg_uplog" || return 1 - kv.chown "$USER_NAME:$GROUP_NAME" "$pg_uplog" - kv.chmod go-rwx "$PGUPLOG" - - kv.restoreSEContext "$pg_uplog" - - kv.show "Performing upgrade..." - - kv.run "$pg_upgrade" -b "/usr/${SHORT_NAME}-${prev_version}/bin/" -B "$pg_engine/" -d "$old_data" -D "$new_data" -p "$old_port" -P "$new_port" - - kv.show "Upgrade complete" $GREEN -} - reload() { - kv.showProcessMessage "Reloading configs" + kv.showProcessMessage "Reloading configuration" kv.run "$pg_ctl" reload -D "$pg_data" -s @@ -218,18 +154,6 @@ reload() { return $status } -promote() { - kv.showProcessMessage "Promoting" - - kv.run "$pg_ctl" promote -D "$pg_data" -s - - local status=$? - - kv.showStatusMessage "$status" - - return $status -} - ############################################################################### initNewDB() { diff --git a/specs/postgresql-16/SOURCES/postgresql.init b/specs/postgresql-16/SOURCES/postgresql.init index 0d9d6cf4e..d939bf4b5 100644 --- a/specs/postgresql-16/SOURCES/postgresql.init +++ b/specs/postgresql-16/SOURCES/postgresql.init @@ -43,17 +43,14 @@ pg_engine="${PG_ENGINE:-/usr/${short_name}-${MAJOR_VERSION}/bin}" pg_postgres="${PG_POSTGRES:-${pg_engine}/postgres}" pg_data="${PG_DATA:-/var/lib/${short_name}/${MAJOR_VERSION}/data}" pg_log="${PG_LOG:-/var/lib/${short_name}/${MAJOR_VERSION}/pgstartup.log}" -pg_uplog="${PG_UPLOG:-/var/lib/${short_name}/${MAJOR_VERSION}/pgupgrade.log}" pg_socket_dir="${PG_SOCKET_DIR:-/var/run/postgresql}" timeout="${TIMEOUT:-300}" disable_auto_numa="${DISABLE_AUTO_NUMA}" pg_ctl="$pg_engine/pg_ctl" -pg_upgrade="$pg_engine/pg_upgrade" pg_initdb="$pg_engine/initdb" export pg_data -export pg_port kv[user]="$USER_NAME" kv[search_pattern]="$pg_engine" @@ -63,9 +60,7 @@ kv[oom_adj]="$OOM_DISABLE" ############################################################################### kv.addCommand "initdb" "Init new database" "initdb" -kv.addCommand "upgrade" "Upgrade data" "upgrade" kv.addCommand "reload" "Reload configuration files" "reload" -kv.addCommand "promote" "Trigger failover" "promote" kv.addHandler "start" "startServiceHandler" kv.addHandler "start" "preStartServiceHandler" "pre" @@ -73,7 +68,6 @@ kv.addHandler "stop" "stopServiceHandler" kv.addCommandArgs "stop" "force" kv.addCommandArgs "initdb" "locale" -kv.addCommandArgs "upgrade" "current-version" "prev-version" kv.disableOutputRedirect "start" "pre" @@ -148,66 +142,8 @@ initdb() { return $status } -upgrade() { - kv[log]="$pg_uplog" - - local cur_version="${1-$MAJOR_VERSION}" - local prev_version="${2-$PREV_VERSION}" - local cur_init="postgresql-$cur_version" - local prev_init="postgresql-$prev_version" - - if [[ ! -f "$INIT_DIR/$cur_init" ]] ; then - kv.error "Couldn't find init script $INIT_DIR/$cur_init" $ACTION_ERROR - fi - - if [[ ! -f "$INIT_DIR/$prev_init" ]] ; then - kv.error "Couldn't find init script $INIT_DIR/$prev_init" - kv.error "Please install ${PROG_NAME}${prev_version/./}-server RPM first." - return $ACTION_ERROR - fi - - if [[ ! -x "$pg_engine/pg_upgrade" ]] ; then - kv.show "Please install the ${PROG_NAME}${PKG_VERSION}-contrib RPM for pg_upgrade command." - return $ACTION_ERROR - fi - - local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version") - local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version") - local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version") - local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version") - - /sbin/service "${PROG_NAME}${PKG_VERSION}" initdb - - if [[ $? -ne 0 ]] ; then - kv.error "Initialization failed!" $ACTION_ERROR - fi - - kv.run "$pg_upgrade" -b "/usr/${SHORT_NAME}-${prev_version}/bin/" -B $pg_engine/ -d "$old_data" -D "$new_data" -p "$old_port" -P "$new_port" -c - - if [[ $? -ne 0 ]] ; then - kv.error "Cluster check failed. Please see the output above." $ACTION_ERROR - fi - - kv.show "Clusters checked successfully, proceeding with upgrade from $prev_version to $cur_version..." - - /sbin/service "$prev_init" stop - - rm -f "$pg_uplog" &> /dev/null - touch "$pg_uplog" || return 1 - kv.chown "$USER_NAME:$GROUP_NAME" "$pg_uplog" - kv.chmod go-rwx "$PGUPLOG" - - kv.restoreSEContext "$pg_uplog" - - kv.show "Performing upgrade..." - - kv.run "$pg_upgrade" -b "/usr/${SHORT_NAME}-${prev_version}/bin/" -B "$pg_engine/" -d "$old_data" -D "$new_data" -p "$old_port" -P "$new_port" - - kv.show "Upgrade complete" $GREEN -} - reload() { - kv.showProcessMessage "Reloading configs" + kv.showProcessMessage "Reloading configuration" kv.run "$pg_ctl" reload -D "$pg_data" -s @@ -218,18 +154,6 @@ reload() { return $status } -promote() { - kv.showProcessMessage "Promoting" - - kv.run "$pg_ctl" promote -D "$pg_data" -s - - local status=$? - - kv.showStatusMessage "$status" - - return $status -} - ############################################################################### initNewDB() { diff --git a/tests/postgresql/postgresql10.recipe b/tests/postgresql/postgresql10.recipe index 3c51d62b0..a1d9ab882 100644 --- a/tests/postgresql/postgresql10.recipe +++ b/tests/postgresql/postgresql10.recipe @@ -10,6 +10,7 @@ var version 10 var service_name postgresql-{version} var service_user postgres var service_group postgres +var sysconfig /etc/sysconfig/{service_name} var install_dir /usr/pgsql-{version} var lib_dir {install_dir}/lib var state_dir /var/lib/pgsql @@ -24,6 +25,8 @@ var python3_lib libpython{PYTHON3_VERSION}* var perl_lib libperl.* var tcl_lib libtcl8.* +var test_data_dir {WORKDIR}/db{version} + ## ENVIRONMENT ################################################################# command "-" "Check environment" @@ -49,7 +52,7 @@ command "-" "Check configuration files for external systems" exist /usr/lib/tmpfiles.d/postgresql-{version}.conf mode /usr/lib/tmpfiles.d/postgresql-{version}.conf 644 -command "-" "Check data directory" +command "-" "Check default data directory" exist {data_dir}/backups exist {data_dir}/data owner {data_dir}/data {service_user} @@ -140,26 +143,55 @@ command "-" "Check PL/PerlU" ## SERVER ###################################################################### -command "service {service_name} initdb" "Database initialization" +command "-" "Create directory for data" + mkdir {test_data_dir} + chown {test_data_dir} {service_user}:{service_group} + +command "-" "Replace default sysconfig" + backup {sysconfig} + template sysconfig.tmpl {sysconfig} + +command "service {service_name} initdb" "Database initialization with default locale" exit 0 - exist {data_dir}/data/PG_VERSION - exist {data_dir}/data/pg_hba.conf - exist {data_dir}/data/pg_ident.conf - exist {data_dir}/data/postgresql.conf - exist {data_dir}/data/pg_wal - mode {data_dir}/data/pg_hba.conf 600 - mode {data_dir}/data/pg_ident.conf 600 - mode {data_dir}/data/postgresql.conf 600 - mode {data_dir}/data/pg_wal 700 - !empty {data_dir}/data/pg_hba.conf - !empty {data_dir}/data/pg_ident.conf - !empty {data_dir}/data/postgresql.conf - owner {data_dir}/data/pg_hba.conf {service_user} - owner {data_dir}/data/pg_ident.conf {service_user} - owner {data_dir}/data/postgresql.conf {service_user} + exist {test_data_dir}/PG_VERSION + exist {test_data_dir}/pg_hba.conf + exist {test_data_dir}/pg_ident.conf + exist {test_data_dir}/postgresql.conf + exist {test_data_dir}/pg_wal + mode {test_data_dir}/pg_hba.conf 600 + mode {test_data_dir}/pg_ident.conf 600 + mode {test_data_dir}/postgresql.conf 600 + mode {test_data_dir}/pg_wal 700 + !empty {test_data_dir}/pg_hba.conf + !empty {test_data_dir}/pg_ident.conf + !empty {test_data_dir}/postgresql.conf + owner {test_data_dir}/pg_hba.conf {service_user} + owner {test_data_dir}/pg_ident.conf {service_user} + owner {test_data_dir}/postgresql.conf {service_user} + ++command "-" "Remove data" + cleanup {test_data_dir} + +command "service {service_name} initdb en_GB.UTF-8" "Database initialization with custom locale" + exit 0 + exist {test_data_dir}/PG_VERSION + exist {test_data_dir}/pg_hba.conf + exist {test_data_dir}/pg_ident.conf + exist {test_data_dir}/postgresql.conf + exist {test_data_dir}/pg_wal + mode {test_data_dir}/pg_hba.conf 600 + mode {test_data_dir}/pg_ident.conf 600 + mode {test_data_dir}/postgresql.conf 600 + mode {test_data_dir}/pg_wal 700 + !empty {test_data_dir}/pg_hba.conf + !empty {test_data_dir}/pg_ident.conf + !empty {test_data_dir}/postgresql.conf + owner {test_data_dir}/pg_hba.conf {service_user} + owner {test_data_dir}/pg_ident.conf {service_user} + owner {test_data_dir}/postgresql.conf {service_user} +command "systemctl start {service_name}" "Start PostgreSQL server" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} checksum-read {pid_file} pid_sha @@ -167,31 +199,34 @@ command "service {service_name} initdb" "Database initialization" +command "systemctl status {service_name}" "Check status of PostgreSQL server" expect "active (running)" -+command "{service_user}:{install_dir}/bin/psql -t -c 'select version();'" "Check PostgreSQL version" ++command "{service_user}:{install_dir}/bin/psql -t -c 'SELECT version();'" "Check PostgreSQL version" exit 0 output-contains "PostgreSQL {version}" ++command "{service_user}:{install_dir}/bin/psql -t -c 'SHOW LC_COLLATE;'" "Check locale" + exit 0 + output-contains "en_GB.UTF-8" + +command "systemctl restart {service_name}" "Restart PostgreSQL server" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} !checksum {pid_file} {pid_sha} +command "systemctl stop {service_name}" "Stop PostgreSQL server" - !wait-fs {data_dir}/data/postmaster.pid {wait_fs} + !wait-fs {test_data_dir}/postmaster.pid {wait_fs} !wait-connect tcp :{port} {wait_connect} !wait-service {service_name} +command "service pg{version} start" "Check start using service with shortname link" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} +command "service pg{version} stop" "Check stop using service with shortname link" - !wait-fs {data_dir}/data/postmaster.pid {wait_fs} + !wait-fs {test_data_dir}/postmaster.pid {wait_fs} !wait-connect tcp :{port} {wait_connect} !wait-service {service_name} -command:teardown "-" "Data cleanup" - cleanup {data_dir}/data - cleanup {data_dir}/backups +command:teardown "-" "Restore original sysconfig file" + backup-restore {sysconfig} diff --git a/tests/postgresql/postgresql11.recipe b/tests/postgresql/postgresql11.recipe index bcaae9e29..738dd6159 100644 --- a/tests/postgresql/postgresql11.recipe +++ b/tests/postgresql/postgresql11.recipe @@ -10,6 +10,7 @@ var version 11 var service_name postgresql-{version} var service_user postgres var service_group postgres +var sysconfig /etc/sysconfig/{service_name} var install_dir /usr/pgsql-{version} var lib_dir {install_dir}/lib var state_dir /var/lib/pgsql @@ -24,6 +25,8 @@ var python3_lib libpython{PYTHON3_VERSION}* var perl_lib libperl.* var tcl_lib libtcl8.* +var test_data_dir {WORKDIR}/db{version} + ## ENVIRONMENT ################################################################# command "-" "Check environment" @@ -49,7 +52,7 @@ command "-" "Check configuration files for external systems" exist /usr/lib/tmpfiles.d/postgresql-{version}.conf mode /usr/lib/tmpfiles.d/postgresql-{version}.conf 644 -command "-" "Check data directory" +command "-" "Check default data directory" exist {data_dir}/backups exist {data_dir}/data owner {data_dir}/data {service_user} @@ -149,26 +152,55 @@ command "-" "Check PL/PerlU" ## SERVER ###################################################################### -command "service {service_name} initdb" "Database initialization" +command "-" "Create directory for data" + mkdir {test_data_dir} + chown {test_data_dir} {service_user}:{service_group} + +command "-" "Replace default sysconfig" + backup {sysconfig} + template sysconfig.tmpl {sysconfig} + +command "service {service_name} initdb" "Database initialization with default locale" exit 0 - exist {data_dir}/data/PG_VERSION - exist {data_dir}/data/pg_hba.conf - exist {data_dir}/data/pg_ident.conf - exist {data_dir}/data/postgresql.conf - exist {data_dir}/data/pg_wal - mode {data_dir}/data/pg_hba.conf 600 - mode {data_dir}/data/pg_ident.conf 600 - mode {data_dir}/data/postgresql.conf 600 - mode {data_dir}/data/pg_wal 700 - !empty {data_dir}/data/pg_hba.conf - !empty {data_dir}/data/pg_ident.conf - !empty {data_dir}/data/postgresql.conf - owner {data_dir}/data/pg_hba.conf {service_user} - owner {data_dir}/data/pg_ident.conf {service_user} - owner {data_dir}/data/postgresql.conf {service_user} + exist {test_data_dir}/PG_VERSION + exist {test_data_dir}/pg_hba.conf + exist {test_data_dir}/pg_ident.conf + exist {test_data_dir}/postgresql.conf + exist {test_data_dir}/pg_wal + mode {test_data_dir}/pg_hba.conf 600 + mode {test_data_dir}/pg_ident.conf 600 + mode {test_data_dir}/postgresql.conf 600 + mode {test_data_dir}/pg_wal 700 + !empty {test_data_dir}/pg_hba.conf + !empty {test_data_dir}/pg_ident.conf + !empty {test_data_dir}/postgresql.conf + owner {test_data_dir}/pg_hba.conf {service_user} + owner {test_data_dir}/pg_ident.conf {service_user} + owner {test_data_dir}/postgresql.conf {service_user} + ++command "-" "Remove data" + cleanup {test_data_dir} + +command "service {service_name} initdb en_GB.UTF-8" "Database initialization with custom locale" + exit 0 + exist {test_data_dir}/PG_VERSION + exist {test_data_dir}/pg_hba.conf + exist {test_data_dir}/pg_ident.conf + exist {test_data_dir}/postgresql.conf + exist {test_data_dir}/pg_wal + mode {test_data_dir}/pg_hba.conf 600 + mode {test_data_dir}/pg_ident.conf 600 + mode {test_data_dir}/postgresql.conf 600 + mode {test_data_dir}/pg_wal 700 + !empty {test_data_dir}/pg_hba.conf + !empty {test_data_dir}/pg_ident.conf + !empty {test_data_dir}/postgresql.conf + owner {test_data_dir}/pg_hba.conf {service_user} + owner {test_data_dir}/pg_ident.conf {service_user} + owner {test_data_dir}/postgresql.conf {service_user} +command "systemctl start {service_name}" "Start PostgreSQL server" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} checksum-read {pid_file} pid_sha @@ -176,31 +208,34 @@ command "service {service_name} initdb" "Database initialization" +command "systemctl status {service_name}" "Check status of PostgreSQL server" expect "active (running)" -+command "{service_user}:{install_dir}/bin/psql -t -c 'select version();'" "Check PostgreSQL version" ++command "{service_user}:{install_dir}/bin/psql -t -c 'SELECT version();'" "Check PostgreSQL version" exit 0 output-contains "PostgreSQL {version}" ++command "{service_user}:{install_dir}/bin/psql -t -c 'SHOW LC_COLLATE;'" "Check locale" + exit 0 + output-contains "en_GB.UTF-8" + +command "systemctl restart {service_name}" "Restart PostgreSQL server" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} !checksum {pid_file} {pid_sha} +command "systemctl stop {service_name}" "Stop PostgreSQL server" - !wait-fs {data_dir}/data/postmaster.pid {wait_fs} + !wait-fs {test_data_dir}/postmaster.pid {wait_fs} !wait-connect tcp :{port} {wait_connect} !wait-service {service_name} +command "service pg{version} start" "Check start using service with shortname link" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} +command "service pg{version} stop" "Check stop using service with shortname link" - !wait-fs {data_dir}/data/postmaster.pid {wait_fs} + !wait-fs {test_data_dir}/postmaster.pid {wait_fs} !wait-connect tcp :{port} {wait_connect} !wait-service {service_name} -command:teardown "-" "Data cleanup" - cleanup {data_dir}/data - cleanup {data_dir}/backups +command:teardown "-" "Restore original sysconfig file" + backup-restore {sysconfig} diff --git a/tests/postgresql/postgresql12.recipe b/tests/postgresql/postgresql12.recipe index f980c0366..48ce1469a 100644 --- a/tests/postgresql/postgresql12.recipe +++ b/tests/postgresql/postgresql12.recipe @@ -10,6 +10,7 @@ var version 12 var service_name postgresql-{version} var service_user postgres var service_group postgres +var sysconfig /etc/sysconfig/{service_name} var install_dir /usr/pgsql-{version} var lib_dir {install_dir}/lib var state_dir /var/lib/pgsql @@ -24,6 +25,8 @@ var python3_lib libpython{PYTHON3_VERSION}* var perl_lib libperl.* var tcl_lib libtcl8.* +var test_data_dir {WORKDIR}/db{version} + ## ENVIRONMENT ################################################################# command "-" "Check environment" @@ -49,7 +52,7 @@ command "-" "Check configuration files for external systems" exist /usr/lib/tmpfiles.d/postgresql-{version}.conf mode /usr/lib/tmpfiles.d/postgresql-{version}.conf 644 -command "-" "Check data directory" +command "-" "Check default data directory" exist {data_dir}/backups exist {data_dir}/data owner {data_dir}/data {service_user} @@ -149,26 +152,55 @@ command "-" "Check PL/PerlU" ## SERVER ###################################################################### -command "service {service_name} initdb" "Database initialization" +command "-" "Create directory for data" + mkdir {test_data_dir} + chown {test_data_dir} {service_user}:{service_group} + +command "-" "Replace default sysconfig" + backup {sysconfig} + template sysconfig.tmpl {sysconfig} + +command "service {service_name} initdb" "Database initialization with default locale" exit 0 - exist {data_dir}/data/PG_VERSION - exist {data_dir}/data/pg_hba.conf - exist {data_dir}/data/pg_ident.conf - exist {data_dir}/data/postgresql.conf - exist {data_dir}/data/pg_wal - mode {data_dir}/data/pg_hba.conf 600 - mode {data_dir}/data/pg_ident.conf 600 - mode {data_dir}/data/postgresql.conf 600 - mode {data_dir}/data/pg_wal 700 - !empty {data_dir}/data/pg_hba.conf - !empty {data_dir}/data/pg_ident.conf - !empty {data_dir}/data/postgresql.conf - owner {data_dir}/data/pg_hba.conf {service_user} - owner {data_dir}/data/pg_ident.conf {service_user} - owner {data_dir}/data/postgresql.conf {service_user} + exist {test_data_dir}/PG_VERSION + exist {test_data_dir}/pg_hba.conf + exist {test_data_dir}/pg_ident.conf + exist {test_data_dir}/postgresql.conf + exist {test_data_dir}/pg_wal + mode {test_data_dir}/pg_hba.conf 600 + mode {test_data_dir}/pg_ident.conf 600 + mode {test_data_dir}/postgresql.conf 600 + mode {test_data_dir}/pg_wal 700 + !empty {test_data_dir}/pg_hba.conf + !empty {test_data_dir}/pg_ident.conf + !empty {test_data_dir}/postgresql.conf + owner {test_data_dir}/pg_hba.conf {service_user} + owner {test_data_dir}/pg_ident.conf {service_user} + owner {test_data_dir}/postgresql.conf {service_user} + ++command "-" "Remove data" + cleanup {test_data_dir} + +command "service {service_name} initdb en_GB.UTF-8" "Database initialization with custom locale" + exit 0 + exist {test_data_dir}/PG_VERSION + exist {test_data_dir}/pg_hba.conf + exist {test_data_dir}/pg_ident.conf + exist {test_data_dir}/postgresql.conf + exist {test_data_dir}/pg_wal + mode {test_data_dir}/pg_hba.conf 600 + mode {test_data_dir}/pg_ident.conf 600 + mode {test_data_dir}/postgresql.conf 600 + mode {test_data_dir}/pg_wal 700 + !empty {test_data_dir}/pg_hba.conf + !empty {test_data_dir}/pg_ident.conf + !empty {test_data_dir}/postgresql.conf + owner {test_data_dir}/pg_hba.conf {service_user} + owner {test_data_dir}/pg_ident.conf {service_user} + owner {test_data_dir}/postgresql.conf {service_user} +command "systemctl start {service_name}" "Start PostgreSQL server" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} checksum-read {pid_file} pid_sha @@ -176,31 +208,34 @@ command "service {service_name} initdb" "Database initialization" +command "systemctl status {service_name}" "Check status of PostgreSQL server" expect "active (running)" -+command "{service_user}:{install_dir}/bin/psql -t -c 'select version();'" "Check PostgreSQL version" ++command "{service_user}:{install_dir}/bin/psql -t -c 'SELECT version();'" "Check PostgreSQL version" exit 0 output-contains "PostgreSQL {version}" ++command "{service_user}:{install_dir}/bin/psql -t -c 'SHOW LC_COLLATE;'" "Check locale" + exit 0 + output-contains "en_GB.UTF-8" + +command "systemctl restart {service_name}" "Restart PostgreSQL server" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} !checksum {pid_file} {pid_sha} +command "systemctl stop {service_name}" "Stop PostgreSQL server" - !wait-fs {data_dir}/data/postmaster.pid {wait_fs} + !wait-fs {test_data_dir}/postmaster.pid {wait_fs} !wait-connect tcp :{port} {wait_connect} !wait-service {service_name} +command "service pg{version} start" "Check start using service with shortname link" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} +command "service pg{version} stop" "Check stop using service with shortname link" - !wait-fs {data_dir}/data/postmaster.pid {wait_fs} + !wait-fs {test_data_dir}/postmaster.pid {wait_fs} !wait-connect tcp :{port} {wait_connect} !wait-service {service_name} -command:teardown "-" "Data cleanup" - cleanup {data_dir}/data - cleanup {data_dir}/backups +command:teardown "-" "Restore original sysconfig file" + backup-restore {sysconfig} diff --git a/tests/postgresql/postgresql13.recipe b/tests/postgresql/postgresql13.recipe index 4de1d3d07..86690eee4 100644 --- a/tests/postgresql/postgresql13.recipe +++ b/tests/postgresql/postgresql13.recipe @@ -10,6 +10,7 @@ var version 13 var service_name postgresql-{version} var service_user postgres var service_group postgres +var sysconfig /etc/sysconfig/{service_name} var install_dir /usr/pgsql-{version} var lib_dir {install_dir}/lib var state_dir /var/lib/pgsql @@ -24,6 +25,8 @@ var python3_lib libpython{PYTHON3_VERSION}* var perl_lib libperl.* var tcl_lib libtcl8.* +var test_data_dir {WORKDIR}/db{version} + ## ENVIRONMENT ################################################################# command "-" "Check environment" @@ -49,7 +52,7 @@ command "-" "Check configuration files for external systems" exist /usr/lib/tmpfiles.d/postgresql-{version}.conf mode /usr/lib/tmpfiles.d/postgresql-{version}.conf 644 -command "-" "Check data directory" +command "-" "Check default data directory" exist {data_dir}/backups exist {data_dir}/data owner {data_dir}/data {service_user} @@ -151,26 +154,55 @@ command "-" "Check PL/PerlU" ## SERVER ###################################################################### -command "service {service_name} initdb" "Database initialization" +command "-" "Create directory for data" + mkdir {test_data_dir} + chown {test_data_dir} {service_user}:{service_group} + +command "-" "Replace default sysconfig" + backup {sysconfig} + template sysconfig.tmpl {sysconfig} + +command "service {service_name} initdb" "Database initialization with default locale" exit 0 - exist {data_dir}/data/PG_VERSION - exist {data_dir}/data/pg_hba.conf - exist {data_dir}/data/pg_ident.conf - exist {data_dir}/data/postgresql.conf - exist {data_dir}/data/pg_wal - mode {data_dir}/data/pg_hba.conf 600 - mode {data_dir}/data/pg_ident.conf 600 - mode {data_dir}/data/postgresql.conf 600 - mode {data_dir}/data/pg_wal 700 - !empty {data_dir}/data/pg_hba.conf - !empty {data_dir}/data/pg_ident.conf - !empty {data_dir}/data/postgresql.conf - owner {data_dir}/data/pg_hba.conf {service_user} - owner {data_dir}/data/pg_ident.conf {service_user} - owner {data_dir}/data/postgresql.conf {service_user} + exist {test_data_dir}/PG_VERSION + exist {test_data_dir}/pg_hba.conf + exist {test_data_dir}/pg_ident.conf + exist {test_data_dir}/postgresql.conf + exist {test_data_dir}/pg_wal + mode {test_data_dir}/pg_hba.conf 600 + mode {test_data_dir}/pg_ident.conf 600 + mode {test_data_dir}/postgresql.conf 600 + mode {test_data_dir}/pg_wal 700 + !empty {test_data_dir}/pg_hba.conf + !empty {test_data_dir}/pg_ident.conf + !empty {test_data_dir}/postgresql.conf + owner {test_data_dir}/pg_hba.conf {service_user} + owner {test_data_dir}/pg_ident.conf {service_user} + owner {test_data_dir}/postgresql.conf {service_user} + ++command "-" "Remove data" + cleanup {test_data_dir} + +command "service {service_name} initdb en_GB.UTF-8" "Database initialization with custom locale" + exit 0 + exist {test_data_dir}/PG_VERSION + exist {test_data_dir}/pg_hba.conf + exist {test_data_dir}/pg_ident.conf + exist {test_data_dir}/postgresql.conf + exist {test_data_dir}/pg_wal + mode {test_data_dir}/pg_hba.conf 600 + mode {test_data_dir}/pg_ident.conf 600 + mode {test_data_dir}/postgresql.conf 600 + mode {test_data_dir}/pg_wal 700 + !empty {test_data_dir}/pg_hba.conf + !empty {test_data_dir}/pg_ident.conf + !empty {test_data_dir}/postgresql.conf + owner {test_data_dir}/pg_hba.conf {service_user} + owner {test_data_dir}/pg_ident.conf {service_user} + owner {test_data_dir}/postgresql.conf {service_user} +command "systemctl start {service_name}" "Start PostgreSQL server" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} checksum-read {pid_file} pid_sha @@ -178,31 +210,34 @@ command "service {service_name} initdb" "Database initialization" +command "systemctl status {service_name}" "Check status of PostgreSQL server" expect "active (running)" -+command "{service_user}:{install_dir}/bin/psql -t -c 'select version();'" "Check PostgreSQL version" ++command "{service_user}:{install_dir}/bin/psql -t -c 'SELECT version();'" "Check PostgreSQL version" exit 0 output-contains "PostgreSQL {version}" ++command "{service_user}:{install_dir}/bin/psql -t -c 'SHOW LC_COLLATE;'" "Check locale" + exit 0 + output-contains "en_GB.UTF-8" + +command "systemctl restart {service_name}" "Restart PostgreSQL server" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} !checksum {pid_file} {pid_sha} +command "systemctl stop {service_name}" "Stop PostgreSQL server" - !wait-fs {data_dir}/data/postmaster.pid {wait_fs} + !wait-fs {test_data_dir}/postmaster.pid {wait_fs} !wait-connect tcp :{port} {wait_connect} !wait-service {service_name} +command "service pg{version} start" "Check start using service with shortname link" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} +command "service pg{version} stop" "Check stop using service with shortname link" - !wait-fs {data_dir}/data/postmaster.pid {wait_fs} + !wait-fs {test_data_dir}/postmaster.pid {wait_fs} !wait-connect tcp :{port} {wait_connect} !wait-service {service_name} -command:teardown "-" "Data cleanup" - cleanup {data_dir}/data - cleanup {data_dir}/backups +command:teardown "-" "Restore original sysconfig file" + backup-restore {sysconfig} diff --git a/tests/postgresql/postgresql14.recipe b/tests/postgresql/postgresql14.recipe index 26eebe3c4..d142d1018 100644 --- a/tests/postgresql/postgresql14.recipe +++ b/tests/postgresql/postgresql14.recipe @@ -10,6 +10,7 @@ var version 14 var service_name postgresql-{version} var service_user postgres var service_group postgres +var sysconfig /etc/sysconfig/{service_name} var install_dir /usr/pgsql-{version} var lib_dir {install_dir}/lib var state_dir /var/lib/pgsql @@ -24,6 +25,8 @@ var python3_lib libpython{PYTHON3_VERSION}* var perl_lib libperl.* var tcl_lib libtcl8.* +var test_data_dir {WORKDIR}/db{version} + ## ENVIRONMENT ################################################################# command "-" "Check environment" @@ -49,7 +52,7 @@ command "-" "Check configuration files for external systems" exist /usr/lib/tmpfiles.d/postgresql-{version}.conf mode /usr/lib/tmpfiles.d/postgresql-{version}.conf 644 -command "-" "Check data directory" +command "-" "Check default data directory" exist {data_dir}/backups exist {data_dir}/data owner {data_dir}/data {service_user} @@ -151,26 +154,55 @@ command "-" "Check PL/PerlU" ## SERVER ###################################################################### -command "service {service_name} initdb" "Database initialization" +command "-" "Create directory for data" + mkdir {test_data_dir} + chown {test_data_dir} {service_user}:{service_group} + +command "-" "Replace default sysconfig" + backup {sysconfig} + template sysconfig.tmpl {sysconfig} + +command "service {service_name} initdb" "Database initialization with default locale" exit 0 - exist {data_dir}/data/PG_VERSION - exist {data_dir}/data/pg_hba.conf - exist {data_dir}/data/pg_ident.conf - exist {data_dir}/data/postgresql.conf - exist {data_dir}/data/pg_wal - mode {data_dir}/data/pg_hba.conf 600 - mode {data_dir}/data/pg_ident.conf 600 - mode {data_dir}/data/postgresql.conf 600 - mode {data_dir}/data/pg_wal 700 - !empty {data_dir}/data/pg_hba.conf - !empty {data_dir}/data/pg_ident.conf - !empty {data_dir}/data/postgresql.conf - owner {data_dir}/data/pg_hba.conf {service_user} - owner {data_dir}/data/pg_ident.conf {service_user} - owner {data_dir}/data/postgresql.conf {service_user} + exist {test_data_dir}/PG_VERSION + exist {test_data_dir}/pg_hba.conf + exist {test_data_dir}/pg_ident.conf + exist {test_data_dir}/postgresql.conf + exist {test_data_dir}/pg_wal + mode {test_data_dir}/pg_hba.conf 600 + mode {test_data_dir}/pg_ident.conf 600 + mode {test_data_dir}/postgresql.conf 600 + mode {test_data_dir}/pg_wal 700 + !empty {test_data_dir}/pg_hba.conf + !empty {test_data_dir}/pg_ident.conf + !empty {test_data_dir}/postgresql.conf + owner {test_data_dir}/pg_hba.conf {service_user} + owner {test_data_dir}/pg_ident.conf {service_user} + owner {test_data_dir}/postgresql.conf {service_user} + ++command "-" "Remove data" + cleanup {test_data_dir} + +command "service {service_name} initdb en_GB.UTF-8" "Database initialization with custom locale" + exit 0 + exist {test_data_dir}/PG_VERSION + exist {test_data_dir}/pg_hba.conf + exist {test_data_dir}/pg_ident.conf + exist {test_data_dir}/postgresql.conf + exist {test_data_dir}/pg_wal + mode {test_data_dir}/pg_hba.conf 600 + mode {test_data_dir}/pg_ident.conf 600 + mode {test_data_dir}/postgresql.conf 600 + mode {test_data_dir}/pg_wal 700 + !empty {test_data_dir}/pg_hba.conf + !empty {test_data_dir}/pg_ident.conf + !empty {test_data_dir}/postgresql.conf + owner {test_data_dir}/pg_hba.conf {service_user} + owner {test_data_dir}/pg_ident.conf {service_user} + owner {test_data_dir}/postgresql.conf {service_user} +command "systemctl start {service_name}" "Start PostgreSQL server" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} checksum-read {pid_file} pid_sha @@ -178,31 +210,34 @@ command "service {service_name} initdb" "Database initialization" +command "systemctl status {service_name}" "Check status of PostgreSQL server" expect "active (running)" -+command "{service_user}:{install_dir}/bin/psql -t -c 'select version();'" "Check PostgreSQL version" ++command "{service_user}:{install_dir}/bin/psql -t -c 'SELECT version();'" "Check PostgreSQL version" exit 0 output-contains "PostgreSQL {version}" ++command "{service_user}:{install_dir}/bin/psql -t -c 'SHOW LC_COLLATE;'" "Check locale" + exit 0 + output-contains "en_GB.UTF-8" + +command "systemctl restart {service_name}" "Restart PostgreSQL server" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} !checksum {pid_file} {pid_sha} +command "systemctl stop {service_name}" "Stop PostgreSQL server" - !wait-fs {data_dir}/data/postmaster.pid {wait_fs} + !wait-fs {test_data_dir}/postmaster.pid {wait_fs} !wait-connect tcp :{port} {wait_connect} !wait-service {service_name} +command "service pg{version} start" "Check start using service with shortname link" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} +command "service pg{version} stop" "Check stop using service with shortname link" - !wait-fs {data_dir}/data/postmaster.pid {wait_fs} + !wait-fs {test_data_dir}/postmaster.pid {wait_fs} !wait-connect tcp :{port} {wait_connect} !wait-service {service_name} -command:teardown "-" "Data cleanup" - cleanup {data_dir}/data - cleanup {data_dir}/backups +command:teardown "-" "Restore original sysconfig file" + backup-restore {sysconfig} diff --git a/tests/postgresql/postgresql15.recipe b/tests/postgresql/postgresql15.recipe index 4cdc3f655..0bfae1966 100644 --- a/tests/postgresql/postgresql15.recipe +++ b/tests/postgresql/postgresql15.recipe @@ -10,6 +10,7 @@ var version 15 var service_name postgresql-{version} var service_user postgres var service_group postgres +var sysconfig /etc/sysconfig/{service_name} var install_dir /usr/pgsql-{version} var lib_dir {install_dir}/lib var state_dir /var/lib/pgsql @@ -24,6 +25,8 @@ var python3_lib libpython{PYTHON3_VERSION}* var perl_lib libperl.* var tcl_lib libtcl8.* +var test_data_dir {WORKDIR}/db{version} + ## ENVIRONMENT ################################################################# command "-" "Check environment" @@ -49,7 +52,7 @@ command "-" "Check configuration files for external systems" exist /usr/lib/tmpfiles.d/postgresql-{version}.conf mode /usr/lib/tmpfiles.d/postgresql-{version}.conf 644 -command "-" "Check data directory" +command "-" "Check default data directory" exist {data_dir}/backups exist {data_dir}/data owner {data_dir}/data {service_user} @@ -151,26 +154,55 @@ command "-" "Check PL/PerlU" ## SERVER ###################################################################### -command "service {service_name} initdb" "Database initialization" +command "-" "Create directory for data" + mkdir {test_data_dir} + chown {test_data_dir} {service_user}:{service_group} + +command "-" "Replace default sysconfig" + backup {sysconfig} + template sysconfig.tmpl {sysconfig} + +command "service {service_name} initdb" "Database initialization with default locale" exit 0 - exist {data_dir}/data/PG_VERSION - exist {data_dir}/data/pg_hba.conf - exist {data_dir}/data/pg_ident.conf - exist {data_dir}/data/postgresql.conf - exist {data_dir}/data/pg_wal - mode {data_dir}/data/pg_hba.conf 600 - mode {data_dir}/data/pg_ident.conf 600 - mode {data_dir}/data/postgresql.conf 600 - mode {data_dir}/data/pg_wal 700 - !empty {data_dir}/data/pg_hba.conf - !empty {data_dir}/data/pg_ident.conf - !empty {data_dir}/data/postgresql.conf - owner {data_dir}/data/pg_hba.conf {service_user} - owner {data_dir}/data/pg_ident.conf {service_user} - owner {data_dir}/data/postgresql.conf {service_user} + exist {test_data_dir}/PG_VERSION + exist {test_data_dir}/pg_hba.conf + exist {test_data_dir}/pg_ident.conf + exist {test_data_dir}/postgresql.conf + exist {test_data_dir}/pg_wal + mode {test_data_dir}/pg_hba.conf 600 + mode {test_data_dir}/pg_ident.conf 600 + mode {test_data_dir}/postgresql.conf 600 + mode {test_data_dir}/pg_wal 700 + !empty {test_data_dir}/pg_hba.conf + !empty {test_data_dir}/pg_ident.conf + !empty {test_data_dir}/postgresql.conf + owner {test_data_dir}/pg_hba.conf {service_user} + owner {test_data_dir}/pg_ident.conf {service_user} + owner {test_data_dir}/postgresql.conf {service_user} + ++command "-" "Remove data" + cleanup {test_data_dir} + +command "service {service_name} initdb en_GB.UTF-8" "Database initialization with custom locale" + exit 0 + exist {test_data_dir}/PG_VERSION + exist {test_data_dir}/pg_hba.conf + exist {test_data_dir}/pg_ident.conf + exist {test_data_dir}/postgresql.conf + exist {test_data_dir}/pg_wal + mode {test_data_dir}/pg_hba.conf 600 + mode {test_data_dir}/pg_ident.conf 600 + mode {test_data_dir}/postgresql.conf 600 + mode {test_data_dir}/pg_wal 700 + !empty {test_data_dir}/pg_hba.conf + !empty {test_data_dir}/pg_ident.conf + !empty {test_data_dir}/postgresql.conf + owner {test_data_dir}/pg_hba.conf {service_user} + owner {test_data_dir}/pg_ident.conf {service_user} + owner {test_data_dir}/postgresql.conf {service_user} +command "systemctl start {service_name}" "Start PostgreSQL server" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} checksum-read {pid_file} pid_sha @@ -178,31 +210,34 @@ command "service {service_name} initdb" "Database initialization" +command "systemctl status {service_name}" "Check status of PostgreSQL server" expect "active (running)" -+command "{service_user}:{install_dir}/bin/psql -t -c 'select version();'" "Check PostgreSQL version" ++command "{service_user}:{install_dir}/bin/psql -t -c 'SELECT version();'" "Check PostgreSQL version" exit 0 output-contains "PostgreSQL {version}" ++command "{service_user}:{install_dir}/bin/psql -t -c 'SHOW LC_COLLATE;'" "Check locale" + exit 0 + output-contains "en_GB.UTF-8" + +command "systemctl restart {service_name}" "Restart PostgreSQL server" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} !checksum {pid_file} {pid_sha} +command "systemctl stop {service_name}" "Stop PostgreSQL server" - !wait-fs {data_dir}/data/postmaster.pid {wait_fs} + !wait-fs {test_data_dir}/postmaster.pid {wait_fs} !wait-connect tcp :{port} {wait_connect} !wait-service {service_name} +command "service pg{version} start" "Check start using service with shortname link" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} +command "service pg{version} stop" "Check stop using service with shortname link" - !wait-fs {data_dir}/data/postmaster.pid {wait_fs} + !wait-fs {test_data_dir}/postmaster.pid {wait_fs} !wait-connect tcp :{port} {wait_connect} !wait-service {service_name} -command:teardown "-" "Data cleanup" - cleanup {data_dir}/data - cleanup {data_dir}/backups +command:teardown "-" "Restore original sysconfig file" + backup-restore {sysconfig} diff --git a/tests/postgresql/postgresql16.recipe b/tests/postgresql/postgresql16.recipe index 6874d6c2b..1232b421c 100644 --- a/tests/postgresql/postgresql16.recipe +++ b/tests/postgresql/postgresql16.recipe @@ -10,6 +10,7 @@ var version 16 var service_name postgresql-{version} var service_user postgres var service_group postgres +var sysconfig /etc/sysconfig/{service_name} var install_dir /usr/pgsql-{version} var lib_dir {install_dir}/lib var state_dir /var/lib/pgsql @@ -24,6 +25,8 @@ var python3_lib libpython{PYTHON3_VERSION}* var perl_lib libperl.* var tcl_lib libtcl8.* +var test_data_dir {WORKDIR}/db{version} + ## ENVIRONMENT ################################################################# command "-" "Check environment" @@ -49,7 +52,7 @@ command "-" "Check configuration files for external systems" exist /usr/lib/tmpfiles.d/postgresql-{version}.conf mode /usr/lib/tmpfiles.d/postgresql-{version}.conf 644 -command "-" "Check data directory" +command "-" "Check default data directory" exist {data_dir}/backups exist {data_dir}/data owner {data_dir}/data {service_user} @@ -151,26 +154,55 @@ command "-" "Check PL/PerlU" ## SERVER ###################################################################### -command "service {service_name} initdb" "Database initialization" +command "-" "Create directory for data" + mkdir {test_data_dir} + chown {test_data_dir} {service_user}:{service_group} + +command "-" "Replace default sysconfig" + backup {sysconfig} + template sysconfig.tmpl {sysconfig} + +command "service {service_name} initdb" "Database initialization with default locale" exit 0 - exist {data_dir}/data/PG_VERSION - exist {data_dir}/data/pg_hba.conf - exist {data_dir}/data/pg_ident.conf - exist {data_dir}/data/postgresql.conf - exist {data_dir}/data/pg_wal - mode {data_dir}/data/pg_hba.conf 600 - mode {data_dir}/data/pg_ident.conf 600 - mode {data_dir}/data/postgresql.conf 600 - mode {data_dir}/data/pg_wal 700 - !empty {data_dir}/data/pg_hba.conf - !empty {data_dir}/data/pg_ident.conf - !empty {data_dir}/data/postgresql.conf - owner {data_dir}/data/pg_hba.conf {service_user} - owner {data_dir}/data/pg_ident.conf {service_user} - owner {data_dir}/data/postgresql.conf {service_user} + exist {test_data_dir}/PG_VERSION + exist {test_data_dir}/pg_hba.conf + exist {test_data_dir}/pg_ident.conf + exist {test_data_dir}/postgresql.conf + exist {test_data_dir}/pg_wal + mode {test_data_dir}/pg_hba.conf 600 + mode {test_data_dir}/pg_ident.conf 600 + mode {test_data_dir}/postgresql.conf 600 + mode {test_data_dir}/pg_wal 700 + !empty {test_data_dir}/pg_hba.conf + !empty {test_data_dir}/pg_ident.conf + !empty {test_data_dir}/postgresql.conf + owner {test_data_dir}/pg_hba.conf {service_user} + owner {test_data_dir}/pg_ident.conf {service_user} + owner {test_data_dir}/postgresql.conf {service_user} + ++command "-" "Remove data" + cleanup {test_data_dir} + +command "service {service_name} initdb en_GB.UTF-8" "Database initialization with custom locale" + exit 0 + exist {test_data_dir}/PG_VERSION + exist {test_data_dir}/pg_hba.conf + exist {test_data_dir}/pg_ident.conf + exist {test_data_dir}/postgresql.conf + exist {test_data_dir}/pg_wal + mode {test_data_dir}/pg_hba.conf 600 + mode {test_data_dir}/pg_ident.conf 600 + mode {test_data_dir}/postgresql.conf 600 + mode {test_data_dir}/pg_wal 700 + !empty {test_data_dir}/pg_hba.conf + !empty {test_data_dir}/pg_ident.conf + !empty {test_data_dir}/postgresql.conf + owner {test_data_dir}/pg_hba.conf {service_user} + owner {test_data_dir}/pg_ident.conf {service_user} + owner {test_data_dir}/postgresql.conf {service_user} +command "systemctl start {service_name}" "Start PostgreSQL server" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} checksum-read {pid_file} pid_sha @@ -178,31 +210,34 @@ command "service {service_name} initdb" "Database initialization" +command "systemctl status {service_name}" "Check status of PostgreSQL server" expect "active (running)" -+command "{service_user}:{install_dir}/bin/psql -t -c 'select version();'" "Check PostgreSQL version" ++command "{service_user}:{install_dir}/bin/psql -t -c 'SELECT version();'" "Check PostgreSQL version" exit 0 output-contains "PostgreSQL {version}" ++command "{service_user}:{install_dir}/bin/psql -t -c 'SHOW LC_COLLATE;'" "Check locale" + exit 0 + output-contains "en_GB.UTF-8" + +command "systemctl restart {service_name}" "Restart PostgreSQL server" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} !checksum {pid_file} {pid_sha} +command "systemctl stop {service_name}" "Stop PostgreSQL server" - !wait-fs {data_dir}/data/postmaster.pid {wait_fs} + !wait-fs {test_data_dir}/postmaster.pid {wait_fs} !wait-connect tcp :{port} {wait_connect} !wait-service {service_name} +command "service pg{version} start" "Check start using service with shortname link" - wait-fs {data_dir}/data/postmaster.pid {wait_fs} + wait-fs {test_data_dir}/postmaster.pid {wait_fs} wait-connect tcp :{port} {wait_connect} wait-service {service_name} +command "service pg{version} stop" "Check stop using service with shortname link" - !wait-fs {data_dir}/data/postmaster.pid {wait_fs} + !wait-fs {test_data_dir}/postmaster.pid {wait_fs} !wait-connect tcp :{port} {wait_connect} !wait-service {service_name} -command:teardown "-" "Data cleanup" - cleanup {data_dir}/data - cleanup {data_dir}/backups +command:teardown "-" "Restore original sysconfig file" + backup-restore {sysconfig} diff --git a/tests/postgresql/sysconfig.tmpl b/tests/postgresql/sysconfig.tmpl new file mode 100644 index 000000000..a307f2557 --- /dev/null +++ b/tests/postgresql/sysconfig.tmpl @@ -0,0 +1,10 @@ +# Sysconfig for postgresql service + +PG_ENGINE="" +PG_POSTMASTER="" +PG_DATA="{{.Var "test_data_dir"}}" +PG_LOG="" +PG_UPLOG="" +PG_SOCKET_DIR="" +TIMEOUT="" +DISABLE_AUTO_NUMA=""