|
#!/bin/sh |
|
|
|
|
|
echo "Creating necessary directories in the persistent /data volume..." |
|
mkdir -p /data/postgresql/data /data/postgresql/run |
|
chmod 0700 /data/postgresql/data |
|
chmod 0755 /data/postgresql/run |
|
|
|
|
|
echo "Initializing PostgreSQL if not already initialized..." |
|
if [ ! -f "/data/postgresql/data/PG_VERSION" ]; then |
|
|
|
echo "Initializing database..." |
|
initdb -D /data/postgresql/data |
|
|
|
|
|
echo "local all all trust" > /data/postgresql/data/pg_hba.conf |
|
echo "host all all 127.0.0.1/32 trust" >> /data/postgresql/data/pg_hba.conf |
|
echo "host all all 0.0.0.0/0 trust" >> /data/postgresql/data/pg_hba.conf |
|
fi |
|
|
|
|
|
echo "Starting PostgreSQL..." |
|
|
|
if [ -f "/data/postgresql/data/postmaster.pid" ]; then |
|
pid=$(cat /data/postgresql/data/postmaster.pid | head -1) |
|
if ! kill -0 "$pid" 2>/dev/null; then |
|
echo "Removing stale PID file..." |
|
rm /data/postgresql/data/postmaster.pid |
|
fi |
|
fi |
|
|
|
pg_ctl -D /data/postgresql/data -o "-c listen_addresses='*' -c unix_socket_directories='/data/postgresql/run'" start |
|
|
|
|
|
echo "Creating 'node' database if it doesn't exist..." |
|
createdb -h localhost node || true |
|
|
|
|
|
echo "Waiting for PostgreSQL to be ready..." |
|
until pg_isready -h localhost; do |
|
echo "Waiting for PostgreSQL to be ready..." |
|
sleep 1 |
|
done |
|
|
|
|
|
export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/node" |
|
|
|
|
|
./web/entrypoint.sh node ./web/server.js --keepAliveTimeout 110000 |