-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgh-update.sh
More file actions
executable file
·103 lines (77 loc) · 2.63 KB
/
gh-update.sh
File metadata and controls
executable file
·103 lines (77 loc) · 2.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
#!/bin/bash
set -e
echo "---BEGIN---"
trap 'echo "---END---"' EXIT
cd "$(dirname "$0")"
# shellcheck source=gh-update.conf
source ./gh-update.conf
sudo -n /bin/systemctl stop gh-update.timer
mkdir -p run
# Default result; overwritten to "updated" only after a successful update.
# Read by gh-notify.sh to suppress the success email when there was no update.
echo "skipped" > run/result
wait_for_gh_ready() {
local port="$1"
local http_code
for _ in $(seq 1 60); do
http_code="$(curl -sS --max-time 10 -o /dev/null -w '%{http_code}' "http://127.0.0.1:${port}/route" \
-H 'Content-Type: application/json' \
--data-raw '{"profile":"car","points":[[20.778408050524682,49.005743088335926],[20.795849427570825,49.00523635421394]]}' \
|| true)"
[ "$http_code" = "200" ] && return 0
sleep 5
done
return 1
}
# GEOFABRIK_URL is set in gh-update.conf
pbf_file="run/$(basename "$GEOFABRIK_URL")"
remote_md5="$(wget -q -O - "${GEOFABRIK_URL}.md5")"
if [ -f run/osm.md5 ] && [ "$(cat run/osm.md5)" = "$remote_md5" ]; then
echo "No update available"
exit 0
fi
if systemctl is-enabled --quiet graphhopper@a; then
active="a"
elif systemctl is-enabled --quiet graphhopper@b; then
active="b"
else
active="none"
fi
echo "Active: $active"
if [ -f "$pbf_file" ] && [ -f run/downloaded.md5 ] && [ "$(cat run/downloaded.md5)" = "$remote_md5" ]; then
echo "Already downloaded, reusing $pbf_file"
else
echo "Downloading"
rm -f "$pbf_file"
wget -nv "$GEOFABRIK_URL" -P run
echo "$remote_md5" > run/downloaded.md5
fi
echo "Extracting"
osmium extract --set-bounds -p limit.geojson "$pbf_file" -o run/extract.pbf --overwrite
if [[ "$active" == "a" ]]; then
next="b"
next_port=9989
else
next="a"
next_port=8989
fi
echo "Importing: $next"
rm -rf /fm/sdata/graphhopper/graph-cache.${next} && mkdir -p /fm/sdata/graphhopper/graph-cache.${next}
nice java -Xms1g -Xmx28g -jar graphhopper-web-11.0.jar import config-freemap.${next}.yml
echo "Starting: $next"
sudo -n /bin/systemctl enable --now graphhopper@${next}
echo "Polling: $next on localhost:${next_port}"
if ! wait_for_gh_ready "$next_port"; then
echo "New instance ${next} did not become ready on localhost:${next_port}"
sudo -n /bin/systemctl disable --now graphhopper@${next} || true
exit 1
fi
echo "$remote_md5" > run/osm.md5
rm -f ./graphhopper.freemap.sk
ln -s ./graphhopper.freemap.sk.${next} ./graphhopper.freemap.sk
sudo -n /bin/systemctl reload nginx
sudo -n /bin/systemctl disable --now graphhopper@${active} || true
rm -f "$pbf_file" run/downloaded.md5 run/extract.pbf
echo "updated" > run/result
sudo -n /bin/systemctl start gh-update.timer
echo "Success"