From d8e7227a73f2234140fb2dbb8b6db33bd25ed5be Mon Sep 17 00:00:00 2001 From: Trent Palmer Date: Mon, 3 Feb 2025 11:40:24 -0800 Subject: [PATCH] continue open-elevation-api-server-upgrade --- .../open-elevation-api-server-upgrade.md | 121 ++++++++++++++++++ mkdocs.yml | 2 + 2 files changed, 123 insertions(+) create mode 100644 docs/posts/open-elevation-api-server-upgrade.md diff --git a/docs/posts/open-elevation-api-server-upgrade.md b/docs/posts/open-elevation-api-server-upgrade.md new file mode 100644 index 0000000..b9cc885 --- /dev/null +++ b/docs/posts/open-elevation-api-server-upgrade.md @@ -0,0 +1,121 @@ +--- +title: "Open Elevation Api Server Upgrade" +date: 2025-02-02 +draft: false +tags: ["linux", "Debian", "bookworm", "buster", "bullseye", "bottle", "geospatial"] +authors: ["trent"] +post: 36 +--- +date: 2025-02-02 + +## Introduction +A while back I left an open-elevation-api-server running on Debian 10, and I can't remember why. + +But I have now worked out how to get it running on Debian 10, Debian 11, and Debian 12 +so I want to have what I learned written down here. +### What is This? +The api returns an elevation when you query it with gps coordinates. + +i.e. you want the elevation at Boring Bowling Alley and Petting Zoo? +```bash +curl 'https://elevation.boringonian.com/api/v1/lookup?locations=45.42949,-122.37563' +``` + +```json +{"results": [{"latitude": 45.42949, "longitude": -122.37563, "elevation": 157}]} +``` + +## What changed? +Going from Debian 10 to Debian 11, you have to change how to import gdal and osr. +```python +# gdal_interfaces.py +# import gdal, osr +from osgeo import gdal, osr +... +``` +Going from Debian 11 to Debian 12, `python3-lazy` is now installable from `apt-get`; +no more _cowboy-pip3-installs_ ; all dependencies are now available from `apt-get`. + +## Debian 10 Installation +### install dependencies +Here's how I got this working on Debian 10. +```bash +apt install python3-bottle python3-gunicorn +apt install gdal-bin python3-gdal +apt install python3-rtree python3-pip +pip3-install lazy +``` +### create user and home directory +```bash +mkdir /var/lib/elevation +useradd -r -s /sbin/nologin -d /var/lib/elevation elevation +``` + +### setup your data directory +[Follow the instructions](https://github.com/Jorl17/open-elevation/blob/master/docs/host-your-own.md) +for extracting your 400 `*.tif` files and 1 `summary.json` +to `/var/lib/elevation/data/`. + +Also place `gdal_interfaces.py` and `server.py` in +`/var/lib/elevation/` + +in `server.py` I comment out the config-parser stuff and just hardcode +the following +```python +# server.py +interface = GDALTileInterface('data/', 'data/summary.json') +interface.create_summary_json() +``` + +And of course then at the very bottom of `server.py` adjust the +_run_ command for the host and port that you want gunicorn to listen on. + +## Debian 11 Installation +In upgrading from Debian 10 to Debian 11, change how you import gdal and osr. +```python +# gdal_interfaces.py +# import gdal, osr +from osgeo import gdal, osr +... +``` +Additionally, and I'm not completely clear if this is necessary or not, I deleted +`/usr/local/lib/python3.7/` and then once again installed `lazy`. +```bash +rm -rf /usr/local/lib/python3.7/ + +# installs lazy in /usr/local/lib/python3.9/ +pip3-install lazy +``` + +## Debian 12 Installation +In upgrading from Debian 11 to Debian 12, it is no longer necessary to install lazy +with pip. + +```bash +rm -rf /usr/local/lib/python3.9/ +apt install python3-lazy +``` + +## Run as Systemd Service +This is probably just based on a google search how to run a `bottle` +server with `gunicorn` from `systemd`. +```conf +# /etc/systemd/system/elevation.service +[Unit] +Description=Bottled Elevation API +After=network.target remote-fs.target nss-lookup.target + +[Service] +Type=simple +User=elevation +Group=elevation +WorkingDirectory=/var/lib/elevation +ExecStart=/usr/bin/python3 /var/lib/elevation/server.py +StandardOutput=inherit +StandardError=inherit +Restart=always +RestartSec=2 + +[Install] +WantedBy=multi-user.target +``` diff --git a/mkdocs.yml b/mkdocs.yml index 7a1b494..a2860b8 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -24,6 +24,7 @@ markdown_extensions: nav: - Home: - Home: index.md + - "Open Elevation Api Server Upgrade": posts/open-elevation-api-server-upgrade.md - "Wireguard on Nspawn": posts/wireguard-on-nspawn.md - "Sandbox IOT Network": posts/sandbox-iot-network.md - "QuasselCore on Debian 11": posts/quasselcore-on-debian-11.md @@ -73,6 +74,7 @@ nav: - FreeCodeCampChallenges: https://trentspalmer.github.io/fcc-challenges/ - DeviceLayout: https://trentpalmer.work/6a57bbe24d8244289610bf57533d6c6f/ - Posts: + - "Open Elevation Api Server Upgrade": posts/open-elevation-api-server-upgrade.md - "Wireguard on Nspawn": posts/wireguard-on-nspawn.md - "Sandbox IOT Network": posts/sandbox-iot-network.md - "QuasselCore on Debian 11": posts/quasselcore-on-debian-11.md