forked from erikj/osm-tiles-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·148 lines (118 loc) · 3.84 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
138
139
140
141
142
143
144
145
146
147
148
#!/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
startdb
createuser
createdb
}
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 Spatial Reference Systems from PostGIS
$asweb psql -d $dbname -f /usr/share/postgresql/9.3/contrib/postgis-2.1/spatial_ref_sys.sql
}
import () {
startdb
# Assign from env var or find the most recent import.pbf or import.osm
import=${OSM_IMPORT_FILE:-$( ls -1t /data/import.pbf /data/import.osm 2>/dev/null | head -1 )}
test -n "${import}" || \
die "No import file present: expected specification via OSM_IMPORT_FILE or existence of /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
}
# render tiles via render_list
render () {
startdb
_startservice renderd
# wait for services to start
sleep 10
min_zoom=${OSM_MIN_ZOOM:-0}
max_zoom=${OSM_MAX_ZOOM:-8}
render_force_arg=$( [ "$OSM_RENDER_FORCE" != false ] && echo '--force' || echo '' )
number_processes=${OSM_RENDER_THREADS:-`nproc`}
# Limit to 8 to prevent overwhelming pg with connections
if test $number_processes -ge 8
then
number_processes=8
fi
echo "Rendering OSM tiles"
$asweb render_list $render_force_arg --all --min-zoom $min_zoom --max-zoom $max_zoom --num-threads $number_processes
}
dropdb () {
echo "Dropping database"
cd /var/www
setuser postgres dropdb gis
}
cli () {
echo "Running bash"
cd /var/www
exec bash
}
startservices () {
startdb
_startservice renderd
_startservice apache2
}
help () {
cat /usr/local/share/doc/run/help.txt
}
# wait until 2 seconds after boot when runit will have started supervising the services.
sleep 2
# 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