6
6
7
7
set -e
8
8
9
- echo " Creating /var/lib/postgresql/data/pgdata..."
10
- mkdir -p /var/lib/postgresql/data/pgdata
9
+ if [ ! -d " /var/lib/postgresql/data/pgdata" ]; then
11
10
12
- echo " Uncompressing into /var/lib/pgsql /data/pgdata..."
13
- tar -xzf /tmp/data.tar.gz -C /var/lib/postgresql/data/pgdata
11
+ echo " Creating /var/lib/postgresql /data/pgdata..."
12
+ mkdir -p /var/lib/postgresql/data/pgdata
14
13
15
- echo " Starting database ..."
16
- POSTGRES_PASSWORD=postgres /usr/local/bin/docker-entrypoint.sh postgres -c config_file=/etc/ postgresql.conf &
14
+ echo " Moving archive to target directory ..."
15
+ mv /tmp/data.tar.gz /var/lib/ postgresql/data/pgdata/data.tar.gz
17
16
18
- echo " Waiting for database to be ready..."
19
- while ! pg_isready -U postgres -h localhost -p 5432; do
20
- sleep 1
21
- done
17
+ echo " Uncompressing into /var/lib/pgsql/data/pgdata..."
18
+ tar -xzf /var/lib/postgresql/data/pgdata/data.tar.gz -C /var/lib/postgresql/data/pgdata
22
19
23
- echo " Changing password..."
24
- if [ " $POSTGRES_PASSWORD " != " postgres" ]; then
25
- PGPASSWORD=postgres psql -c " ALTER USER postgres WITH PASSWORD '$POSTGRES_PASSWORD ';"
26
- fi
20
+ echo " Removing archive..."
21
+ rm /var/lib/postgresql/data/pgdata/data.tar.gz
22
+
23
+ echo " Starting database..."
24
+ POSTGRES_PASSWORD_FILE=" " POSTGRES_PASSWORD=postgres /usr/local/bin/docker-entrypoint.sh postgres -c config_file=/etc/postgresql.conf &
25
+
26
+ echo " Waiting for database to be ready..."
27
+ while ! pg_isready -U postgres -h localhost -p 5432; do
28
+ sleep 1
29
+ done
30
+
31
+ echo " Changing password if POSTGRES_PASSWORD is set..."
32
+ if [ -n " $POSTGRES_PASSWORD " ]; then
33
+ PGPASSWORD=postgres psql -c " ALTER USER postgres WITH PASSWORD '$POSTGRES_PASSWORD ';"
34
+ elif [ -n " $POSTGRES_PASSWORD_FILE " ]; then
35
+ PGPASSWORD=$( cat " $POSTGRES_PASSWORD_FILE " ) psql -c " ALTER USER postgres WITH PASSWORD '$POSTGRES_PASSWORD ';"
36
+ fi
27
37
28
- echo " Renaming postgres user if necessary..."
29
- if [ " $POSTGRES_USER " != " postgres" ]; then
30
- PGPASSWORD=" $POSTGRES_PASSWORD " psql -c " ALTER USER postgres RENAME TO $POSTGRES_USER ;"
38
+ echo " Renaming postgres user if necessary..."
39
+ if [ -n " $POSTGRES_USER " ]; then
40
+ if [ " $POSTGRES_USER " != " postgres" ]; then
41
+ PGPASSWORD=" $POSTGRES_PASSWORD " psql -c " ALTER USER postgres RENAME TO $POSTGRES_USER ;"
42
+ fi
43
+ fi
44
+
45
+ echo " Stopping database..."
46
+ pg_ctl -w stop
47
+
48
+ else
49
+ echo " Database already initialized. Skipping initialization..."
31
50
fi
32
51
33
- echo " Stopping database..."
34
- pg_ctl -w stop
52
+ if [ " ${ROX_SCANNER_DB_INIT} " == " true" ]; then
53
+ echo " ROX_SCANNER_DB_INIT is set to true. Exiting..."
54
+ exit 0
55
+ else
56
+ echo " Database initialized."
57
+ fi
35
58
36
59
# Now we can start the database for real. But we will
37
60
# forward any arguments to the actual entrypoint script
38
61
echo " Starting database for real..."
39
-
40
- exec /usr/local/bin/docker-entrypoint.sh " $@ "
62
+ exec /usr/local/bin/docker-entrypoint.sh " $@ "
0 commit comments