@@ -29,16 +29,18 @@ cleanup() {
29
29
fi
30
30
31
31
# Wait for Overmind to fully shut down
32
- max_wait=10
32
+ max_wait=30 # Increased from 10 to 30 seconds
33
33
count=0
34
34
while [ -S " ./.overmind.sock" ] && [ $count -lt $max_wait ]; do
35
35
echo " Waiting for Overmind socket to close (attempt $count /$max_wait )..."
36
36
sleep 1
37
37
count=$(( count + 1 ))
38
38
done
39
39
40
+ # Force remove the socket file if it still exists
40
41
if [ -S " ./.overmind.sock" ]; then
41
- echo " Warning: Overmind socket still exists after waiting"
42
+ echo " Warning: Overmind socket still exists after waiting, forcefully removing..."
43
+ rm -f ./.overmind.sock
42
44
else
43
45
echo " Overmind socket closed successfully"
44
46
fi
@@ -48,8 +50,8 @@ cleanup() {
48
50
if pgrep -f " postgres" > /dev/null; then
49
51
echo " Attempting to stop PostgreSQL gracefully..."
50
52
51
- # Try to find the PostgreSQL data directory
52
- PGDATA=$( ps aux | grep postgres | grep -v grep | grep -oP ' (?<= -D ).*?(?=\s)' )
53
+ # Improved logic to find PostgreSQL data directory
54
+ PGDATA=$( ps aux | grep postgres | grep -v grep | grep -oP ' (?<= -D ).*?(?=\s)' || true )
53
55
54
56
if [ -n " $PGDATA " ] && [ -d " $PGDATA " ]; then
55
57
# Use pg_ctl for graceful shutdown if available
@@ -58,7 +60,7 @@ cleanup() {
58
60
" ${PSQLBIN} /pg_ctl" -D " $PGDATA " stop -m smart
59
61
60
62
# Wait for PostgreSQL to shut down
61
- max_wait=30
63
+ max_wait=60 # Increased from 30 to 60 seconds
62
64
count=0
63
65
while pgrep -f " postgres" > /dev/null && [ $count -lt $max_wait ]; do
64
66
echo " Waiting for PostgreSQL to stop (attempt $count /$max_wait )..."
@@ -77,9 +79,18 @@ cleanup() {
77
79
sleep 5
78
80
fi
79
81
else
80
- echo " Warning: Could not determine PostgreSQL data directory, using signal-based shutdown"
82
+ echo " Warning: Could not determine PostgreSQL data directory, using enhanced signal-based shutdown"
83
+
84
+ # Enhanced shutdown with multiple signals
81
85
pkill -TERM postgres || true
82
86
sleep 5
87
+ if pgrep -f " postgres" > /dev/null; then
88
+ pkill -INT postgres || true
89
+ sleep 5
90
+ if pgrep -f " postgres" > /dev/null; then
91
+ pkill -KILL postgres || true
92
+ fi
93
+ fi
83
94
fi
84
95
fi
85
96
@@ -100,15 +111,20 @@ cleanup() {
100
111
echo " Warning: Some processes are still running after graceful shutdown attempts:"
101
112
ps aux | grep -E " (postgres|overmind|tmux.*postgresql)" | grep -v grep
102
113
103
- # Last resort: Use SIGINT before SIGKILL
104
- echo " Sending SIGINT to remaining processes..."
105
- pkill -INT -f " (postgres|overmind|tmux.*postgresql)" || true
114
+ # More aggressive cleanup
115
+ echo " Sending SIGTERM to remaining processes..."
116
+ pkill -TERM -f " (postgres|overmind|tmux.*postgresql)" || true
106
117
sleep 5
107
118
108
- # If processes still remain, use SIGKILL as a final measure
109
119
if ps aux | grep -E " (postgres|overmind|tmux.*postgresql)" | grep -v grep > /dev/null; then
110
- echo " Force killing remaining processes..."
111
- pkill -KILL -f " (postgres|overmind|tmux.*postgresql)" || true
120
+ echo " Sending SIGINT to remaining processes..."
121
+ pkill -INT -f " (postgres|overmind|tmux.*postgresql)" || true
122
+ sleep 5
123
+
124
+ if ps aux | grep -E " (postgres|overmind|tmux.*postgresql)" | grep -v grep > /dev/null; then
125
+ echo " Force killing remaining processes..."
126
+ pkill -KILL -f " (postgres|overmind|tmux.*postgresql)" || true
127
+ fi
112
128
fi
113
129
fi
114
130
@@ -124,7 +140,6 @@ cleanup() {
124
140
echo " Cleanup completed successfully"
125
141
fi
126
142
}
127
-
128
143
# Set up trap for cleanup on script exit
129
144
trap cleanup EXIT INT TERM
130
145
# Function to display help
0 commit comments