Skip to content

Commit 2b99b04

Browse files
committed
chore: do not run pg with overmin, just pg_ctl in daemon mode
1 parent 84e8c04 commit 2b99b04

File tree

2 files changed

+35
-41
lines changed

2 files changed

+35
-41
lines changed

flake.nix

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,6 @@
437437
in
438438
pkgs.runCommand "start-postgres-server" {
439439
inherit migrationsDir postgresqlSchemaSql pgbouncerAuthSchemaSql statExtensionSql;
440-
nativeBuildInputs = with pkgs; [
441-
overmind
442-
];
443440
} ''
444441
mkdir -p $out/bin $out/etc/postgresql-custom $out/etc/postgresql $out/extension-custom-scripts
445442
cp ${supautilsConfigFile} $out/etc/postgresql-custom/supautils.conf || { echo "Failed to copy supautils.conf"; exit 1; }
@@ -455,7 +452,6 @@
455452
chmod 644 $out/etc/postgresql-custom/logging.conf
456453
chmod 644 $out/etc/postgresql/pg_hba.conf
457454
substitute ${./nix/tools/run-server.sh.in} $out/bin/start-postgres-server \
458-
--subst-var-by 'OVERMIND' '${pkgs.overmind}/bin/overmind' \
459455
--subst-var-by 'PGSQL_DEFAULT_PORT' '${pgsqlDefaultPort}' \
460456
--subst-var-by 'PGSQL_SUPERUSER' '${pgsqlSuperuser}' \
461457
--subst-var-by 'PSQL15_BINDIR' '${basePackages.psql_15.bin}' \
@@ -612,7 +608,7 @@
612608
pkgs.runCommand "postgres-${pgpkg.version}-check-harness"
613609
{
614610
nativeBuildInputs = with pkgs; [
615-
coreutils bash pgpkg pg_prove pg_regress procps overmind
611+
coreutils bash pgpkg pg_prove pg_regress procps
616612
basePackages.start-server
617613
];
618614
} ''

nix/tools/run-server.sh.in

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,21 @@ print_help() {
2222
echo "PORT is optional (default: @PGSQL_DEFAULT_PORT@)"
2323
}
2424

25-
cleanup() {
26-
echo "Shutting down PostgreSQL..."
27-
@OVERMIND@ quit
28-
# Wait for overmind processes to exit
29-
while ps -ef | grep "[o]vermind.*Procfile" > /dev/null; do
30-
sleep 0.1
31-
done
32-
exit $1
25+
start_postgres() {
26+
local mode=$1
27+
if [ "$mode" = "daemon" ]; then
28+
pg_ctl start -D "$DATDIR" -l "$DATDIR/logfile" -o "--config-file=$DATDIR/postgresql.conf -p $PORTNO -k $DATDIR/tmp"
29+
else
30+
# Foreground mode
31+
exec postgres --config-file="$DATDIR/postgresql.conf" -p "$PORTNO" -D "$DATDIR" -k "/tmp" -F
32+
fi
33+
}
34+
35+
stop_postgres() {
36+
pg_ctl stop -D "$DATDIR" -m fast
3337
}
3438

35-
trap cleanup SIGINT SIGTERM
39+
trap 'stop_postgres' SIGINT SIGTERM
3640

3741
# Parse arguments
3842
while [[ "$#" -gt 0 ]]; do
@@ -204,13 +208,15 @@ orioledb_config_items "$VERSION"
204208
export GRN_PLUGINS_DIR=$GROONGA/lib/groonga/plugins
205209

206210
# Create Procfile for postgres only
207-
mkdir -p "$DATDIR/tmp"
208-
cat > "$DATDIR/Procfile" << EOL
209-
postgres: exec postgres --config-file="$DATDIR/postgresql.conf" -p "$PORTNO" -D "$DATDIR" -k "$DATDIR/tmp" -F
210-
EOL
211+
# mkdir -p "$DATDIR/tmp"
212+
# cat > "$DATDIR/Procfile" << EOL
213+
# postgres: exec postgres --config-file="$DATDIR/postgresql.conf" -p "$PORTNO" -D "$DATDIR" -k "$DATDIR/tmp" -F
214+
# EOL
211215

212-
# Start postgres with overmind
213-
@OVERMIND@ start -f "$DATDIR/Procfile" --daemonize --socket "$DATDIR/.overmind.sock"
216+
# Start postgres
217+
mkdir -p "$DATDIR/tmp"
218+
chmod 1777 "$DATDIR/tmp"
219+
start_postgres "daemon"
214220

215221
# Wait for PostgreSQL to start
216222
for i in {1..60}; do
@@ -221,7 +227,7 @@ for i in {1..60}; do
221227
sleep 1
222228
if [ $i -eq 60 ]; then
223229
echo "PostgreSQL failed to start"
224-
cleanup 1
230+
'stop_postgres' 1
225231
fi
226232
done
227233

@@ -238,64 +244,56 @@ if [ "$SKIP_MIGRATIONS" = false ]; then
238244
alter database postgres owner to postgres;
239245
EOSQL
240246
then
241-
cleanup 1
247+
'stop_postgres' 1
242248
fi
243249

244250
if [ -n "$MIGRATION_FILE" ]; then
245251
echo "Running user-provided migration file $MIGRATION_FILE"
246252
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -f "$MIGRATION_FILE" postgres; then
247-
cleanup 1
253+
'stop_postgres' 1
248254
fi
249255
else
250256
# Run default init scripts
251257
for sql in "$MIGRATIONS_DIR"/init-scripts/*.sql; do
252258
echo "Running $sql"
253259
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PSQL_USER" -p "$PORTNO" -h localhost -f "$sql" postgres; then
254-
cleanup 1
260+
'stop_postgres' 1
255261
fi
256262
done
257263

258264
# Set superuser password
259265
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PSQL_USER" -p "$PORTNO" -h localhost -c "ALTER USER supabase_admin WITH PASSWORD '$PGPASSWORD'"; then
260-
cleanup 1
266+
'stop_postgres' 1
261267
fi
262268

263269
# Run additional schema files
264270
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PSQL_USER" -p "$PORTNO" -h localhost -d postgres -f "$PGBOUNCER_AUTH_SCHEMA_SQL"; then
265-
cleanup 1
271+
'stop_postgres' 1
266272
fi
267273
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PSQL_USER" -p "$PORTNO" -h localhost -d postgres -f "$STAT_EXTENSION_SQL"; then
268-
cleanup 1
274+
'stop_postgres' 1
269275
fi
270276

271277
# Run migrations as superuser
272278
for sql in "$MIGRATIONS_DIR"/migrations/*.sql; do
273279
echo "Running $sql"
274280
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -f "$sql" postgres; then
275-
cleanup 1
281+
'stop_postgres' 1
276282
fi
277283
done
278284

279285
# Run PostgreSQL schema
280286
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -f "$POSTGRESQL_SCHEMA_SQL" postgres; then
281-
cleanup 1
287+
'stop_postgres' 1
282288
fi
283289
fi
284290
fi
285291
echo "Shutting down PostgreSQL..."
286-
@OVERMIND@ quit --socket "$DATDIR/.overmind.sock" # This stops the PostgreSQL process
287-
288-
# Wait for Overmind to clean up and shut down completely
289-
while ps -ef | grep -E "[o]vermind.*Procfile" > /dev/null; do
290-
sleep 0.1
291-
done
292+
stop_postgres
292293

293-
# Step 4: Restart PostgreSQL in the foreground (with log output visible)
294+
# Step 4: Restart PostgreSQL in the foreground (with log output visible) or as a daemon
294295
if [ "$DAEMONIZE" = true ]; then
295-
echo "Starting PostgreSQL $VERSIOn in daemon mode..."
296-
@OVERMIND@ start -f "$DATDIR/Procfile" --daemonize --socket "$DATDIR/.overmind.sock"
297-
echo "PostgreSQL $VERSION is running in daemon mode. Use overmind connect to view logs."
296+
start_postgres "daemon"
298297
else
299-
echo "Starting PostgreSQL $VERSION in foreground mode, use Ctrl+C to stop ..."
300-
exec @OVERMIND@ start -f "$DATDIR/Procfile" --socket "$DATDIR/.overmind.sock"
298+
start_postgres "foreground"
301299
fi

0 commit comments

Comments
 (0)