Skip to content

Commit cbd8dca

Browse files
FIX: attempt the postgresql update if a stale socket file exists
If postgres was not shut down cleanly, pg_upgrade returns that error. If it's just a stale file, pg_upgrade should continue to run.
1 parent ad89eb3 commit cbd8dca

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

templates/postgres.template.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ run:
5050
chmod: "+x"
5151
contents: |
5252
#!/bin/bash
53+
run_upgrade_postgres() {
54+
if [ -f /root/upgrade_postgres ]; then
55+
unset RETCODE
56+
/root/upgrade_postgres || RETCODE=$?
57+
[ -z "${RETCODE}" ] && rm /root/upgrade_postgres || exit $RETCODE
58+
fi
59+
exit 0
60+
}
5361
sed -i "s/^# $LANG/$LANG/" /etc/locale.gen
5462
locale-gen && update-locale
5563
mkdir -p /shared/postgres_run
@@ -58,7 +66,7 @@ run:
5866
rm -fr /var/run/postgresql
5967
ln -s /shared/postgres_run /var/run/postgresql
6068
if [ -e /shared/postgres_run/.s.PGSQL.5432 ]; then
61-
socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
69+
socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || run_upgrade_postgres && echo postgres already running stop container ; exit 1
6270
fi
6371
rm -fr /shared/postgres_run/.s*
6472
rm -fr /shared/postgres_run/*.pid
@@ -70,11 +78,8 @@ run:
7078
sudo -E -u postgres /usr/lib/postgresql/15/bin/initdb -D /shared/postgres_data
7179
chown -R postgres:postgres /shared/postgres_data
7280
chown -R postgres:postgres /var/run/postgresql
73-
elif [ -f /root/upgrade_postgres ]; then
74-
unset RETCODE
75-
/root/upgrade_postgres || RETCODE=$?
76-
[ -z "${RETCODE}" ] && rm /root/upgrade_postgres || exit $RETCODE
7781
fi
82+
run_upgrade_postgres
7883
# Necessary to enable backups
7984
install -d -m 0755 -o postgres -g postgres /shared/postgres_backup
8085

0 commit comments

Comments
 (0)