forked from mapcentia/dockerfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
107 lines (94 loc) · 4.07 KB
/
entrypoint.sh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
set -e
export PGUSER=gc2
if [ $1 == "/usr/bin/supervisord" ]; then
# Start service so we can create GC2 system tables and users.
service postgresql start
# But first we check if they are created. I.e. if the container is restarted
if echo 'SELECT 1' | psql postgres >/dev/null 2>&1; then
echo "GC2 system already initiated"
echo "
****************************************************
INFO: GC2 system already initiated.
Doing nothing else than start the service.
****************************************************"
# Stop the service, so it can be started in foreground.
service postgresql stop
else
# First run
# Set time zone if passed
if [ -n "$TIMEZONE" ]; then
# OS
ln -snf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
echo $TIMEZONE > /etc/timezone
# PGSQL
echo "timezone = '$TIMEZONE'" >> /etc/postgresql/9.6/main/postgresql.conf
fi
if [ -n "$GC2_PASSWORD" ]; then
echo "Password set"
else
echo "
****************************************************
ERROR: No password has been set for the GC2 user.
Use "-e GC2_PASSWORD=password" to set it.
****************************************************"
exit 1
fi
if [ -n "$LOCALE" ]; then
locale=$LOCALE
else
locale=en_US.UTF-8
echo "
****************************************************
WARNING: No locale has been set for the GC2
template db. Setting it to en_US.UTF-8.
Use "-e locale=your_locale" to set it.
****************************************************"
fi
# Create template database and run latest migrations
echo "Creating GC2 template database and user $PGUSER"
psql postgres -U postgres -c "CREATE USER $PGUSER WITH SUPERUSER CREATEROLE CREATEDB PASSWORD '$GC2_PASSWORD'" &&\
createdb template_geocloud -T template0 --encoding UTF-8 --locale $locale &&\
psql template_geocloud -c "create extension postgis" &&\
psql template_geocloud -c "create extension pgcrypto" &&\
psql template_geocloud -c "create extension pgrouting" &&\
psql template_geocloud -f /var/www/geocloud2/public/install/geometry_columns_join.sql &&\
# Create the user database
createdb mapcentia &&\
psql mapcentia -c "CREATE TABLE users\
(screenname character varying(255),\
pw character varying(255),\
email character varying(255),\
zone character varying,\
parentdb varchar(255),\
created timestamp with time zone DEFAULT ('now'::text)::timestamp(0) with time zone)" &&\
# Create the gc2scheduler database
createdb gc2scheduler -T template0 --encoding UTF-8 --locale $locale &&\
psql gc2scheduler -c "CREATE TABLE jobs (
id serial PRIMARY KEY,
name character varying(255),
url character varying(255),
cron character varying(255),
schema character varying(255),
epsg character varying(255),
type character varying(255),
min character varying,
hour character varying,
dayofmonth character varying,
month character varying,
dayofweek character varying,
encoding character varying(255),
lastcheck boolean,
lasttimestamp timestamp with time zone,
db character varying(255),
extra character varying(255)
);" &&\
# Pull from GitHub and run database migration
cd /var/www/geocloud2 && git pull &&\
cd /var/www/geocloud2/app/conf/migration/ && ./run &&\
service postgresql stop
#Add gc2 user to pgbouncer user list
echo "\"gc2\" \"$GC2_PASSWORD\"" >> /etc/pgbouncer/userlist.txt
fi
fi
exec "$@"