Py-QGIS-Server

Py-QGIS-Server byl navržen pro správu mapových procesů QGIS Serveru.

Předběžné požadavky

Předpokládáme, že již máte nainstalované balíčky QGIS Server, jak je vysvětleno v dokumentaci QGIS Server.

Poznámka

Konfiguraci webového serveru Nginx/Apache nemusíte číst v dokumentaci QGIS. Py-QGIS-Server má totiž vlastní webový server.

Instalace v Python venv

Přidáme potřebné balíčky, které nejsou součástí QGIS Serveru :

apt install python3-venv python3-psutil

Poté vytvoříme virtuální prostředí Py-QGIS-Server a nainstalujeme py-qgis-server pomocí pip :

set -e
python3 -m venv /opt/local/py-qgis-server --system-site-packages
/opt/local/py-qgis-server/bin/pip install -U pip setuptools wheel pysocks typing py-qgis-server

Py-QGIS-Server je nainstalován.

Konfigurace a související soubory

Níže použité složky

mkdir -p /srv/qgis/plugins /srv/qgis/config /srv/data /var/log/qgis /var/lib/py-qgis-server

Soubor, který je třeba sledovat pro restartování workers

Vytvoříme prázdný soubor, který bude sledován Py-QGIS-Serverem, aby zkontroloval, kdy restartovat mapové pracovníky QGIS Serveru.

touch /var/lib/py-qgis-server/py-qgis-restartmon
chmod 664 /var/lib/py-qgis-server/py-qgis-restartmon

The bash file to restart workers

Vytvoříme spustitelný soubor /usr/bin/qgis-reload pro restartování mapových workerů QGIS Serveru. Bude obsahovat:

#!/bin/bash

touch /var/lib/py-qgis-server/py-qgis-restartmon

Then we change its mod :

chmod 750 /usr/bin/qgis-reload

The configuration file

We create the Py-QGIS-Server configuration file /srv/qgis/server.conf. It will contain:

#
# Py-QGIS-Server configuration
# https://docs.3liz.org/py-qgis-server/
#

[server]
port = 7200
interfaces = 127.0.0.1
workers = 4
pluginpath = /srv/qgis/plugins
timeout = 200
restartmon = /var/lib/py-qgis-server/py-qgis-restartmon

[logging]
level = info

[projects.cache]
strict_check = false
rootdir = /srv/data
size = 50
advanced_report = no

[monitor:amqp]
routing_key =
default_routing_key=
host =

[api.endpoints]
lizmap_api=/lizmap

[api.enabled]
lizmap_api=yes

In this example:

  • QGIS Server will be available at http://127.0.0.1:7200/ows/

  • the plugins are installed in /srv/qgis/plugins (pluginpath). See Zásuvné moduly QGIS Server.

  • the file to watch for restarting workers is /var/lib/py-qgis-server/py-qgis-restartmon (restartmon).

  • the directory containing the projects to be published /srv/data (rootdir). The projects must be in sub-folders.

  • Lizmap QGIS Server API is enabled

Manage it with systemd

First of all, we create an environment file /srv/qgis/config/qgis-service.env with

LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
DISPLAY=:99
QGIS_OPTIONS_PATH=/srv/qgis/
QGIS_AUTH_DB_DIR_PATH=/srv/qgis/
GDAL_CACHEMAX=2048
QGIS_SERVER_CACHE_SIZE=2048
QGIS_SERVER_LIZMAP_REVEAL_SETTINGS=TRUE
QGIS_SERVER_FORCE_READONLY_LAYERS=TRUE
QGIS_SERVER_TRUST_LAYER_METADATA=TRUE
QGIS_SERVER_APPLICATION_NAME=qgis-server

In this file, we defined:

  • The language

  • The Xvfb display port, needed to print PDF

  • The QGIS options and authDB path (needed for HTTPS, when used in remote layers such as OSM tiles)

  • Lizmap environment variable to reveal settings

  • Other QGIS Server variables, from the documentation.

Then we can create the QGIS service systemd file /etc/systemd/system/qgis.service with

[Unit]
Description=QGIS server
After=network.target

[Service]
Type=simple

ExecStart=/opt/local/py-qgis-server/bin/qgisserver -c /srv/qgis/server.conf

# FIXME it is recommended to have a script *synchronous*, which is not the case here
ExecReload=/usr/bin/qgis-reload

KillMode=control-group
KillSignal=SIGTERM
TimeoutStopSec=10

Restart=always

StandardOutput=append:/var/log/qgis/qgis-server.log
StandardError=inherit
SyslogIdentifier=qgis

EnvironmentFile=/srv/qgis/config/qgis-service.env
User=root

LimitNOFILE=4096

[Install]
WantedBy=multi-user.target

Finally, we enable the QGIS Server service to start at system launch and we also start the service right now :

systemctl enable qgis
service qgis start

Debug and check

Tip

1. We can check that QGIS Server with Py-QGIS-Server is working with : curl http://127.0.0.1:7200/ows/

2. After the installation of Lizmap Server QGIS plugin, we can check with : curl http://127.0.0.1:7200/lizmap/server.json | jq '.' Read Zásuvné moduly QGIS Server with the use of QGIS-Plugin-Manager.

Adapt the Lizmap Web Client configuration

Either by editing manually the file lizmap/var/config/lizmapConfig.ini.php or by changing in Lizmap Web Client GUI :

[services]
;URL to QGIS Server for OGC web services
wmsServerURL="http://127.0.0.1:7200/ows/"
;URL to the API exposed by the Lizmap plugin for QGIS Server
lizmapPluginAPIURL="http://127.0.0.1:7200/lizmap/"

; path to find repositories
rootRepositories="/srv/data"

Your Server information panel must show you the QGIS Server version and installed plugins.