__netbox_uwsgi: enable further protocols to bind to

Enables multiple protocols like fastcgi or HTTP to bind to. This makes
it more flexible to use.

Also, a little fix for __netbox was done: correctly output a error msg.
This commit is contained in:
matze 2020-09-05 11:20:20 +02:00
parent 2805b6beff
commit 243e34f0a5
4 changed files with 55 additions and 9 deletions

View file

@ -127,7 +127,7 @@ fi
export SMTP_USE_SSL
if [ -f "$__object/parameter/smtp-use-tls" ]; then
if [ "$SMTP_USE_SSL" = "True" ]; then
echo "options --smtp-use-ssl and --smtp-use-tls are not compatible"
echo "options --smtp-use-ssl and --smtp-use-tls are not compatible" >&2
exit 2
fi
SMTP_USE_TLS="True"

View file

@ -2,6 +2,18 @@
# Generates uwsgi config
# see https://uwsgi-docs.readthedocs.io/en/latest/Options.html
# or https://uwsgi-docs-additions.readthedocs.io/en/latest/Options.html
# params:
# 1: parameter name
# 2: parameter value file
#
# output: the lines for the configuration option
multi_options() {
while read -r line; do
printf "%s = %s\n" "$1" "$line"
done < "$2"
}
# fix missing $__explorer
# see https://code.ungleich.ch/ungleich-public/cdist/-/issues/834
@ -13,8 +25,21 @@ cores="$(cat "$__explorer/cpu_cores")"
cat << EOF
[uwsgi]
; socket to bind
socket = $HOST
; socket(s) to bind
EOF
# special protocol to bind
for param in $(find "$__object/parameter/" -maxdepth 1 -name "*-bind" -print); do
multi_options "$(basename "$param" | awk -F'-' '{print $1}')-socket" "$param"
socket_changes=yes
done
# else, default bind to
if [ -z "$socket_changes" ]; then
multi_options "socket" "$__object/parameter/bind-to"
fi
cat << EOF
; processes and threads
processes = $(( 2*cores + 1 ))

View file

@ -9,10 +9,11 @@ cdist-type__netbox_uwsgi - Run NetBox with uWSGI
DESCRIPTION
-----------
This (singleton) type installs uWSGI into the NetBox `python-venv`. It hosts
the NetBox WSGI application over the WSGI protocol. A further server must be
installed to provide it as HTTP. This application is available via the
`uwsgi-netbox` systemd service. It is controllable via the `netbox` wrapper
service, too.
the NetBox WSGI application via the WSGI protocol. A further server must be
installed to provide it as HTTP and serve static content. It supports multiple
protocols like uwsgi, fastcgi or HTTP to comunicate with the proxy server. This
application is available via the `uwsgi-netbox` systemd service. It is
controllable via the `netbox` wrapper service, too.
REQUIRED PARAMETERS
@ -24,7 +25,15 @@ OPTIONAL PARAMETERS
-------------------
bind-to
The socket uwsgi should bind to. Must be UNIX/TCP for the uwsgi protocol.
Defaults to ``127.0.0.1:3031``.
Defaults to ``127.0.0.1:3031``. Can be set multiple times.
uwsgi-bind
http-bind
fastcgi-bind
scgi-bind
Bind the application to a specific protocol instead of implicit uwsgi via
``--bind-to``. If such parameter given, ``--bind-to`` will be ignored. Must
be a UNIX/TCP socket. Can be set multiple times.
BOOLEAN PARAMETERS
@ -55,10 +64,18 @@ EXAMPLES
__netbox $args
require="__netbox" __netbox_uwsgi
# with special bind
# with multiple binds
__netbox $args
require="__netbox" __netbox_uwsgi --bind-to 0.0.0.0:3032 \
--bind-to 0.0.0.0:3033
# with multiple protocols
# parameter `--bind-to` will be ignored
__netbox $args
require="__netbox" __netbox_uwsgi --uwsgi-bind 0.0.0.0:3031 \
--http-bind 0.0.0.0:8080 \
--fastcgi-bind 1.2.3.4:5678
SEE ALSO
--------

View file

@ -1 +1,5 @@
bind-to
uwsgi-bind
http-bind
fastcgi-bind
scgi-bind