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

ENT-10647: Fixed and improved postgresql server state handling in package scriptlets (3.21) #1305

Merged
merged 1 commit into from
Sep 29, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packaging/common/cfengine-hub/postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ init_postgres_dir()
# Started successfully, stop it again, the migration requires it to be not running.
(cd /tmp && su cfpostgres -c "$PREFIX/bin/pg_ctl -w -D $PREFIX/state/pg/data -l /var/log/postgresql.log stop") || failure=1
if [ $failure = 0 ]; then
wait_for_cfpostgres_down || failure=1
wait_for_cf_postgres_down || failure=1
fi
if [ $failure != 0 ]; then
cf_console echo "Error: unable to shutdown postgresql server. Showing last of /var/log/postgresql.log for clues."
Expand Down Expand Up @@ -696,7 +696,7 @@ do_migration() {
# Consult the last few lines of "/var/cfengine/state/pg/data/pg_upgrade_output.d/20230913T150025.959/log/pg_upgrade_server.log" for the probable cause of the failure.
cf_console echo "Showing last lines of any related log files:"
_daysearch=$(date +%Y%m%d)
find "$PREFIX"/state/pg/data/pg_upgrade_output.d -name *.log | grep "$_daysearch" | xargs tail
find "$PREFIX"/state/pg/data/pg_upgrade_output.d -name *.log | grep "$_daysearch" | cf_console xargs tail
cf_console echo
check_disk_space # will abort if low on disk space
init_postgres_dir "$new_pgconfig_file" "$pgconfig_type"
Expand Down
18 changes: 9 additions & 9 deletions packaging/common/script-templates/script-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ restore_cfengine_state() {
}

wait_for_cf_postgres() {
# wait for CFEngine Postgresql service to be available, up to 5 sec.
# wait for CFEngine Postgresql service to be available, up to 60 sec.
# Returns 0 is psql command succeeds,
# Returns non-0 otherwise (1 if exited by timeout)
for i in $(seq 1 5); do
for i in $(seq 1 60); do
true "checking if Postgresql is available..."
if $PREFIX/bin/psql cfsettings -c "SELECT 1;" >/dev/null 2>&1; then
if cd /tmp && su cfpostgres -c "$PREFIX/bin/psql -l" >/dev/null 2>&1; then
true "Postgresql is available, moving on"
return 0
fi
Expand All @@ -96,25 +96,25 @@ wait_for_cf_postgres() {
done
# Note: it is important that this is the last command of this function.
# Return code of `psql` is the return code of whole function.
$PREFIX/bin/psql cfsettings -c "SELECT 1;" >/dev/null 2>&1
cd /tmp && su cfpostgres -c "$PREFIX/bin/psql -l" >/dev/null 2>&1
}

wait_for_cf_postgres_down() {
# wait for CFEngine Postgresql service to be shutdown, up to 5 sec.
# wait for CFEngine Postgresql service to be shutdown, up to 60 sec.
# Returns 0 if postgresql service is not running
# Returns non-0 otherwise (1 if exited by timeout)
for i in $(seq 1 5); do
for i in $(seq 1 60); do
true "checking if Postgresql is shutdown..."
if ! "$PREFIX"/bin/pg_isready >/dev/null 2>&1; then
if cd /tmp && ! su cfpostgres -c "$PREFIX/bin/psql -l" >/dev/null 2>&1; then
true "Postgresql is shutdown, moving on"
return 0
fi
true "waiting 1 sec for Postgresql to shutdown..."
sleep 1
done
# Note: it is important that this is the last command of this function.
# Return code of `pg_isready` is the return code of whole function.
! "$PREFIX"/bin/pg_isready >/dev/null 2>&1
# Return code of `psql` is the return code of whole function.
cd /tmp && ! su cfpostgres -c "$PREFIX/bin/psql -l" >/dev/null 2>&1
}

safe_cp() {
Expand Down
Loading