@@ -19,36 +19,49 @@ STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@
19
19
cleanup () {
20
20
echo " Cleaning up..."
21
21
22
- # Kill postgres processes first
22
+ # First, gracefully stop Overmind if it's running
23
+ if [ -S " ./.overmind.sock" ]; then
24
+ echo " Stopping Overmind gracefully..."
25
+ overmind quit || true
26
+ sleep 5 # Give Overmind time to shut down
27
+ fi
28
+
29
+ # Stop PostgreSQL processes gracefully
23
30
if pgrep -f " postgres" > /dev/null; then
31
+ echo " Stopping PostgreSQL gracefully..."
24
32
pkill -TERM postgres || true
25
- sleep 2
33
+ sleep 5 # Wait for PostgreSQL to shut down
26
34
fi
27
35
28
- # Then kill overmind
29
- if [ -S " ./.overmind.sock" ]; then
30
- overmind kill || true
36
+ # Clean up any remaining tmux sessions
37
+ if tmux ls 2> /dev/null | grep ' overmind' ; then
38
+ echo " Cleaning up tmux sessions..."
39
+ tmux ls 2> /dev/null | grep ' overmind' | cut -d: -f1 | xargs -I{} tmux kill-session -t {} || true
31
40
sleep 2
32
41
fi
33
42
34
- # Kill tmux sessions explicitly
35
- pkill -f " tmux.*overmind.*postgresql" || true
36
- tmux ls 2> /dev/null | grep ' overmind' | cut -d: -f1 | xargs -I{} tmux kill-session -t {} || true
43
+ # Final cleanup: Force kill if necessary (as a last resort)
44
+ if ps aux | grep -E " (postgres|overmind|tmux.*postgresql)" | grep -v grep > /dev/null; then
45
+ echo " Force killing remaining processes..."
46
+ pkill -9 -f " (postgres|overmind|tmux.*postgresql)" || true
47
+ sleep 2
48
+ fi
37
49
38
- # Force kill any stragglers
39
- pkill -9 -f " (postgres|tmux.*overmind.*postgresql)" || true
40
-
50
+ # Remove socket and Procfile
41
51
rm -f .overmind.sock Procfile
42
52
43
- # Final verification
53
+ # Verify cleanup
44
54
if ps aux | grep -E " (postgres|overmind|tmux.*postgresql)" | grep -v grep > /dev/null; then
55
+ echo " Warning: Some processes could not be cleaned up:"
45
56
ps aux | grep -E " (postgres|overmind|tmux.*postgresql)" | grep -v grep
46
57
return 1
58
+ else
59
+ echo " Cleanup completed successfully"
47
60
fi
48
61
}
49
62
50
63
# Set up trap for cleanup on script exit
51
-
64
+ trap cleanup EXIT INT TERM
52
65
# Function to display help
53
66
print_help () {
54
67
echo " Usage: nix run .#dbmate-tool -- [options]"
0 commit comments