@@ -19,28 +19,31 @@ STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@
19
19
cleanup () {
20
20
echo " Cleaning up..."
21
21
22
- # Kill overmind processes first
22
+ # Kill postgres processes first
23
+ if pgrep -f " postgres" > /dev/null; then
24
+ pkill -TERM postgres || true
25
+ sleep 2
26
+ fi
27
+
28
+ # Then kill overmind
23
29
if [ -S " ./.overmind.sock" ]; then
24
30
overmind kill || true
25
31
sleep 2
26
32
fi
27
33
28
- # Kill any remaining postgres processes
29
- echo " Killing any remaining postgres processes..."
30
- pkill -9 postgres || true
31
- pkill -9 -f " tmux.*overmind.*postgresql" || true
32
-
33
- # Extra cleanup for tmux sessions
34
+ # Kill tmux sessions explicitly
35
+ pkill -f " tmux.*overmind.*postgresql" || true
34
36
tmux ls 2> /dev/null | grep ' overmind' | cut -d: -f1 | xargs -I{} tmux kill-session -t {} || true
37
+
38
+ # Force kill any stragglers
39
+ pkill -9 -f " (postgres|tmux.*overmind.*postgresql)" || true
35
40
36
- # Remove socket and Procfile
37
41
rm -f .overmind.sock Procfile
38
-
39
- # Verify cleanup
40
- remaining=$( ps aux | grep -E " (postgres|overmind|tmux.*postgresql)" | grep -v grep || true)
41
- if [ ! -z " $remaining " ]; then
42
- echo " Warning: Some processes might still be running:"
43
- echo " $remaining "
42
+
43
+ # Final verification
44
+ if ps aux | grep -E " (postgres|overmind|tmux.*postgresql)" | grep -v grep > /dev/null; then
45
+ ps aux | grep -E " (postgres|overmind|tmux.*postgresql)" | grep -v grep
46
+ return 1
44
47
fi
45
48
}
46
49
174
177
count=$(( count + 1 ))
175
178
done
176
179
}
180
+ perform_dump () {
181
+ local max_attempts=3
182
+ local attempt=1
183
+
184
+ while [ $attempt -le $max_attempts ]; do
185
+ echo " Attempting dbmate dump (attempt $attempt /$max_attempts )"
186
+
187
+ if dbmate dump; then
188
+ return 0
189
+ fi
190
+
191
+ echo " Dump attempt $attempt failed, waiting before retry..."
192
+ sleep 5
193
+ attempt=$(( attempt + 1 ))
194
+ done
195
+
196
+ echo " All dump attempts failed"
197
+ return 1
198
+ }
177
199
migrate_version () {
178
200
echo " PSQL_VERSION: $PSQL_VERSION "
179
201
overmind kill || true
@@ -233,7 +255,7 @@ EOSQL
233
255
fi
234
256
235
257
echo " Running dbmate dump with $PSQLBIN "
236
- dbmate dump
258
+ perform_dump
237
259
238
260
echo " CURRENT_SYSTEM: $CURRENT_SYSTEM "
239
261
if [ -f " ./db/schema.sql" ]; then
0 commit comments