|
#!/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 |
|
|
|
su postgres -c "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 |
|
fi |
|
|
|
|
|
echo "Ensuring proper ownership..." |
|
chown -R postgres:postgres /data/postgresql/data /data/postgresql/run |
|
|
|
|
|
echo "Starting PostgreSQL with the persistent directories..." |
|
su postgres -c "pg_ctl -D /data/postgresql/data -o '-c listen_addresses=*' -o '-c unix_socket_directories=/data/postgresql/run' start" |
|
|
|
|
|
echo "Creating database and roles..." |
|
su postgres -c "createuser -s postgres" || true |
|
su postgres -c "createuser -s node" || true |
|
su postgres -c "createdb -U postgres postgres" || true |
|
|
|
|
|
until su postgres -c "pg_isready -h /data/postgresql/run"; do |
|
echo "Waiting for PostgreSQL to be ready..." |
|
sleep 1 |
|
done |
|
|
|
|
|
export DATABASE_URL="postgresql://postgres:postgres@%2Fdata%2Fpostgresql%2Frun:5432/postgres" |
|
|
|
|
|
./web/entrypoint.sh node ./web/server.js --keepAliveTimeout 110000 |