@@ -15,39 +15,36 @@ CURRENT_SYSTEM="@CURRENT_SYSTEM@"
15
15
ANSIBLE_VARS=" @ANSIBLE_VARS@"
16
16
PGBOUNCER_AUTH_SCHEMA_SQL=@PGBOUNCER_AUTH_SCHEMA_SQL@
17
17
STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@
18
+ PG_PID=" "
19
+
18
20
# Cleanup function
19
21
cleanup () {
20
22
echo " Cleaning up..."
21
23
22
- # Kill postgres processes first
23
- if pgrep -f " postgres" > /dev/null; then
24
- pkill -TERM postgres || true
24
+ # Kill postgres process using PG_PID if available
25
+ if [ -n " $PG_PID " ]; then
26
+ echo " Stopping PostgreSQL (PID: $PG_PID )..."
27
+ kill -TERM " $PG_PID " || true
25
28
sleep 2
26
29
fi
27
-
28
- # Then kill overmind
29
- if [ -S " ./.overmind.sock " ] ; then
30
- overmind kill || true
30
+
31
+ # Kill any remaining postgres processes
32
+ if pgrep -f " postgres " > /dev/null ; then
33
+ pkill -TERM postgres || true
31
34
sleep 2
35
+ # Force kill any remaining postgres processes
36
+ pkill -9 -f " postgres" || true
32
37
fi
33
38
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
37
-
38
- # Force kill any stragglers
39
- pkill -9 -f " (postgres|tmux.*overmind.*postgresql)" || true
40
-
41
- rm -f .overmind.sock Procfile
42
-
43
39
# 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
40
+ if ps aux | grep -f " postgres" | grep -v grep > /dev/null; then
41
+ ps aux | grep -f " postgres" | grep -v grep
46
42
return 1
47
43
fi
48
44
}
49
45
50
46
# Set up trap for cleanup on script exit
47
+ trap cleanup EXIT
51
48
52
49
# Function to display help
53
50
print_help () {
@@ -175,62 +172,42 @@ trim_schema() {
175
172
;;
176
173
esac
177
174
}
178
- overmind_start () {
179
- cat > Procfile << EOF
180
- postgres_${PSQL_VERSION} : exec nix run "$FLAKE_URL #start-server" -- "$PSQL_VERSION " --skip-migrations
181
- EOF
182
- overmind start -D
183
- echo " Waiting for overmind socket..."
184
- max_wait=5
185
- count=0
186
- while [ $count -lt $max_wait ]; do
187
- if [ -S " ./.overmind.sock" ]; then
188
- # Found the socket, give it a moment to be ready
189
- sleep 5
190
- echo " Socket file found and ready"
191
- break
192
- fi
193
- echo " Waiting for socket file (attempt $count /$max_wait )"
194
- sleep 1
195
- count=$(( count + 1 ))
196
- done
197
- }
198
- perform_dump () {
199
- local max_attempts=3
200
- local attempt=1
201
-
202
- while [ $attempt -le $max_attempts ]; do
203
- echo " Attempting dbmate dump (attempt $attempt /$max_attempts )"
204
-
205
- if dbmate dump; then
206
- return 0
207
- fi
208
-
209
- echo " Dump attempt $attempt failed, waiting before retry..."
210
- sleep 5
211
- attempt=$(( attempt + 1 ))
212
- done
213
-
214
- echo " All dump attempts failed"
215
- return 1
175
+
176
+ # Start postgres function
177
+ start_postgres () {
178
+ echo " Starting PostgreSQL server version $PSQL_VERSION ..."
179
+ nix run " $FLAKE_URL #start-server" -- " $PSQL_VERSION " --skip-migrations &
180
+ PG_PID=$!
181
+ echo " PostgreSQL started with PID: $PG_PID "
182
+
183
+ # Give postgres a moment to start
184
+ sleep 2
185
+
186
+ # Check if process is still running
187
+ if ! kill -0 " $PG_PID " 2> /dev/null; then
188
+ echo " PostgreSQL failed to start"
189
+ PG_PID=" "
190
+ return 1
191
+ fi
216
192
}
193
+
217
194
migrate_version () {
218
195
echo " PSQL_VERSION: $PSQL_VERSION "
219
- overmind kill || true
220
- rm -f .overmind.sock Procfile || true
221
196
PSQLBIN=$( nix build --no-link " $FLAKE_URL #psql_$PSQL_VERSION /bin" --json | jq -r ' .[].outputs.out + "/bin"' )
222
197
echo " Using PostgreSQL version $PSQL_VERSION from $PSQLBIN "
223
198
224
- # Start overmind
225
- overmind_start
226
- echo " Waiting for overmind socket..."
227
-
199
+ # Start PostgreSQL
200
+ if ! start_postgres; then
201
+ echo " Failed to start PostgreSQL server"
202
+ exit 1
203
+ fi
228
204
229
205
echo " Waiting for PostgreSQL to be ready..."
230
206
231
- # Wait for PostgreSQL to be ready to accept connections
207
+ # Wait for PostgreSQL to be ready to accept connections
232
208
if ! wait_for_postgres; then
233
209
echo " Failed to connect to PostgreSQL server"
210
+ cleanup
234
211
exit 1
235
212
fi
236
213
0 commit comments