-
Notifications
You must be signed in to change notification settings - Fork 483
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·156 lines (125 loc) · 5.63 KB
/
init.sh
File metadata and controls
executable file
·156 lines (125 loc) · 5.63 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
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
149
150
151
152
153
154
155
156
#!/bin/bash -ex
OSMFILE=${PROJECT_DIR}/data.osm.pbf
CURL=("curl" "-L" "-A" "${USER_AGENT}" "--fail-with-body")
SCP='sshpass -p DMg5bmLPY7npHL2Q scp -o StrictHostKeyChecking=no u355874-sub1@u355874-sub1.your-storagebox.de'
# Check if THREADS is not set or is empty
if [ -z "$THREADS" ]; then
THREADS=$(nproc)
fi
# we re-host the files on a Hetzner storage box because inconsiderate users eat up all of
# nominatim.org's bandwidth
# https://github.com/mediagis/nominatim-docker/issues/416
# https://nominatim.org/release-docs/5.2/admin/Import/#wikipediawikidata-rankings
if [ "$IMPORT_WIKIPEDIA" = "true" ]; then
echo "Downloading Wikipedia importance dump"
${SCP}:wikimedia-importance.csv.gz ${PROJECT_DIR}/wikimedia-importance.csv.gz
elif [ -f "$IMPORT_WIKIPEDIA" ]; then
# use local file if asked
ln -s "$IMPORT_WIKIPEDIA" ${PROJECT_DIR}/wikimedia-importance.csv.gz
else
echo "Skipping optional Wikipedia importance import"
fi;
if [ "$IMPORT_SECONDARY_WIKIPEDIA" = "true" ]; then
echo "Downloading Wikipedia secondary importance dump"
${SCP}:wikimedia-secondary-importance.sql.gz ${PROJECT_DIR}/secondary_importance.sql.gz
elif [ -f "$IMPORT_SECONDARY_WIKIPEDIA" ]; then
# use local file if asked
ln -s "$IMPORT_SECONDARY_WIKIPEDIA" ${PROJECT_DIR}/secondary_importance.sql.gz
else
echo "Skipping optional Wikipedia secondary importance import"
fi;
if [ "$IMPORT_GB_POSTCODES" = "true" ]; then
${SCP}:gb_postcodes.csv.gz ${PROJECT_DIR}/gb_postcodes.csv.gz
elif [ -f "$IMPORT_GB_POSTCODES" ]; then
# use local file if asked
ln -s "$IMPORT_GB_POSTCODES" ${PROJECT_DIR}/gb_postcodes.csv.gz
else \
echo "Skipping optional GB postcode import"
fi;
if [ "$IMPORT_US_POSTCODES" = "true" ]; then
${SCP}:us_postcodes.csv.gz ${PROJECT_DIR}/us_postcodes.csv.gz
elif [ -f "$IMPORT_US_POSTCODES" ]; then
# use local file if asked
ln -s "$IMPORT_US_POSTCODES" ${PROJECT_DIR}/us_postcodes.csv.gz
else
echo "Skipping optional US postcode import"
fi;
if [ "$IMPORT_TIGER_ADDRESSES" = "true" ]; then
${SCP}:tiger2024-nominatim-preprocessed.csv.tar.gz ${PROJECT_DIR}/tiger-nominatim-preprocessed.csv.tar.gz
elif [ -f "$IMPORT_TIGER_ADDRESSES" ]; then
# use local file if asked
ln -s "$IMPORT_TIGER_ADDRESSES" ${PROJECT_DIR}/tiger-nominatim-preprocessed.csv.tar.gz
else
echo "Skipping optional Tiger addresses import"
fi
if [ "$PBF_URL" != "" ]; then
echo Downloading OSM extract from "$PBF_URL"
"${CURL[@]}" "$PBF_URL" -C - --create-dirs -o $OSMFILE
fi
if [ "$PBF_PATH" != "" ]; then
echo Reading OSM extract from "$PBF_PATH"
OSMFILE=$PBF_PATH
fi
# if we use a bind mount then the PG directory is empty and we have to create it
if [ ! -f /var/lib/postgresql/16/main/PG_VERSION ]; then
chown postgres:postgres /var/lib/postgresql/16/main
sudo -u postgres /usr/lib/postgresql/16/bin/initdb -D /var/lib/postgresql/16/main
fi
# temporarily enable unsafe import optimization config
cp /etc/postgresql/16/main/conf.d/postgres-import.conf.disabled /etc/postgresql/16/main/conf.d/postgres-import.conf
sudo service postgresql start && \
sudo -E -u postgres psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='nominatim'" | grep -q 1 || sudo -E -u postgres createuser -s nominatim && \
sudo -E -u postgres psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='www-data'" | grep -q 1 || sudo -E -u postgres createuser -SDR www-data && \
sudo -E -u postgres psql postgres -tAc "ALTER USER nominatim WITH ENCRYPTED PASSWORD '$NOMINATIM_PASSWORD'" && \
sudo -E -u postgres psql postgres -tAc "ALTER USER \"www-data\" WITH ENCRYPTED PASSWORD '${NOMINATIM_PASSWORD}'" && \
sudo -E -u postgres psql postgres -c "DROP DATABASE IF EXISTS nominatim"
chown -R nominatim:nominatim ${PROJECT_DIR}
cd ${PROJECT_DIR}
if [ "$REVERSE_ONLY" = "true" ]; then
sudo -E -u nominatim nominatim import --osm-file $OSMFILE --threads $THREADS --reverse-only
else
sudo -E -u nominatim nominatim import --osm-file $OSMFILE --threads $THREADS
fi
if [ -f tiger-nominatim-preprocessed.csv.tar.gz ]; then
echo "Importing Tiger address data"
sudo -E -u nominatim nominatim add-data --tiger-data tiger-nominatim-preprocessed.csv.tar.gz
fi
# Sometimes Nominatim marks parent places to be indexed during the initial
# import which leads to '123 entries are not yet indexed' errors in --check-database
# Thus another quick additional index here for the remaining places
sudo -E -u nominatim nominatim index --threads $THREADS
sudo -E -u nominatim nominatim admin --check-database
if [ "$REPLICATION_URL" != "" ]; then
sudo -E -u nominatim nominatim replication --init
if [ "$FREEZE" = "true" ]; then
echo "Skipping freeze because REPLICATION_URL is not empty"
fi
else
if [ "$FREEZE" = "true" ]; then
echo "Freezing database"
sudo -E -u nominatim nominatim freeze
fi
fi
export NOMINATIM_QUERY_TIMEOUT=600
export NOMINATIM_REQUEST_TIMEOUT=3600
if [ "$REVERSE_ONLY" = "true" ]; then
sudo -H -E -u nominatim nominatim admin --warm --reverse
else
sudo -H -E -u nominatim nominatim admin --warm
fi
export NOMINATIM_QUERY_TIMEOUT=10
export NOMINATIM_REQUEST_TIMEOUT=60
# gather statistics for query planner to potentially improve query performance
# see, https://github.com/osm-search/Nominatim/issues/1023
# and https://github.com/osm-search/Nominatim/issues/1139
sudo -E -u nominatim psql -d nominatim -c "ANALYZE VERBOSE"
sudo service postgresql stop
# Remove slightly unsafe postgres config overrides that made the import faster
rm /etc/postgresql/16/main/conf.d/postgres-import.conf
echo "Deleting downloaded dumps in ${PROJECT_DIR}"
rm -f ${PROJECT_DIR}/*sql.gz
rm -f ${PROJECT_DIR}/*csv.gz
rm -f ${PROJECT_DIR}/tiger-nominatim-preprocessed.csv.tar.gz
if [ "$PBF_URL" != "" ]; then
rm -f ${OSMFILE}
fi