-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-postgres.sh
More file actions
executable file
·54 lines (45 loc) · 1.98 KB
/
init-postgres.sh
File metadata and controls
executable file
·54 lines (45 loc) · 1.98 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash -e
chown -R postgres:docker-machines /var/lib/postgresql/{data,conf}
if [ -d /run/postgresql ]; then
chmod g+s /run/postgresql
chown -R postgres:docker-machines /run/postgresql
fi
if [ -s /var/lib/postgresql/conf/patroni.yml ]; then
echo "Patroni configuration detected. Starting patroni"
exec gosu postgres:docker-machines patroni /var/lib/postgresql/conf/patroni.yml
fi
echo "Patroni configuration '/var/lib/postgresql/conf/patroni.yml' missing. Runing as a standalone instance"
if [ ! -s "/var/lib/postgresql/data/PG_VERSION" ]; then
echo "initializing a new database"
gosu postgres:docker-machines /usr/lib/postgresql/*/bin/initdb \
-D /var/lib/postgresql/data \
--encoding 'UTF-8' \
--lc-collate='en_US.UTF-8' \
--lc-ctype='en_US.UTF-8' \
--allow-group-access \
--no-instructions
rm /var/lib/postgresql/data/{postgresql.conf,pg_hba.conf,pg_ident.conf}
gosu postgres:docker-machines /usr/lib/postgresql/*/bin/pg_ctl -s \
-D "/var/lib/postgresql/data" \
-o "-c listen_addresses='127.0.0.1'" \
-o "-c config_file=/var/lib/postgresql/conf/postgresql.conf" \
-w start
psql=( psql -v ON_ERROR_STOP=1 --username "postgres" --dbname "postgres" )
for f in /sql-init.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${psql[@]}" < "$f"; echo ;;
/sql-init.d/*) echo "no scripts found in /sql-init.d/" ;;
*) echo "$0: ignoring $f" ;;
esac
done
gosu postgres:docker-machines /usr/lib/postgresql/*/bin/pg_ctl -s \
-D "/var/lib/postgresql/data" \
-o "-c config_file=/var/lib/postgresql/conf/postgresql.conf" \
-m fast \
-w stop
echo
echo 'PostgreSQL init process complete; ready for start up.'
echo
fi
exec gosu postgres:docker-machines /usr/lib/postgresql/*/bin/postgres -c config_file=/var/lib/postgresql/conf/postgresql.conf