@@ -22,17 +22,21 @@ print_help() {
22
22
echo " PORT is optional (default: @PGSQL_DEFAULT_PORT@)"
23
23
}
24
24
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
33
37
}
34
38
35
- trap cleanup SIGINT SIGTERM
39
+ trap ' stop_postgres ' SIGINT SIGTERM
36
40
37
41
# Parse arguments
38
42
while [[ " $# " -gt 0 ]]; do
@@ -204,13 +208,15 @@ orioledb_config_items "$VERSION"
204
208
export GRN_PLUGINS_DIR=$GROONGA /lib/groonga/plugins
205
209
206
210
# 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
211
215
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"
214
220
215
221
# Wait for PostgreSQL to start
216
222
for i in {1..60}; do
@@ -221,7 +227,7 @@ for i in {1..60}; do
221
227
sleep 1
222
228
if [ $i -eq 60 ]; then
223
229
echo " PostgreSQL failed to start"
224
- cleanup 1
230
+ ' stop_postgres ' 1
225
231
fi
226
232
done
227
233
@@ -238,64 +244,56 @@ if [ "$SKIP_MIGRATIONS" = false ]; then
238
244
alter database postgres owner to postgres;
239
245
EOSQL
240
246
then
241
- cleanup 1
247
+ ' stop_postgres ' 1
242
248
fi
243
249
244
250
if [ -n " $MIGRATION_FILE " ]; then
245
251
echo " Running user-provided migration file $MIGRATION_FILE "
246
252
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
248
254
fi
249
255
else
250
256
# Run default init scripts
251
257
for sql in " $MIGRATIONS_DIR " /init-scripts/* .sql; do
252
258
echo " Running $sql "
253
259
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
255
261
fi
256
262
done
257
263
258
264
# Set superuser password
259
265
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
261
267
fi
262
268
263
269
# Run additional schema files
264
270
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
266
272
fi
267
273
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
269
275
fi
270
276
271
277
# Run migrations as superuser
272
278
for sql in " $MIGRATIONS_DIR " /migrations/* .sql; do
273
279
echo " Running $sql "
274
280
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
276
282
fi
277
283
done
278
284
279
285
# Run PostgreSQL schema
280
286
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
282
288
fi
283
289
fi
284
290
fi
285
291
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
292
293
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
294
295
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"
298
297
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"
301
299
fi
0 commit comments