File size: 1,655 Bytes
79becd2
 
 
6ff9480
a603a7e
 
 
79becd2
 
6ff9480
79becd2
77a2880
 
 
 
a603a7e
 
79becd2
 
 
a603a7e
77a2880
79becd2
77a2880
6ff9480
77a2880
 
 
79becd2
 
77a2880
79becd2
 
 
 
 
 
 
 
 
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
38
39
40
#!/bin/sh

# Create necessary directories in the persistent /data volume
echo "Creating necessary directories in the persistent /data volume..."
su postgres -c "mkdir -p /data/postgresql/data /data/postgresql/run"
su postgres -c "chmod 0700 /data/postgresql/data"
su postgres -c "chmod 0755 /data/postgresql/run"

# Initialize PostgreSQL if not already initialized
echo "Initializing PostgreSQL if not already initialized..."
if [ ! -f "/data/postgresql/data/PG_VERSION" ]; then
    # Initialize as postgres user
    su postgres -c "initdb -D /data/postgresql/data"
    
    # Modify pg_hba.conf to allow local connections
    su postgres -c "echo 'local all all trust' > /data/postgresql/data/pg_hba.conf"
    su postgres -c "echo 'host all all 127.0.0.1/32 trust' >> /data/postgresql/data/pg_hba.conf"
fi

# Start PostgreSQL with the persistent directories
echo "Starting PostgreSQL..."
su postgres -c "pg_ctl -D /data/postgresql/data -o '-c listen_addresses=*' -o '-c unix_socket_directories=/data/postgresql/run' start"

# Create database and roles
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

# Wait for PostgreSQL to be ready
until su postgres -c "pg_isready -h /data/postgresql/run"; do
  echo "Waiting for PostgreSQL to be ready..."
  sleep 1
done

# Update DATABASE_URL to use the correct socket directory
export DATABASE_URL="postgresql://postgres:postgres@%2Fdata%2Fpostgresql%2Frun:5432/postgres"

# Run the original entrypoint script
./web/entrypoint.sh node ./web/server.js --keepAliveTimeout 110000