gws.server¶
Configuration and control of the embedded servers.
GWS runs several servers in the container: the uWSGI web server, which handles
client and API requests, the uWSGI spool server, which runs background jobs and
the monitor, the frontend NGINX proxy and, in a container, an rsyslogd
daemon for logging. This package configures these servers, creates their
configuration files and the start script, and handles server starts, reloads
and reconfigurations.
Submodules:
core: theserversection of the application configuration (Configand the configs for the web and spool servers, the monitor, logging and QGIS).manager: the server manager (gws.ServerManager), which applies config defaults and environment overrides and renders the configuration files and the start script from templates.control: functions that start, reconfigure and reload the servers, and test the configuration.cli: theservercommand-line commands, which delegate tocontrol.monitor: the server monitor (gws.ServerMonitor), which watches configuration files and runs periodic tasks.spool: the spool server application and the job queue functions.uwsgi_module: access to theuwsgimodule, which only exists inside a uWSGI process.templates: default templates for the nginx, uWSGI and syslog configs and the start script.
The configuration files are rendered from templates, which can be replaced in
the server.templates config. These template subjects are used:
server.rsyslog_config: the embeddedrsyslogddaemon, only in a containerserver.uwsgi_config: the uWSGI backends, theuwsgiargument holds the backend name (weborspool)server.nginx_config: the frontend NGINX proxyserver.start_script: the shell script that starts the servers
Each template receives a gws.server.manager.TemplateArgs object as
arguments. By default, text-only templates from the templates directory
are used.
The startup sequence is the following:
the main script
bin/gwsinvokes theserver startcommand ingws.server.clithe CLI delegates to
gws.server.controlcontrolconfigures the application (gws.base.application.core.Object) and stores the configurationthe application creates the server manager (
gws.server.manager.Object) and the monitor (gws.server.monitor.Object)controlmakes the manager write the configuration files for the servers and the start scriptcontrol returns to
bin/gws, which executes the start scriptthe script starts
rsyslogd, the uWSGI backends and finally NGINX, which keeps running in the foreground
On configure, the manager fills in the defaults of the server config and
its subsections, maps the deprecated enabled keys to withWeb,
withSpool and withMonitor, and applies overrides from the environment
variables GWS_LOG_LEVEL, GWS_WEB_WORKERS and GWS_SPOOL_WORKERS.
Besides the start, control supports these workflows:
reconfigure (
server reconfigure): configure the application, store the configuration, rewrite the server configs, empty the transient directory, reload the uWSGI backends and NGINXreload (
server reload): empty the transient directory, reload the uWSGI backends and NGINXconfigure (
server configure, for debugging): configure the application and store the configurationconfig test (
server configtest, for debugging): configure or only parse the configuration and log the report
The spool server loads the stored configuration and starts the monitor, if
withMonitor is set. A uWSGI timer calls the monitor every few seconds. When watched files change, or when an object calls
schedule_reload, the monitor configures and stores the configuration (on
a reconfigure) and reloads the web and spool backends. It does not rewrite the
server configs and does not reload NGINX.
Example:
server {
withSpool true
spool { workers 2 timeout 600 }
web { workers 8 maxRequestLength 50 }
log { level "DEBUG" }
qgis { host "qgis" port 80 }
timeZone "Europe/Berlin"
}
Example:
root.app.monitor.register_periodic_task(self, frequency=60)
root.app.monitor.schedule_reload(with_reconfigure=True)
Source code: gws.server