-
-
Save funkotron/6043379 to your computer and use it in GitHub Desktop.
Modified init script to keep existing password if arg given and keep existing /data dir if non empty for persistence of database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
mkdir -p /usr/share/zoneinfo /data | |
chown default /data | |
if [ $# -eq 1 ] | |
then | |
echo $1 > /pwfile | |
else | |
head -c 16 /dev/urandom | sha1sum | cut -c1-10 > /pwfile | |
fi | |
echo "PG_PASSWORD=$(cat /pwfile)" | |
if [ ! "$(ls -A /data)" ]; then | |
#/data is empty | |
su default -s /usr/bin/initdb -- --pgdata=/data --pwfile=/pwfile --username=postgres --auth=trust >/dev/null | |
fi | |
echo host all all 0.0.0.0 0.0.0.0 md5 >> /data/pg_hba.conf | |
exec su default -s /usr/bin/postgres -- -D /data -c 'listen_addresses=*' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment