Skip to content

Commit a9d8458

Browse files
committed
fix: wait for data volume to be detected prior to completing upgrade
1 parent 47d4ec7 commit a9d8458

1 file changed

Lines changed: 37 additions & 3 deletions

File tree

  • ansible/files/admin_api_scripts/pg_upgrade_scripts

ansible/files/admin_api_scripts/pg_upgrade_scripts/complete.sh

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@ source "$SCRIPT_DIR/common.sh"
1414
IS_CI=${IS_CI:-}
1515
LOG_FILE="/var/log/pg-upgrade-complete.log"
1616

17+
18+
# Wait for the volume mapped to /data to appear before attempting to mount it
19+
function wait_for_data_device {
20+
local fstab_src dev=""
21+
fstab_src=$(awk '$2 == "/data" {print $1}' /etc/fstab)
22+
if [ -z "$fstab_src" ]; then
23+
echo "No /data entry in /etc/fstab"
24+
return 1
25+
fi
26+
27+
echo "Waiting for /data device ($fstab_src) to appear"
28+
for _ in $(seq 1 60); do
29+
dev=$(findfs "$fstab_src" 2>/dev/null) || dev=""
30+
if [ -n "$dev" ] && [ -b "$dev" ]; then
31+
echo "/data device ($dev) is available"
32+
return 0
33+
fi
34+
sleep 1
35+
done
36+
echo "Timed out waiting for /data device ($fstab_src)"
37+
return 1
38+
}
39+
1740
function cleanup {
1841
UPGRADE_STATUS=${1:-"failed"}
1942
EXIT_CODE=${?:-0}
@@ -221,7 +244,18 @@ function complete_pg_upgrade {
221244

222245
echo "1. Mounting data disk"
223246
if [ -z "$IS_CI" ]; then
247+
# Let udev finish detecting the vollume before mounting
248+
udevadm settle --timeout=60 || true
249+
wait_for_data_device
250+
224251
retry 8 mount -a -v
252+
253+
# `nofail` in /etc/fstab makes `mount -a` exit with a code of 0 even when the volume is absent
254+
# In the offchance of the volume not being mounted or detected, explicitly fail here
255+
if ! mountpoint -q /data; then
256+
echo "FATAL: /data is not a mountpoint"
257+
exit 1
258+
fi
225259
else
226260
echo "Skipping mount -a -v"
227261
fi
@@ -262,11 +296,11 @@ function complete_pg_upgrade {
262296
echo "5. Restarting postgresql"
263297
if [ -z "$IS_CI" ]; then
264298
retry 3 service postgresql restart
265-
299+
266300
echo "5.1. Restarting gotrue and postgrest"
267301
retry 3 service gotrue restart
268302
retry 3 service postgrest restart
269-
303+
270304
else
271305
retry 3 CI_stop_postgres || true
272306
retry 3 CI_start_postgres
@@ -327,7 +361,7 @@ locale-gen
327361

328362
if [ -z "$IS_CI" ]; then
329363
complete_pg_upgrade >> $LOG_FILE 2>&1 &
330-
else
364+
else
331365
CI_stop_postgres || true
332366

333367
rm -f /tmp/pg-upgrade-status

0 commit comments

Comments
 (0)