User:SomeoneElse/map.atownsend.org.uk/Setup
Server Setup
Getting the server and setting up the OS
The current server is the fourth in that I've used for this purpose - when I need to upgrade I setup a replacement server somewhere and update the DNS (at Gandi) to point at the new one. The current server is at Hetzner (mostly for reasons of "what you get for what you pay for"). It's a VM on a dedicated server running Proxmox. The specification of the VM (32GB RAM, 250GB SSD disk) can comfortably deal with hosting a "Britain and Ireland" map and the other things that it gets used for. To start things off, I installed a fairly minimal installation of Debian 13 on it - I'll add required software later.
The reason for the choice of this OS over others is:
- It's an LTS release, and so is supported for a long time
- The latest mod_tile and renderd are available via "apt install" - setup is much easier (also true for Ubuntu 22.04)
- More recent versions of other software used within OSM such as osm2pgsql and osmium-tool are also available directly via "apt install" (newer than in Debian 11)
The time zone default of Debian 12 is UTC - I have not changed that. As an aside, the time zone default of "Ubuntu 22.04.1 LTS Desktop" is local.
I initially added one ssh key (for use with the initial root account) and then later added other ssh keys to the non-root account I will use for future access.
The Proxmox server has an IPV4 address and an IPV6 range. Using iptables I forwarded the IPV4 address and one IPV6 address to point to this server (with a normal cloud server you wouldn't need to do this). I set up DNS entries for both.
I made sure that all software was up to date with "sudo apt update; sudo apt upgrade".
I created a non-root account for regular use and added it to the "sudo" group.
Once that was done I removed the ability to ssh in as root, or to ssh in with a password rather than a key.
non-map software
I installed a mail server and command-line tools for mail. Using "/etc/aliases" root's mail is forwarded to the main non-root account on the server, and mail from there is forwared to an external mailbox.
The various QA scripts are set up so an output (and hence an email) is only produced if something has gone wrong.
I installed Apache as a web server.
I set up an ssl certificate for the web server via certbot. Certbot can install itself and configure Apache in one go; for new server installs that makes sense. If not, also add a renewal line to root's crontab, and to enable ssl in apache, edit "/etc/apache2/sites-enabled/default-ssl.conf" to contain the fullchain and key of the certificate, replacing the "snakeoil" values, so that it looks something like this:
SSLCertificateFile /root/.acme.sh/yourserveraddress_ecc/fullchain.cer SSLCertificateKeyFile /root/.acme.sh/yourserveraddress_ecc/yourserveraddress.key
and then run:
sudo a2enmod ssl sudo a2ensite default-ssl sudo systemctl reload apache2
I set up iptables for IPV4 and IPV6 and made the settings permanent. No "odd ports" will be in use; inbound will just be ssh, http and https.
Raster map software
This essentially involves following the Ubuntu 22.04 or Debian 13 switch2osm guide down to but not including "Stylesheet configuration".
Important caveat: Those guides suggest using "lua5.1". The shared code used by both the raster and vector versions of this map style now needs lua 5.3, as UTF-8 string handling is only available in that version or later. Therefore:
sudo apt install lua5.3 liblua5.3-dev
As well as creating a database "gis" I also created "gis3" (which is setup identically). The reason for having 2 databases instead of 1 is to eliminate downtime - a new version of the map style can be loaded into "gis3" while "gis" is still serving tiles to users, tested, and then switched over if the load was successful.
stylesheet configuration, initially with "mod_tile" from Debian
Most of the software I've created for this map style can be configured to work under "~/src" under any desired non-root account. See an example script here.
The initial projects to clone to get us started are
- https://github.com/SomeoneElseOSM/SomeoneElse-style
- https://github.com/SomeoneElseOSM/openstreetmap-carto-AJT
- https://github.com/SomeoneElseOSM/SomeoneElse-style-legend
- https://github.com/SomeoneElseOSM/SomeoneElse-map
(there are others for other data layers that we'll look at later)
cd ~/src/openstreetmap-carto-AJT time sh -x get-shapefiles.sh
That will take between 20 seconds and potentially hours, depending on the speed of download.
Note that "get-shapefiles.sh" may fail to download some data from Natural Earth due to the bizarre way that their CDN is configured (redirects etc.). If this happens, download files referred to in the script manually. Also check issues at https://github.com/nvkelso/natural-earth-vector/issues to see if it is currently broken.
sudo emacs /etc/renderd.conf
Add:
[ajt] URI=/hot/ XML=/home/youruseraccount/src/openstreetmap-carto-AJT/mapnik.xml HOST=localhost TILESIZE=256 MAXZOOM=20
and
[ajt3] URI=/hot3/ XML=/home/youruseraccount/src/openstreetmap-carto-AJT/mapnik3.xml HOST=localhost TILESIZE=256 MAXZOOM=20
We will want to support zooms > 20 later, but lets check that the basics work first. 20 is the highest value supported by the standard mod_tile.
The earlier section of this file may also need to be modified. The location of the Mapnik plugins directory now varies between different architectures. You can type
sudo updatedb locate mapnik/4.0/input
to find the location on your server, and then edit "/etc/renderd.conf" so that plugins_dir in the [mapnik] section is correct, perhaps something like:
[mapnik] plugins_dir=/usr/lib/aarch64-linux-gnu/mapnik/4.0/input
If this is set incorrectly or missing among the errors that you might get when trying to render tiles are:
An error occurred while loading the map layer 's2o': Could not create datasource for type: 'postgis' (no datasource plugin directories have been successfully registered) encountered during parsing of layer 'landcover-low-zoom'
Other errors might include tiles not rendering properly and renderd using an unexpectedly large amount of memory.
Once that is sorted out, in the "openstreetmap-carto-AJT" area,
carto project.mml > mapnik.xml
Some warnings will be displayed here, something like this:
Warning: roads.mss:299:10 Styles do not match layer selector .roads-casing. Warning: Styles do not match layer selector .tunnels-fill. (node:14640) [DEP0128] DeprecationWarning: Invalid 'main' field in '/usr/share/node_modules/chroma-js/package.json' of 'chroma.js'. Please either fix that or report it to the module author (Use `node --trace-deprecation ...` to show where the warning was created) (node:14640) [DEP0128] DeprecationWarning: Invalid 'main' field in '/usr/share/node_modules/chroma-js/package.json' of 'chroma.js'. Please either fix that or report it to the module author
You can safely ignore those warnings.
At the top of [service] in /usr/lib/systemd/system/renderd.service Add
Environment=G_MESSAGES_DEBUG=all
then
sudo systemctl daemon-reload
Software used by the update script
The update_render.sh script is what I use for data loads. I copy it to /usr/local/sbin . I also copy make_gis3_live.sh there too (that swaps the "gis" and "gis3" databases around).
This script downloads various parts around Britain and Ireland. It splits the part corresponding to to Britain into "English speaking", "Welsh speaking" and "Scots Gaelic speaking" areas, and sets the "name" tag in those areas to "name:XX". It then merges everything together again.
That needs osmium, so
sudo apt install osmium-tool
It needs osm-tags-transform, which needs to be built from scratch (follow the instructions at that link).
sudo apt install pandoc pyosmium
The pyosmium setup is very similar to what is described at switch2osm, except that two databases are used here "gis" and "gis3" (one can be loaded while the other is live). The directories used for these are "/var/cache/renderd/pyosmium.gis" and "/var/cache/renderd/pyosmium.gis3", and "/var/cache/renderd/pyosmium.gis2" is used as a temporary location when swapping between them. As we copy scripts to the bin directory below, we'll amend them to support the databases we are using.
Changes to scripts
Many of the scripts that we use will need changing for things like local path definitions.
It is suggested to copy scripts to "/usr/local/sbin", modify them there, and run them from there.
Initially we'll create local copies of these scripts:
update_render.sh pyosmium_replag.sh make_gis3_live.sh
Looking at these one at a time:
We will update "update_render.sh" so that the local user matches your local user where the software has been downloaded. We'll also amend the osm2pgsql parameters so that it matches the local system - set "-C" to the amount of memory that you would like osm2pgsql to use up to, and "--number-processes" to the number of cores you want to make available to the load process.
During a database reload use tools such as "top" to look at the maximum CPU and memory load.
The "pyosmium_replag.sh" script will need changing if you want to to report on a state stored in a different place to the default.
The "make_gis3_live.sh" script needs changing in line with where you have downloaded software.
Access to data
Wherever the stylesheet is (and the files that osm2pgsql reads) need to be readable by the "_renderd" account that will load the database. If it won't cause a security issue do "chmod o+rx ~" against the non-root account in use; if it will then grant access via groups, copying files, or some other mechanism.
If this is not done you'll get cryptic messages from osm2pgsql saying it can't open the style file, or similar.
We'll also create a data directory,
mkdir ~/data
The "update_render.sh" script has references defined within it to four Geofabrik downloads. For testing, you can try something small like Rutland four times.
Edit the "update_render.sh" so that it's trying to load a small area initially, and then run it something like this:
screen script time sudo update_render.sh
"screen" allows you to disconnect from a session and reconnect to it (it may take a couple of hours with larger files).
"script" means that all output is also captured in a "typescript" file for future reference.
"time" means that the length of time that the command took to run will be reported on.
"sudo" means that it will be run as root.
Setting up the map website
You'll probably want to increase "ModTileMissingRequestTimeout" in the Apache config from the default of 10 to a larger number (see the end of the relevant switch2osm page for some suggestions) to avoid displaying grey tiles to users.
When a request for a tile is received, mod_tile initially waits ModTileRequestTimeout. If no new tile is available but a previous one is, it will then serve that old tile. It also uses ModTileMaxLoadOld to skip trying to render a new tile if an old one exists.
If no previous tile is available, it will wait ModTileMissingRequestTimeout before giving up and not returning a tile. It also uses ModTileMaxLoadMissing to skip trying to render a new tile even if there is no old one.
Different servers vary in terms of the mix of speed of various components (and of course the nature of the load is a factor). After testing it, I actually went with "ModTileRequestTimeout 2", "ModTileMissingRequestTimeout 120" and "ModTileMaxLoadMissing 6". I also prerendered everything up to zoom 14 so that there was something there at that zoom, even if not up to date.
One caveat about the Debian 13 versions of the software compared to older ones - the "tile dirtying algorithm" seems more effective, so more tiles are dirty more of the time. Also see this important fix needed to prevent tiles getting dirtied twice (upstream issue).
You may already have a website that you want to use and just need a source of raster tiles; if so, you can probably skip parts of the rest of this section.
This view shows the software in here. That is all set up below "/var/www/html/".
Leaflet is used to display the raster maps. "leaflet_dist" and "control" are in ldc.tar. The leaflet version is quite old (0.7.7), but I much prefer the way that it works, especially on mobile devices.
The "gis_test.html" and "gis3_test.html" pages can be edited to look at the local "gis" and "gis3" databases (provided that /etc/renderd.conf is set up appropriately). The contain "127.0.0.1" by default - edit that to match the desired name or IP address.
"map" is the main site. "leaflet_embed_small.js" can be edited so that the source of all the layers is correct. Most are local, but some other useful layers (e.g. OSM DE) are also available. Setting up of the other local layers such as "floodedUrl" and "novisUrl" will be discussed later.
The HTML files here are created using "pandoc" by "update_render.sh" and are available from buttons at the top here. The sources are markdown files in various repositories.
Uncomment "AddDefaultCharset UTF-8" in "/etc/apache2/conf-available/charset.conf" so that the HTML files display correctly.
The "legend" button jumps to a location in the middle of Australia where the legend has been appended to the database. Zoom in and out and move around to see everything
To summarise, the things needed have been obtained above from the "SomeoneElse-Map" repository are probably:
sudo mkdir /var/www/html/maps cd /var/www/html/maps sudo tar xvf /home/youruseraccount/src/SomeoneElse-map/ldc.tar sudo cp /home/youruseraccount/src/SomeoneElse-map/gis3_test.html . sudo cp /home/youruseraccount/src/SomeoneElse-map/gis_test.html . sudo mkdir /var/www/html/maps/map cd /var/www/html/maps/map sudo cp /home/youruseraccount/src/SomeoneElse-map/map/leaflet.css . sudo cp /home/youruseraccount/src/SomeoneElse-map/map/map.html . sudo cp /home/youruseraccount/src/SomeoneElse-map/map/permalink.html . sudo mkdir /var/www/html/maps/map/Scripts cd /var/www/html/maps/map/Scripts sudo cp /home/youruseraccount/src/SomeoneElse-map/map/Scripts/leaflet_embed_small.js . sudo cp /home/youruseraccount/src/SomeoneElse-map/map/Scripts/leaflet-hash.js . sudo cp /home/youruseraccount/src/SomeoneElse-map/map/Scripts/leaflet-hash-plus.js .
There are tile sources defined in these locations:
gis3_test.html gis_test.html leaflet_embed_small.js
You'll want to edit these to match what you will access the server as. If your server is "https://foo.bar", then the easiest way to avoid CORS errors is to use that consistently throughout, so that (for example) a raster tile is retrieved as "https://foo.bar/hot/8/121/84.png".
We've described "gis_test.html" and "gis3_test.html" already. The third, "leaflet_embed_small.js" is a full website incorporating a layer switcher. Initially you'll likely only want to change the "local" layer to point to your new server and make it the default layer.
As well as this, you'll need to tell the web server how to request new tiles from "renderd". To do this:
cd /etc/apache2/conf-available/ sudo wget https://raw.githubusercontent.com/openstreetmap/mod_tile/python-implementation/etc/apache2/renderd.conf sudo a2enconf renderd sudo systemctl reload apache2
Testing after database load
Likely initially using gis3_test.html, ensure that a map tile displays OK - or just access a single tile via e.g. http://yourserver/hot3/0/0/0.png .
"update_render.sh" also initialises database updates from https://planet.osm.org ; we'll look at that later.
Note that if you've loaded "gis3" but not "gis", "journalctl" will show errors when trying to start "renderd" pointing at "gis". This can be avoided by swapping the databases over with "make_gis3_live.sh" and loading the other database too.
The "make_gis3_live.sh" script stops various services (e.g. database checking cron jobs) before a database reload and restarts them afterwards, and also restarts services.
Low zoom tiles (0-12) will take a long time to render. This isn't a problem as normally these are prerendered and something is always available to be shown to the user. We'll set up a script to that below.
Also note that the "update_render.sh" process sends emails on successful or error completion to the local filesystem user defined in the script. It may be helpful to use the "aliases" file to forward these to an external email address.
Zoom levels above 20
The version of mod_tile distributed with Ubuntu only supports zoom levels up to 20. I've created a fork that supports up to 24, which we'll use on this server. See also this issue.
The "zoom2022" branch works on Ubuntu 22.04, Ubuntu 24.04 and Debian 12, but the "zoom2025" branch is needed for Debian 13 (likely because that has a different Mapnik library). The code changes from "master" in each case are essentially the same.
Install some prerequisites first, as documented here:
sudo apt install build-essential \ autoconf \ apache2-dev \ libcairo2-dev \ libcurl4-gnutls-dev \ libglib2.0-dev \ libiniparser-dev \ libmapnik-dev \ libmemcached-dev \ librados-dev
Then build mod_tile:
cd ~/src git clone https://github.com/SomeoneElseOSM/mod_tile cd mod_tile
on Ubuntu 22.04, Ubuntu 24.04 and Debian 12 do this:
git checkout zoom2022
but on Debian 13 do this:
git checkout zoom2025
time ./autogen.sh time ./configure time make
If that all works:
sudo make install sudo make install-mod_tile
It should be mentioned that even if this all works, some of the on-screen messages will look like "errors". If the files exist where they should as noted below, it has worked.
You should now have things such as "renderd" in "/usr/local/bin". Edit the service file "/usr/lib/systemd/system/renderd.service" to use that instead of the original. Change 20 to 24 in /etc/renderd.conf . It's recommended to rename the "/usr/bin" ones out of the way to avoid calling them by accident. As an example, if the old "render_expired" was to run, it wouldn't expire the right tiles, so you don't want to run it by mistake. Also edit "/etc/init.d/renderd" to access the daemon in "/usr/local/bin" if you use that to restart the service.
sudo systemctl daemon-reload sudo systemctl restart renderd sudo systemctl restart apache2
Remove all cached tiles (the directory format of the newly built version is different).
Test that everything still works, and that you can now zoom in to zoom 24. You can use test scripts "gis_test.html" and "gis3_test.html", which are in the "SomeoneElse-map" area for this. If not testing locally, you'll need to edit the IP address from "127.0.0.1" in those files.
maps showing current flooding
Clone this directory
As described here, this uses an existing field in the database ("wetland") to store whether a particular linear or area feature is flooded or not. This script contains a list of OSM ways, Environment Agency station numbers and values. In each case the "is it flooded at that level" is as a result of survey. There's a download for each EA station (see e.g. on this page). The EA information is cached locally.
Install prerequisite software:
sudo apt install bc
The stylesheet relies on this entry in /etc/renderd.conf:
[ajt4] URI=/hot4/ XML=/home/youruseraccount/src/floodedmap/mapnik.xml HOST=localhost TILESIZE=256 MAXZOOM=28
Create the "gis4" database in the same way as "gis" and "gis3".
The update scripts are set up in cron to run a few times per day, including "just before lunch". If the server time zone is UTC and the local time zone supports daylight saving, then the time when these scripts are run may need adjusting as local daylight saving comes in and out, as "just before lunch" changes by an hour at that time.
Example from root's cron:
# ----------------------------------------------------------------------------- # Flood map updates. # This script is from https://github.com/SomeoneElseOSM/floodedmap # Now run from root so that it can handle the "sudo" calls needed if running # from a later version of Debian or Ubuntu where the database user and # filesystem user are different. # The "#CONTROLLED BY update_render.sh" comments are to allow these lines to # be temporarily removed while the database is reloaded. # ----------------------------------------------------------------------------- 33 23 * * * /usr/local/sbin/update_floods.sh #CONTROLLED BY update_render.sh 33 08 * * * /usr/local/sbin/update_floods.sh #CONTROLLED BY update_render.sh 33 11 * * * /usr/local/sbin/update_floods.sh #CONTROLLED BY update_render.sh 33 14 * * * /usr/local/sbin/update_floods.sh #CONTROLLED BY update_render.sh 33 17 * * * /usr/local/sbin/update_floods.sh #CONTROLLED BY update_render.sh 33 20 * * * /usr/local/sbin/update_floods.sh #CONTROLLED BY update_render.sh
The "flood" overlay in "map.html" defaults to "map.atownsend.org.uk"; you'll want to change it to your server.
munin
This is mostly covered by the relevant switch2osm guide.
One other thing that I wanted to do was to track HTTP return codes, so I added support for that. This config goes in "/etc/munin/plugin-conf.d" ("adm" group access is needed to read Apache logfiles) and this script goes in "/etc/munin/plugins".
The line that extracts data from the log will need changing if the Apache log format has been changed, and in my example it has because I've changed this slightly. An example of my other format to use is in a comment at the top of the file.
fail2ban
Fail2ban was also installed. The jail definition is here (note that the ban time is only 5 minutes, although that can be adjusted). The regexp for detection can be found here - it detects non-munin 404 errors, and excludes ones that were genuine tile read attempts.
updates via pyosmium
Most of this is covered here. However, that guide has just one "pyosmium" directory below "/var/cache/renderd" and we have two "pyosmium.gis" and "pyosmium.gis3". The "make_gis3_live.sh" (see below) will swap databases around and will also swap the two pyosmium state directories around too.
The switch2osm guide explains how to manually set up the "sequence.state" file, but our "update_render.sh" has already done that.
You will probably need to do this:
sudo mkdir /var/log/tiles sudo chown _renderd /var/log/tiles
You'll also need to follow the switch2osm guide to install "trim_osc.py" and its dependencies, and the "Applying updates" section in that guide.
You already have the script to call pyosmium at:
/home/youruseraccount/src/SomeoneElse-style/call_pyosmium.sh
so don't get the "switch2osm" version of that script; it'll need editing to match your directory structure. Copy your version to "/usr/local/sbin". Edit the last line of the file to explicitly refer to the script location:
echo "Database Replication Lag:" `/usr/local/sbin/pyosmium_replag.sh -h`
and also ensure that the full path to "render_expired" is used throughout ("/usr/local/bin/render_expired").
To run the script once:
sudo -u _renderd /usr/local/sbin/call_pyosmium.sh
Check that the "Database Replication Lag:" line contains a time such as "Database Replication Lag: 1 day(s) and 1 hour(s)". If it doesn't, edit your script to correct it.
Run it again (perhaps a couple of times) and that time should go down.
Then edit "_renderd"'s crontab:
sudo -u _renderd crontab -l
and add it:
# ----------------------------------------------------------------------------- # Applying minutely updates # # The comment at the end of the line removes from cron while an update is in # progress. # Those scripts that require a valid database are not run until the database # update is complete. # # update_render.sh is in https://github.com/SomeoneElseOSM/SomeoneElse-style # ----------------------------------------------------------------------------- */5 * * * * /usr/local/sbin/call_pyosmium.sh >> /var/log/tiles/run.log #CONTROLLED BY update_render.> #
Wait and watch it run from cron a few times. "pyosmium_replag -h" should show the database lag going down. The logfile "/var/log/tiles/run.log" shows progress.
Other sections of the switch2osm guide need to be followed next, to clear the "pyosmium is running" flag when renderd is restated, and to add the replication delay to munin. As with other munin updates that graph will take a little while to appear.
"no vis paths" tiles
By default, paths that are not public footpaths and are not very visible on the ground are suppressed from the main map. The "no vis paths" tile layer optionally shows them. The Leaflet layer selector uses "hot5", and the entry in "/etc/renderd.conf" is "ajt5", pointing to a "mapnik.xml" below "novispaths" in "openstreetmap-carto-AJT" that is created by "update_renderd.sh".
[ajt5] URI=/hot5/ XML=/home/youruseraccount/src/openstreetmap-carto-AJT/novispaths/mapnik.xml TILESIZE=256 MAXZOOM=24
There is no separate database for this - if you look at the "mapnik,xml" referenced above you can see that it just uses "gis".
boundaries
Clone this repository:
The script in there cuts down a PBF database and loads it into a "gis6" database, only containing boundaries. It then creates "hot6" overlay tiles based on a cut-down map style (project6.mml / mapnik6.xml) that only shows boundaries.
Create the "gis6" database in the same way as "gis" and "gis3", and add "hot6" to "/etc/renderd.conf" like "hot" and "hot3".
Create the boundaries database:
time sudo ./update_boundaries.sh
To test it turn "boundaries" on at the main map website, and check that they appear.
Daily housekeeping scripts
Clone this directory
Set these up as required from cron as described here, and note other dependencies. Example cron files for each user are in this repository as e.g. "~/src/database_qa_scripts/report_database_size.sh".
In each case I've copied the script to /usr/local/sbin and edited (if necessary) to match local account names.
Note that "rerender_low.sh" depends on https://github.com/alx77/render_list_geo.pl , which also needs to be "git cloned" locally.
In addition, there are 3 files ("osm_ldp1", "osm_ldp2", "osm_ldp3") to be copied to "/etc/cron.d/" that depend on "/usr/local/sbin/count_generic.sh".
These scripts go in various crontabs. Looking at each in turn:
/etc/cron.d/
These scripts, "osm_ldp1", "osm_ldp2" and "osm_ldp3" go in "/etc/cron.d". Each one has a configuration in it that says what it should run as and where mail should go.
Each script checks many long distance paths for integrity (walking, horse and cycling). Many routes are broken, but if the number of pieces of a relation changes, an email is sent. This allows new holes to be filled in as they occur.
The first time any of these scripts are run an error will be displayed saying that the "before" file was missing. Therefore, run each line once before running from cron to avoid getting inundated with email over a period of 3 days.
root
There should be something in here to renew the SSL certificate. It won't do anything until within a month of expiry, so test that it does work then.
The QA scripts include scripts to "count various multipolygon relations". These do things like make sure that the number of "national parks" hasn't gone down because someone hasn't accidentally broken the boundary and made it no longer a valid multipolygon. In each case we'll copy to "/usr/local/sbin" and run from there.
# ----------------------------------------------------------------------------- # Count various multipolygon relations. # # The selection in each script is slightly different # These scripts are from https://github.com/SomeoneElseOSM/database_qa_scripts # ----------------------------------------------------------------------------- 47 06 * * * /usr/local/sbin/count_nationalparks_id.sh #CONTROLLED BY update_render.sh 52 06 * * * /usr/local/sbin/count_counties_id.sh #CONTROLLED BY update_render.sh 57 06 * * * /usr/local/sbin/count_baronies_id.sh #CONTROLLED BY update_render.sh 02 07 * * * /usr/local/sbin/count_civilparishes_id.sh #CONTROLLED BY update_render.sh 07 07 * * * /usr/local/sbin/count_townlands_id.sh #CONTROLLED BY update_render.sh 12 07 * * * /usr/local/sbin/count_electoraldistricts_id.sh #CONTROLLED BY update_render.sh 17 07 * * * /usr/local/sbin/count_historicchurchprovinces_id.sh #CONTROLLED BY update_render.sh 22 07 * * * /usr/local/sbin/count_historicchurchdioceses_id.sh #CONTROLLED BY update_render.sh 27 07 * * * /usr/local/sbin/count_historicchurchanglicanparishes_id.sh #CONTROLLED BY update_render.sh
Before running any from cron, check that they all work from a (root) command line.
Most of these just send email to the user running them (root). The "townlands" script is an exception; it sends mail to a local "townlands" user. Set the desired recipients of this mail up in /etc/aliases.
Next there may be a section of "flood map updates" (described above).
Next:
# ----------------------------------------------------------------------------- # Restart renderd regularly in case of leaks # This is because depending on server config renderd can encounter OOM errors # during Garmin map creation. # The Garmin process should finish around 7:00 UTC # ----------------------------------------------------------------------------- 30 07 * * * /etc/init.d/renderd restart #
Finally, you'll want some sort of automatic backup mechanism to copy configurations (or anything else that you don't want to lose) elsewhere.
_renderd
We've already set up "minutely updates" above.
Add the following housekeeping scripts:
# ----------------------------------------------------------------------------- # Housekeeping scripts # # These run every day. # These scripts are from https://github.com/SomeoneElseOSM/database_qa_scripts # ----------------------------------------------------------------------------- # 32 05 * * * /usr/local/sbin/purge_old_tiles.sh 37 05 * * * /usr/local/sbin/report_tile_size.sh 42 05 * * * /usr/local/sbin/rerender_low.sh #CONTROLLED BY update_render.sh
In each case copy each file to "/usr/local/sbin", edit so that references to your local user account are correct and test via e.g.
sudo -u _renderd /usr/local/sbin/purge_old_tiles.sh
before running from cron. The first time that "rerender_low.sh" is run it will take a long time, as it has lots of data-intensive tiles to create.
postgres
# m h dom mon dow command 42 06 * * * /usr/local/sbin/report_database_size.sh #
youruseraccount
Things that can be run from here include Garmin map updates:
# ----------------------------------------------------------------------------- # Create new "ajt03" Garmin maps once a week of Great Britain and Ireland # "ajt02" maps only run once a month at a different time so as not to collide. # "ajt04" maps only run once a month at a different time so as not to collide. # ----------------------------------------------------------------------------- 06 07 2 * * /home/youruseraccount/src/mkgmap_style_ajt/garmin_map_etrex_02.sh europe great-britain 06 05 * * 2 /home/youruseraccount/src/mkgmap_style_ajt/garmin_map_etrex_03.sh europe great-britain 06 05 * * 3 /home/youruseraccount/src/mkgmap_style_ajt/garmin_map_etrex_03.sh europe ireland-and-northern-ireland 06 07 4 * * /home/youruseraccount/src/mkgmap_style_ajt/garmin_map_etrex_04.sh europe great-britain
and if desired tag usage change checks:
# ----------------------------------------------------------------------------- # Investigate changes to tag usage and mail them out. # ----------------------------------------------------------------------------- 04 08 * * * /home/youruseraccount/src/SomeoneElse-style/report_tag_usage_changes.sh someoneelse_style 06 08 * * * /home/youruseraccount/src/SomeoneElse-style/report_tag_usage_changes.sh someoneelse_mkgmap_ajt02 08 08 * * * /home/youruseraccount/src/SomeoneElse-style/report_tag_usage_changes.sh someoneelse_mkgmap_ajt03 10 08 * * * /home/youruseraccount/src/SomeoneElse-style/report_tag_usage_changes.sh someoneelse_vector_sve01 #
Changing default web page
Edit "/etc/apache2/apache2.conf" and find this section:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
edit it so that instead says
<Directory /var/www/>
Options Indexes FollowSymLinks
Redirect /index.html https://yourserver/maps/map/map.html
AllowOverride None
Require all granted
</Directory>
Obviously, edit "yourserver" appropriately.
This will mean that browsers landing at the default page will be redrected to he raster map.
Maps for Garmin devices
The website also has pages for a few Garmin map styles, created using "mkgmap". To set that up:
Clone this repository:
Install prerequisite software:
sudo apt install openjdk-21-jre-headless openjdk-21-jdk mkgmap-splitter mkgmap
(for Debian 13; you can also install via "default-jdk")
Create these directories:
/var/www/html/maps/mkgmap_maps /var/www/html/maps/mkgmap_maps/ajt2 /var/www/html/maps/mkgmap_maps/ajt03 /var/www/html/maps/mkgmap_maps/ajt04
Make ajt2 and ajt03 writable by a regular user account. Also create overwriteable files for the documentation.
sudo touch /var/www/html/maps/map/mkgmap.html sudo chown youruseraccount /var/www/html/maps/map/mkgmap.html sudo touch /var/www/html/maps/map/changelog_mkgmap.html sudo chown youruseraccount /var/www/html/maps/map/changelog_mkgmap.html
There are two scripts, "garmin_map_etrex.sh" (which creates a basic mkgmap Garmin map) and "garmin_map_etrex_03.sh" (which creates a more detailed mkgmap Garmin map). Currently one of them is run weekly by cron and the other on an ad-hoc basis. If run from cron, it makes sense for the script in cron to copy resulting files under "/var/www/html/maps/mkgmap_maps/".
Vector Maps
Map styles
Creating the raster maps above is basically a two-stage process - data is converted from OSM tags and values into other ones by lua code and inserted into a database by osm2pgql, and then a display style using CartoCSS and ultimately Mapnik is used to display the data onto a web page.
The process for vector is actually similar - data is converted from OSM tags and values into other ones by lua code and inserted into vector tiles, and then Maplibre is used to display the data onto a web page.
In the case of vector the format of the data in the vector tiles is referred to as the "vector schema". There is a vector schema called SVE01 that broadly matches the format of the data used by the raster maps described above.
On the display side, there is a display style called SVWD01 that displays data in a similar way to the raster map style described above. Most of this section describes SVE01 and SVWD01, but there also other display styles hosted here (based on both the SVE01 schema and others). See "other display styles" below.
Installing the basic software
Clone some repositories:
cd ~/src git clone https://github.com/systemed/tilemaker git clone https://github.com/systemed/mod_mbtiles git clone https://github.com/SomeoneElseOSM/SomeoneElse-vector-extract git clone https://github.com/SomeoneElseOSM/SomeoneElse-vector-web-display
Install some software
sudo apt install socat build-essential libboost-dev libboost-filesystem-dev libboost-iostreams-dev libboost-program-options-dev libboost-system-dev liblua5.3-dev libshp-dev libsqlite3-dev rapidjson-dev zlib1g-dev
(some of that will likely already be there; some of it will not)
Install "mod_mbtiles" to allow a regular Apache web server to serve vector tiles from a large vector.pbf:
cd ~/src cd mod_mbtiles sudo apxs -lsqlite3 -i -a -c mod_mbtiles.c sudo systemctl restart apache2
Check that Apache still works at this point!
Build "tilemaker".
cd ~/src/tilemaker time make sudo make install
That will take a few minutes. Visually check that it is linking with lua 5.3 or later, not an earlier version.
MapLibre, CORS, and scripts
Instead of Leaflet, MapLibre GL JS is used to display the vector web maps on this site. If you point a web browser at https://map.atownsend.org.uk/vector/index.html and turn on "web developer" and have a look at "network", you can see that there are several sorts of things loaded:
- The maplibre code itself from "unpkg.com"
- The vector tiles themselves, from e.g. https://map.atownsend.org.uk/sve01/8/127/83.pbf
- Sprites, from e.g. https://map.atownsend.org.uk/vector/svwd01sprite.png and the accompanying .json file
- (and also optionally fonts)
In order to avoid CORS errors the HTML for the site is generated so that all the values align. The scripts that do this are here.
You need to copy the "update_vector.sh" and "update_vector2.sh" from the "SomeoneElse-vector-extract" repository that you have cloned into "/usr/local/sbin", and edit them there.
First, set the "local_filesystem_user=" correctly in both scripts. Second, ensure that "map.atownsend.org.uk" is changed to your server name throughout.
Change "/etc/apache2/sites-available/000-default.conf" and "/etc/apache2/sites-available/default-ssl.conf" to your http and https sites. Failure to do that will cause CORS errors.
In "update_vector.sh" change "europe britain-and-ireland" to the path to your desired region at Gefabrik (for example, "europe united-kingdom england rutland"
Leave the "nocoast" parameter in that script as is for now; we'll look at coastline later.
Shared lua scripts
The main "raster" lua script that we used earlier was "~/src/SomeoneElse-style/style.lua". That has a line in it that says:
require "shared_lua_raster"
The equivalent for vector tiles is "~/src/SomeoneElse-vector-extract/resources/process-sve01.lua". The equivalent line in that is
require "shared_lua_vector"
These files are originate from the same place (~/src/SomeoneElse-style/shared_lua.lua), in order to avoid writing the same code twice. They are copied to different names by the scripts we run so that an updated raster deployment won't break an existing vector one, and vice-versa. A slight complication is that raster and vector may use different versions (the default build for raster is 5.3, for vector 5.1.0 or 5.2). Avoid this being a problem by doing e.g.
sudo ln -s /usr/local/share/lua/5.3/ /usr/local/share/lua/5.1
Running update_vector.sh
time sudo /usr/local/sbin/update_vector.sh
It should complete with:
Filled the tileset with good things at /home/ajtown/data/tilemaker_sve01.mbtiles
"/var/www/html/vector/sve01" should now contain "tilemaker_sve01.mbtiles", and "/var/www/html/vector/fonts" should contain some fonts.
Browse to "https://yourservername/vector/index_svwd01.html" and check via web browser debug that there are no errors. Zoom to the area that you loaded data to see it.
By default that has debug enabled - we'll remove that below, but for now it is quite useful to help see what data is being displayed.
Turning off Maplibre debug
Copy "/var/www/html/vector/index_svwd01.html" to "/var/www/html/vector/index.html". In the latter file, towards the end you will see
// -- Comment the following lines out to remove debug UI --
map.showTileBoundaries=true;
map.addControl(new MaplibreInspect({
showInspectMap: false,
showInspectButton: false,
showInspectMapPopup: false,
showMapPopup: true
}));
// -- --
Adding "//" in front of each of those lines will disable the relevant bit of debug.
Coastline
"Tilemaker" contains a configuration to generate coastline vector tiles. First we'll download shapefile data as described here:
cd ~/src/tilemaker ./get-coastline.sh ./get-landcover.sh
Then we'll generate the vector tiles temselves:
cd ~/src/tilemaker time tilemaker --output ~/data/coastline.mbtiles --bbox -27.57,34.5,40.17,71.64 --process resources/process-coastline.lua --config resources/config-coastline.json
That will take a while and then display:
Filled the tileset with good things at /home/ajtown/data/coastline.mbtiles
update_vector2.sh
Like the main raster script, this one downloads various parts around Britain and Ireland. It splits the part corresponding to to Britain into "English speaking", "Welsh speaking" and "Scots Gaelic speaking" areas, and sets the "name" tag in those areas to "name:XX". It then merges everything together again.
There are "nocoast" and "coast" alternatives in the script. By default, the "nocoast" one is uncommented. If you've just generate some "coast" tiles you'll want to comment that out and uncomment the "coast" line immediately below. Run it via e.g.
time sudo /usr/local/sbin/update_vector2.sh
The resultant map should be accessible from the "vector" button at the top of the main website. Note that the vector site also has a language switcher on it to change from default (different languages in their popular areas) to Welsh, English, Irish and Scots Gaelic.
Again, you'll want to use browser debug to check for any errors and correct the scripts as required.
Other display styles
As noted above, this section has dealt with the SVE01 schema and SVWD01 display style. However, other display styles are also supported.
SVWD06
This is like SVWD01, but doesn't contain anything that will not work on MapLibre Native. It uses the vector tile schema SVE01. It is created automatically by the scripts so will already exist.
SVWD08
This is also based on the SVE01 schema, and can share the same set of vector tiles. The style is very similar to SVWD01 except that secondary and above roads with no documented sidewalk or verge are not shown. To create:
sudo /home/youraccount/src/SomeoneElse-vector-web-display/svwd_into_apache.sh sve01 svwd08 https://yourerver /home/ajtown/src/SomeoneElse-vector-web-display/resources/svwd01_spec.json /home/ajtown/src/SomeoneElse-vector-web-display/resources/svwd01_metadata.json /home/youraccount/src/tilemaker/server/static/fonts /home/youraccount/src/SomeoneElse-vector-web-display/resources/svwd08_style.json /home/youraccount/src/SomeoneElse-vector-web-display/resources/svwd01_index_nodebug.html svwd01sprite /home/youraccount/src/SomeoneElse-vector-web-display/resources
Obviously replace "youraccount" and "https://yourserver" with appropriate values.
Test that Apache is still working afterwards, and then browse to https://yourserver/vector/index_svwd08.html .
SVWD03
This is based on the Shortbread schema and uses OSMF's minutely updated Shortbread vector tiles. Although the style is visually based on SVWD01 (in turn visually based on the raster tiles above), the schema is much more lightweight, so many things are missing.
To create:
sudo /home/ajtown/src/SomeoneElse-vector-web-display/svwd_into_apache.sh NONE svwd03 https://h27.atownsend.org.uk /home/ajtown/src/SomeoneElse-vector-web-display/resources/svwd03_spec.json /home/ajtown/src/SomeoneElse-vector-web-display/resources/svwd03_metadata.json /home/ajtown/src/tilemaker/server/static/fonts /home/ajtown/src/SomeoneElse-vector-web-display/resources/svwd03_style.json /home/ajtown/src/SomeoneElse-vector-web-display/resources/svwd03_index.html svwd03sprite /home/ajtown/src/SomeoneElse-vector-web-display/resources
Obviously replace "youraccount" and "https://yourserver" with appropriate values.
Test that Apache is still working afterwards, and then browse to https://yourserver/vector/index_svwd03.html .