Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB tries to init every time, throws error #26

Open
jkottler opened this issue Sep 12, 2024 · 0 comments
Open

DB tries to init every time, throws error #26

jkottler opened this issue Sep 12, 2024 · 0 comments

Comments

@jkottler
Copy link

jkottler commented Sep 12, 2024

Error reports that /var/lib/postgresql/data/ is present but not empty, refuses to start the db.

I have been using a container with this feature for months with no problem up until the last week or so, at which point the problem raised its head.

A little digging made me suspect the pq-init.sh entrypoint file.

I can't push a branch and submit a PR. So the change I implemented in install.sh is pasted below:

setup_pq() {
    tee /usr/local/share/pq-init.sh << 'EOF'
#!/bin/sh
set -e

version_major=$(psql --version | sed -z "s/psql (PostgreSQL) //g" | grep -Eo -m 1 "^([0-9]+)" | sed -z "s/-//g")

if [ ! -f "$PGDATA/PG_VERSION" ]; then
    echo "Initializing PostgreSQL database..."
    chown -R postgres:postgres $PGDATA \
        && chmod 0750 $PGDATA \
        && echo "listen_addresses = '*'" >> /etc/postgresql/${version_major}/main/postgresql.conf \
        && echo "data_directory = '$PGDATA'" >> /etc/postgresql/${version_major}/main/postgresql.conf \
        && echo "host   all all 0.0.0.0/0        trust" > /etc/postgresql/${version_major}/main/pg_hba.conf \
        && echo "host   all all ::/0             trust" >> /etc/postgresql/${version_major}/main/pg_hba.conf \
        && echo "host   all all ::1/128          trust" >> /etc/postgresql/${version_major}/main/pg_hba.conf \
        && sudo -H -u postgres sh -c "/usr/lib/postgresql/${version_major}/bin/initdb -D $PGDATA --auth-local trust --auth-host scram-sha-256"
else
    echo "PostgreSQL database already initialized, skipping initialization"
fi

echo "Starting PostgreSQL..."
sudo /etc/init.d/postgresql start \
    && pg_isready -t 60

set +e

# Execute whatever commands were passed in (if any). This allows us
# to set this script to ENTRYPOINT while still executing the default CMD.
exec "$@"
EOF
    chmod +x /usr/local/share/pq-init.sh \
        && chown ${USERNAME}:root /usr/local/share/pq-init.sh
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant