diff --git a/roles/renderd/tasks/cyclosm.yml b/roles/renderd/tasks/cyclosm.yml new file mode 100644 index 00000000..285cdedc --- /dev/null +++ b/roles/renderd/tasks/cyclosm.yml @@ -0,0 +1,144 @@ +# style cyclosm +- include: ../../../shared/project-account.yml user=cyclosm + +- name: checkout git repository + git: + repo: https://github.com/cyclosm/cyclosm-cartocss-style.git + dest: /data/project/cyclosm/cyclosm-cartocss-style/ + force: no + update: no + version: v0.6 + become: yes + become_user: cyclosm + +- name: get nodejs apt key + apt_key: + url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key + state: present + +- name: add nodejs apt repository + apt_repository: + repo: deb https://deb.nodesource.com/node_18.x "{{ ansible_distribution_release }}" main + state: present + filename: nodesource + +- name: install nodejs packages + apt: + pkg: nodejs + state: latest + +- name: install packages + apt: + pkg: + - nodejs + state: latest + +- name: npm install + community.general.npm: + name: carto + path: /data/project/cyclosm/ + become: yes + become_user: cyclosm + +- name: init /data/work/cyclosm/data + file: + path: /data/work/cyclosm/data + state: directory + become: yes + become_user: cyclosm + +- name: download land polygons + ansible.builtin.unarchive: + src: http://osmdata.openstreetmap.de/download/land-polygons-complete-3857.zip + dest: /data/work/cyclosm/data/ + remote_src: true + creates: /data/work/cyclosm/data/land-polygons-complete-3857/ + become: yes + become_user: cyclosm + +- name: download simplified land polygons + ansible.builtin.unarchive: + src: http://osmdata.openstreetmap.de/download/simplified-land-polygons-complete-3857.zip + dest: /data/work/cyclosm/data/ + remote_src: true + creates: /data/work/cyclosm/data/simplified-land-polygons-complete-3857/ + become: yes + become_user: cyclosm + +- name: update project.mml + lineinfile: + path: /data/project/cyclosm/cyclosm-cartocss-style/project.mml + regexp: '{{ item.regexp }}' + line: '{{ item.line }}' + with_items: + - {regexp: "^ file:.*/simplified-land-polygons", line: " file: /data/work/cyclosm/data/simplified-land-polygons-complete-3857/simplified_land_polygons.shp"} + - {regexp: "^ file:.*/land-polygons", line: " file: /data/work/cyclosm/data/land-polygons-complete-3857/land_polygons.shp"} + become: yes + become_user: cyclosm + +- name: configure hostname for postgresql + lineinfile: + path: /etc/hosts + line: '{{ renderd_pghostip }} osmdb' + when: renderd_pghostip is defined + +- name: configure database connection + ansible.builtin.blockinfile: + path: /data/project/cyclosm/cyclosm-cartocss-style/project.mml + insertafter: ' dbname: "osm"' + block: |2 + user: "cyclosm" + host: "osmdb" + port: 5432 + password: "{{ lookup('password', 'private/passwords/postgresql-cyclosm') }}" + +- name: mapnik file generation + command: chdir=/data/project/cyclosm/ node_modules/.bin/carto \ + /data/project/cyclosm/cyclosm-cartocss-style/project.mml \ + --file /data/project/cyclosm/cyclosm-cartocss-style/mapnik.xml.new + become: yes + become_user: cyclosm + +- name: mapnik file copy + copy: + dest: /data/project/cyclosm/cyclosm-cartocss-style/mapnik.xml + src: /data/project/cyclosm/cyclosm-cartocss-style/mapnik.xml.new + remote_src: true + notify: + - restart renderd + - reload apache2 + become: yes + become_user: cyclosm + +- name: add layer cyclosm into renderd.conf + blockinfile: + path: /etc/renderd.conf + marker: "## {mark} ANSIBLE MANAGED BLOCK - cyclosm" + block: | + [cyclosm] + URI=/cyclosm/ + XML=/data/project/cyclosm/cyclosm-cartocss-style/mapnik.xml + HOST=tile.openstreetmap.fr + MAXZOOM=20 + notify: + - restart renderd + - reload apache2 + +- name: copy apache config + template: + src: tileserver_site.conf + dest: /etc/apache2/sites-available/tileserver_site.conf + notify: reload apache2 + +- name: enable apache site + file: + src: /etc/apache2/sites-available/tileserver_site.conf + dest: /etc/apache2/sites-enabled/tileserver_site.conf + state: link + notify: reload apache2 + +- name: remove default apache site + file: + dest: /etc/apache2/sites-enabled/000-default.conf + state: absent + notify: reload apache2 diff --git a/roles/renderd/tasks/main.yml b/roles/renderd/tasks/main.yml index b8f5faac..64486a8b 100644 --- a/roles/renderd/tasks/main.yml +++ b/roles/renderd/tasks/main.yml @@ -13,12 +13,14 @@ - apache2 - apache2-dev - autoconf + - fonts-noto + - fonts-noto-core - fonts-noto-cjk - fonts-noto-hinted - fonts-noto-unhinted - fonts-hanazono + - fonts-unifont - git - - libmapnik3.0 - libmapnik-dev - libncursesw5-dev - mapnik-utils @@ -26,14 +28,13 @@ - python3-pip - python3-venv - software-properties-common - - ttf-unifont - unifont - unzip - apt_repository: repo: 'ppa:osmadmins/ppa' codename: bionic - when: (ansible_distribution == 'Debian' and ansible_distribution_major_version >= 10) + when: (ansible_distribution == 'Debian' and ansible_distribution_major_version == 10 and ansible_distribution_major_version == 11) - name: install packages apt: @@ -114,3 +115,7 @@ - restart renderd - reload apache2 when: renderd_layers + +# style cyclosm +- import_tasks: cyclosm.yml + when: renderd_cyclosm diff --git a/roles/renderd/templates/tileserver_site.conf b/roles/renderd/templates/tileserver_site.conf new file mode 100644 index 00000000..32ab9fbb --- /dev/null +++ b/roles/renderd/templates/tileserver_site.conf @@ -0,0 +1,145 @@ +# This is the Apache server configuration file for providing OSM tile support +# through mod_tile + + + ServerAdmin webmaster@localhost + + ServerName {{ inventory_hostname }} + ServerAlias {{ renderd_serveralias }} + DocumentRoot /var/www + + # increase the log level for more detailed information + LogLevel info + + ErrorLog /var/log/apache2/tile-error.log + CustomLog /var/log/apache2/tile-access.log combined + +# You can manually configure each tile set with AddTileConfig or AddTileMimeConfig. +# The first argument is the URL path relative to this virtual host +# under which a tile set is served. The second argument specifies the +# name of the tile set. This is used in the communication with renderd +# and is the directory under which (meta)tiles are stored on disk. +# +# By default (AddTileConfig) mod_tile assumes you are serving png files, however, +# mod_tile can also serve arbitrary other tile types such as javascript vector tiles, +# assuming the backend render daemon can handle the file type. +# To this purpose AddTileMimeConfig takes a 3rd agument, the file extension and it +# will guess the correct mimetype from it. If the mime type is not set correctly automatically, +# you need to use the configuration file route, where you can specify the mimetype and file extension +# independently. +# +# AddTileConfig /folder/ TileSetName +# AddTileMimeConfig /folder2/ TileSetName2 js + +# Alternatively (or in addition) you can load all the tile sets defined in the configuration file into this virtual host + LoadTileConfigFile /etc/renderd.conf + +# Timeout before giving up for a tile to be rendered + ModTileRequestTimeout 1 + +# Timeout before giving up for a tile to be rendered that is otherwise missing + ModTileMissingRequestTimeout 30 + +# If tile is out of date, don't re-render it if past this load threshold (users gets old tile) + ModTileMaxLoadOld 36 + +# If tile is missing, don't render it if past this load threshold (user gets 404 error) + ModTileMaxLoadMissing 50 + +# Sets how old an expired tile has to be to be considered very old and therefore get elevated priority in rendering + ModTileVeryOldThreshold 631324800 + +# Socket where we connect to the rendering daemon + ModTileRenderdSocketName /var/run/renderd/renderd.sock + +## +## Options controlling the cache proxy expiry headers. All values are in seconds. +## +## Caching is both important to reduce the load and bandwidth of the server, as +## well as reduce the load time for the user. The site loads fastest if tiles can be +## taken from the users browser cache and no round trip through the internet is needed. +## With minutely or hourly updates, however there is a trade-off between cacheability +## and freshness. As one can't predict the future, these are only heuristics, that +## need tuning. +## If there is a known update schedule such as only using weekly planet dumps to update the db, +## this can also be taken into account through the constant PLANET_INTERVAL in render_config.h +## but requires a recompile of mod_tile + +## The values in this sample configuration are not the same as the defaults +## that apply if the config settings are left out. The defaults are more conservative +## and disable most of the heuristics. + + +## +## Caching is always a trade-off between being up to date and reducing server load or +## client side latency and bandwidth requirements. Under some conditions, like poor +## network conditions it might be more important to have good caching rather than the latest tiles. +## Therefor the following config options allow to set a special hostheader for which the caching +## behaviour is different to the normal heuristics +## +## The CacheExtended parameters overwrite all other caching parameters (including CacheDurationMax) +## for tiles being requested via the hostname CacheExtendedHostname +#ModTileCacheExtendedHostname cache.tile.openstreetmap.org +#ModTileCacheExtendedDuration 2592000 + +# Upper bound on the length a tile will be set cacheable, which takes +# precedence over other settings of cacheing +ModTileCacheDurationMax 604800 + +# Sets the time tiles can be cached for that are known to by outdated and have been +# sent to renderd to be rerendered. This should be set to a value corresponding +# roughly to how long it will take renderd to get through its queue. There is an additional +# fuzz factor on top of this to not have all tiles expire at the same time +ModTileCacheDurationDirty 900 + +# Specify the minimum time mod_tile will set the cache expiry to for fresh tiles. There +# is an additional fuzz factor of between 0 and 3 hours on top of this. +ModTileCacheDurationMinimum 10800 + +# Lower zoom levels are less likely to change noticeable, so these could be cached for longer +# without users noticing much. +# The heuristic offers three levels of zoom, Low, Medium and High, for which different minimum +# cacheing times can be specified. + +#Specify the zoom level below which Medium starts and the time in seconds for which they can be cached +ModTileCacheDurationMediumZoom 16 43200 + +#Specify the zoom level below which Low starts and the time in seconds for which they can be cached +ModTileCacheDurationLowZoom 13 86400 + +# A further heuristic to determine cacheing times is when was the last time a tile has changed. +# If it hasn't changed for a while, it is less likely to change in the immediate future, so the +# tiles can be cached for longer. +# For example, if the factor is 0.20 and the tile hasn't changed in the last 5 days, it can be cached +# for up to one day without having to re-validate. +ModTileCacheLastModifiedFactor 0.20 + +## Tile Throttling +## Tile scrappers can often download large numbers of tiles and overly staining tileserver resources +## mod_tile therefore offers the ability to automatically throttle requests from ip addresses that have +## requested a lot of tiles. +## The mechanism uses a token bucket approach to shape traffic. I.e. there is an initial pool of n tiles +## per ip that can be requested arbitrarily fast. After that this pool gets filled up at a constant rate +## The algorithm has to metrics. One based on overall tiles served to an ip address and a second one based on +## the number of requests to renderd / tirex to render a new tile. + +## Overall enable or disable tile throttling +ModTileEnableTileThrottling Off +## When the tileserver is behind a proxy one can use the X-Forwarded-For http header to determin the remote IP for throttling +## 0: don't use X-Forwarded-For +## 1: Use the first address in the X-Forwarded chain, which should be the client address. However, this may not be trusted. +## 2: Use the last address in the X-Forwarded chain. If one uses a reverse proxy, this will be the IP address seen by the reverse proxy and can be trusted. +ModTileEnableTileThrottlingXForward 0 + +## Parameters (poolsize in tiles and topup rate in tiles per second) for throttling tile serving. +ModTileThrottlingTiles 10000 1 +## Parameters (poolsize in tiles and topup rate in tiles per second) for throttling render requests. +ModTileThrottlingRenders 128 0.2 + + + Options FollowSymLinks + AllowOverride None + + + +