Skip to content

Instantly share code, notes, and snippets.

@funkotron
Last active December 20, 2015 00:39
Show Gist options
  • Save funkotron/6043379 to your computer and use it in GitHub Desktop.
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
#!/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