These scripts keep GraphHopper routing data up to date using systemd timers and services.
gh-update.sh— downloads OSM data, imports it into the inactive instance, switches nginx to it, stops the old instance.gh-notify.sh— sends a Mailgun email on success (only when an update was actually performed) or failure.
| Unit | Purpose |
|---|---|
graphhopper@.service |
GraphHopper routing server (instances a and b) |
gh-update.service |
Oneshot update job |
gh-update.timer |
Triggers gh-update.service hourly |
gh-update-notify@.service |
Email notification, called by OnSuccess=/OnFailure= |
- Timer triggers
gh-update.serviceevery hour. - Script checks if new OSM data is available; exits silently if not.
- If yes, imports data into the inactive instance (
aorb). - Starts the new instance via systemd and polls until it is healthy.
- Switches nginx to the new instance and stops the old one.
- On success:
gh-update-notify@success.servicesends a notification email. - On failure:
gh-update-notify@failure.servicesends a failure email. The service is left infailedstate — the timer does not retry until the service is explicitly reset.
cp gh-update.conf.example gh-update.conf
chmod 600 gh-update.conf
# fill in MAILGUN_API_KEY, MAILGUN_DOMAIN, NOTIFY_EMAILfreemap ALL=(root) NOPASSWD: /bin/systemctl reload nginx, \
/bin/systemctl enable --now graphhopper@a, /bin/systemctl enable --now graphhopper@b, \
/bin/systemctl disable --now graphhopper@a, /bin/systemctl disable --now graphhopper@b, \
/bin/systemctl stop gh-update.timer, /bin/systemctl start gh-update.timer
cp graphhopper@.service gh-update.service gh-update.timer gh-update-notify@.service \
/etc/systemd/system/
chmod +x gh-update.sh gh-notify.sh
systemctl daemon-reload
# Start whichever graphhopper instance is currently active (e.g. a).
# The update script will enable/disable instances automatically on each update.
systemctl enable --now graphhopper@a.service
# Enable the timer (replaces cron)
systemctl enable --now gh-update.timerjournalctl -u gh-update.service # update job
journalctl -u graphhopper@a.service # instance a
journalctl -u graphhopper@b.service # instance bOn failure the timer is stopped automatically, preventing retries until the issue is fixed. After fixing:
systemctl start gh-update.timer # re-enable hourly runs
systemctl start gh-update.service # optional: trigger immediately