Handle special PostgreSQL directories safely
Browse files
start.sh
CHANGED
|
@@ -7,7 +7,21 @@ APP_DATA_DIR=/data/sub2api
|
|
| 7 |
APP_PID=""
|
| 8 |
REDIS_PID=""
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
pg_commit_ts
|
| 12 |
pg_dynshmem
|
| 13 |
pg_logical
|
|
@@ -31,20 +45,27 @@ pg_wal/summaries
|
|
| 31 |
"
|
| 32 |
|
| 33 |
ensure_pg_dirs() {
|
| 34 |
-
for rel in $
|
| 35 |
dir="$PGDATA/$rel"
|
| 36 |
-
marker="$dir/.hf-keep"
|
| 37 |
if [ ! -d "$dir" ]; then
|
| 38 |
mkdir -p "$dir"
|
| 39 |
chown postgres:postgres "$dir"
|
| 40 |
chmod 700 "$dir"
|
| 41 |
echo "Restored PostgreSQL directory: $rel"
|
| 42 |
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
if [ ! -f "$marker" ]; then
|
| 44 |
printf '%s\n' "HF Spaces persistent directory marker" > "$marker"
|
| 45 |
chown postgres:postgres "$marker"
|
| 46 |
fi
|
| 47 |
done
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
}
|
| 49 |
|
| 50 |
start_postgres() {
|
|
@@ -132,7 +153,7 @@ while kill -0 "$APP_PID" 2>/dev/null; do
|
|
| 132 |
fi
|
| 133 |
echo "PostgreSQL recovered"
|
| 134 |
fi
|
| 135 |
-
sleep
|
| 136 |
done
|
| 137 |
|
| 138 |
wait "$APP_PID"
|
|
|
|
| 7 |
APP_PID=""
|
| 8 |
REDIS_PID=""
|
| 9 |
|
| 10 |
+
PG_MARKER_DIRS="
|
| 11 |
+
pg_commit_ts
|
| 12 |
+
pg_dynshmem
|
| 13 |
+
pg_multixact/members
|
| 14 |
+
pg_multixact/offsets
|
| 15 |
+
pg_notify
|
| 16 |
+
pg_serial
|
| 17 |
+
pg_snapshots
|
| 18 |
+
pg_stat
|
| 19 |
+
pg_stat_tmp
|
| 20 |
+
pg_subtrans
|
| 21 |
+
pg_twophase
|
| 22 |
+
"
|
| 23 |
+
|
| 24 |
+
PG_RECREATE_DIRS="
|
| 25 |
pg_commit_ts
|
| 26 |
pg_dynshmem
|
| 27 |
pg_logical
|
|
|
|
| 45 |
"
|
| 46 |
|
| 47 |
ensure_pg_dirs() {
|
| 48 |
+
for rel in $PG_RECREATE_DIRS; do
|
| 49 |
dir="$PGDATA/$rel"
|
|
|
|
| 50 |
if [ ! -d "$dir" ]; then
|
| 51 |
mkdir -p "$dir"
|
| 52 |
chown postgres:postgres "$dir"
|
| 53 |
chmod 700 "$dir"
|
| 54 |
echo "Restored PostgreSQL directory: $rel"
|
| 55 |
fi
|
| 56 |
+
done
|
| 57 |
+
|
| 58 |
+
for rel in $PG_MARKER_DIRS; do
|
| 59 |
+
marker="$PGDATA/$rel/.hf-keep"
|
| 60 |
if [ ! -f "$marker" ]; then
|
| 61 |
printf '%s\n' "HF Spaces persistent directory marker" > "$marker"
|
| 62 |
chown postgres:postgres "$marker"
|
| 63 |
fi
|
| 64 |
done
|
| 65 |
+
|
| 66 |
+
for rel in pg_logical pg_logical/mappings pg_logical/snapshots pg_multixact pg_replslot pg_tblspc pg_wal pg_wal/archive_status pg_wal/summaries; do
|
| 67 |
+
rm -f "$PGDATA/$rel/.hf-keep"
|
| 68 |
+
done
|
| 69 |
}
|
| 70 |
|
| 71 |
start_postgres() {
|
|
|
|
| 153 |
fi
|
| 154 |
echo "PostgreSQL recovered"
|
| 155 |
fi
|
| 156 |
+
sleep 2
|
| 157 |
done
|
| 158 |
|
| 159 |
wait "$APP_PID"
|