keithproject commited on
Commit
e8f054f
·
1 Parent(s): bf79b7b

fix: keepalive loop — re-assert FUSE dirs every 5s during postgres runtime

Browse files

FUSE drops empty dirs not only at startup but also during runtime (seen at
00:56:12+10min: checkpoint ERROR pg_logical/snapshots). One-shot repair at
start is not enough. Add background loop that checks and recreates missing
dirs every 5s while postgres is running. Trap EXIT to clean up loop PID.

Files changed (1) hide show
  1. postgres-fuse-wrap +25 -1
postgres-fuse-wrap CHANGED
@@ -52,7 +52,31 @@ chown mem0:mem0 \
52
  2>/dev/null || true
53
  chown -h mem0:mem0 "$PGDATA/pg_tblspc"
54
 
55
- # Drop to mem0 and exec postgres (gosu replaces this shell — supervisord tracks the pid)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  exec gosu mem0 /usr/lib/postgresql/15/bin/postgres \
57
  -D "$PGDATA" \
58
  -c config_file="$PGDATA/postgresql.conf"
 
52
  2>/dev/null || true
53
  chown -h mem0:mem0 "$PGDATA/pg_tblspc"
54
 
55
+ # Background loop: FUSE can drop empty dirs at any time during runtime, not
56
+ # just at startup. Re-assert critical dirs every 5s while postgres is alive.
57
+ fuse_keepalive() {
58
+ while true; do
59
+ sleep 5
60
+ for dir in pg_replslot pg_twophase pg_dynshmem pg_notify \
61
+ pg_snapshots pg_logical/snapshots pg_logical/mappings; do
62
+ if [ ! -d "$PGDATA/$dir" ]; then
63
+ mkdir -p "$PGDATA/$dir" 2>/dev/null && \
64
+ chown mem0:mem0 "$PGDATA/$dir" 2>/dev/null || true
65
+ fi
66
+ done
67
+ if [ ! -L "$PGDATA/pg_tblspc" ]; then
68
+ rm -rf "$PGDATA/pg_tblspc"
69
+ ln -sfn /tmp/pg_tblspc "$PGDATA/pg_tblspc" 2>/dev/null
70
+ chown -h mem0:mem0 "$PGDATA/pg_tblspc" 2>/dev/null || true
71
+ fi
72
+ done
73
+ }
74
+ fuse_keepalive &
75
+ KEEPALIVE_PID=$!
76
+
77
+ # Drop to mem0 and exec postgres.
78
+ # Note: exec replaces this shell, so trap cleanup of keepalive on exit.
79
+ trap "kill $KEEPALIVE_PID 2>/dev/null" EXIT
80
  exec gosu mem0 /usr/lib/postgresql/15/bin/postgres \
81
  -D "$PGDATA" \
82
  -c config_file="$PGDATA/postgresql.conf"