-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_entrypoint.sh
More file actions
37 lines (27 loc) · 1007 Bytes
/
batch_entrypoint.sh
File metadata and controls
37 lines (27 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
set -e
echo "Starting as user: $(whoami)"
echo "PGDATA location: $PGDATA"
echo "Starting PostgreSQL initialization and job as postgres user..."
# Set PGDATA if not set
export PGDATA=${PGDATA:-/var/lib/postgresql/data}
# Initialize PostgreSQL if needed
if [ ! -s "$PGDATA/PG_VERSION" ]; then
echo "Initializing PostgreSQL database..."
initdb --auth-host=trust --auth-local=trust
fi
echo "Starting PostgreSQL in background..."
# Start PostgreSQL in background
pg_ctl -D "$PGDATA" -o "-c listen_addresses='localhost' -c port=5432" -w start
echo "PostgreSQL started. Waiting for it to be ready..."
until pg_isready -h localhost -p 5432; do
echo "Waiting for PostgreSQL to be ready..."
sleep 2
done
echo "PostgreSQL is ready. Starting database sanitization..."
# Run your sanitization script
cd /home/app
bash /home/app/scrubbed_database.sh
echo "Sanitization complete. Shutting down PostgreSQL..."
pg_ctl -D "$PGDATA" -m fast -w stop
echo "Container job finished successfully."