-
Notifications
You must be signed in to change notification settings - Fork 147
/
run.sh
executable file
·137 lines (110 loc) · 3.33 KB
/
run.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/sh
##
# Run OpenStreetMap tile server operations
#
# Command prefix that runs the command as the web user
asweb="setuser www-data"
die () {
msg=$1
echo "FATAL ERROR: " msg > 2
exit
}
_startservice () {
sv start $1 || die "Could not start $1"
}
startdb () {
_startservice postgresql
}
initdb () {
echo "Initialising postgresql"
if [ -d /var/lib/postgresql/9.3/main ] && [ $( ls -A /var/lib/postgresql/9.3/main | wc -c ) -ge 0 ]
then
die "Initialisation failed: the directory is not empty: /var/lib/postgresql/9.3/main"
fi
mkdir -p /var/lib/postgresql/9.3/main && chown -R postgres /var/lib/postgresql/
sudo -u postgres -i /usr/lib/postgresql/9.3/bin/initdb --pgdata /var/lib/postgresql/9.3/main
ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /var/lib/postgresql/9.3/main/server.crt
ln -s /etc/ssl/private/ssl-cert-snakeoil.key /var/lib/postgresql/9.3/main/server.key
}
createuser () {
USER=www-data
echo "Creating user $USER"
setuser postgres createuser -s $USER
}
createdb () {
dbname=gis
echo "Creating database $dbname"
cd /var/www
# Create the database
setuser postgres createdb -O www-data $dbname
# Install the Postgis schema
$asweb psql -d $dbname -f /usr/share/postgresql/9.3/contrib/postgis-2.1/postgis.sql
$asweb psql -d $dbname -c 'CREATE EXTENSION HSTORE;'
# Set the correct table ownership
$asweb psql -d $dbname -c 'ALTER TABLE geometry_columns OWNER TO "www-data"; ALTER TABLE spatial_ref_sys OWNER TO "www-data";'
# Add the 900913 Spatial Reference System
$asweb psql -d $dbname -f /usr/local/share/osm2pgsql/900913.sql
}
import () {
# Find the most recent import.pbf or import.osm
import=$( ls -1t /data/import.pbf /data/import.osm 2>/dev/null | head -1 )
test -n "${import}" || \
die "No import file present: expected /data/import.osm or /data/import.pbf"
echo "Importing ${import} into gis"
echo "$OSM_IMPORT_CACHE" | grep -P '^[0-9]+$' || \
die "Unexpected cache type: expected an integer but found: ${OSM_IMPORT_CACHE}"
number_processes=`nproc`
# Limit to 8 to prevent overwhelming pg with connections
if test $number_processes -ge 8
then
number_processes=8
fi
$asweb osm2pgsql --slim --hstore --cache $OSM_IMPORT_CACHE --database gis --number-processes $number_processes $import
}
dropdb () {
echo "Dropping database"
cd /var/www
setuser postgres dropdb gis
}
cli () {
echo "Running bash"
cd /var/www
exec bash
}
startservices () {
_startservice renderd
_startservice apache2
}
help () {
cat /usr/local/share/doc/run/help.txt
}
_wait () {
WAIT=$1
NOW=`date +%s`
BOOT_TIME=`stat -c %X /etc/container_environment.sh`
UPTIME=`expr $NOW - $BOOT_TIME`
DELTA=`expr 5 - $UPTIME`
if [ $DELTA -gt 0 ]
then
sleep $DELTA
fi
}
# Unless there is a terminal attached wait until 5 seconds after boot
# when runit will have started supervising the services.
if ! tty --silent
then
_wait 5
fi
# Execute the specified command sequence
for arg
do
$arg;
done
# Unless there is a terminal attached don't exit, otherwise docker
# will also exit
if ! tty --silent
then
# Wait forever (see
# http://unix.stackexchange.com/questions/42901/how-to-do-nothing-forever-in-an-elegant-way).
tail -f /dev/null
fi