forked from ungleich-public/cdist-contrib
__netbox_uwsgi: new type to handle uwsgi for netbox
This commit is contained in:
parent
bbce0030ab
commit
1ef4420c53
13 changed files with 188 additions and 6 deletions
|
@ -89,7 +89,7 @@ EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# meta
|
# meta
|
||||||
printf "configuration\n" >> "$__messages_out"
|
printf "configured\n" >> "$__messages_out"
|
||||||
changes=yes
|
changes=yes
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,7 @@ MESSAGES
|
||||||
installed $VERSION
|
installed $VERSION
|
||||||
Netbox was fresh installed or updated. The new version number is appended.
|
Netbox was fresh installed or updated. The new version number is appended.
|
||||||
|
|
||||||
configuration
|
configured
|
||||||
Some configuration files got updated and therefore the service was
|
Some configuration files got updated and therefore the service was
|
||||||
restarted. This message will not be echoed if configuration got updated due
|
restarted. This message will not be echoed if configuration got updated due
|
||||||
a standard installation.
|
a standard installation.
|
||||||
|
|
|
@ -16,7 +16,7 @@ fi
|
||||||
# configuration changes
|
# configuration changes
|
||||||
if grep -q "^__file/opt/netbox/gunicorn.py:" "$__messages_in"; then
|
if grep -q "^__file/opt/netbox/gunicorn.py:" "$__messages_in"; then
|
||||||
do_restart=yes
|
do_restart=yes
|
||||||
printf "configuration\n" >> "$__messages_out"
|
printf "configured\n" >> "$__messages_out"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# application
|
# application
|
||||||
|
@ -32,5 +32,4 @@ if [ "$do_restart"]; then
|
||||||
# Restart service
|
# Restart service
|
||||||
service gunicorn-netbox restart
|
service gunicorn-netbox restart
|
||||||
EOF
|
EOF
|
||||||
echo restarted >> "$__messages_out"
|
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -34,7 +34,7 @@ MESSAGES
|
||||||
updated $old to $new
|
updated $old to $new
|
||||||
The version of the gunicorn software was updated from `$old` to `$new`.
|
The version of the gunicorn software was updated from `$old` to `$new`.
|
||||||
|
|
||||||
configuration
|
configured
|
||||||
Configuration for gunicorn changed.
|
Configuration for gunicorn changed.
|
||||||
|
|
||||||
In both cases, and at messages from the `__netbox` type, it restarts the
|
In both cases, and at messages from the `__netbox` type, it restarts the
|
||||||
|
|
4
type/__netbox_uwsgi/explorer/installed
Executable file
4
type/__netbox_uwsgi/explorer/installed
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
# print version if available
|
||||||
|
/opt/netbox/venv/bin/pip3 show uwsgi | awk '/Version:/{print $2}'
|
4
type/__netbox_uwsgi/explorer/upgradeable
Executable file
4
type/__netbox_uwsgi/explorer/upgradeable
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
# print latest version if availble
|
||||||
|
/opt/netbox/venv/bin/pip3 list --outdated | awk '$1 == "uwsgi" {print $3}'
|
23
type/__netbox_uwsgi/files/netbox.service
Normal file
23
type/__netbox_uwsgi/files/netbox.service
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Netbox uWSGI WSGI Service
|
||||||
|
Documentation=https://netbox.readthedocs.io/en/stable/
|
||||||
|
After=network-online.target
|
||||||
|
Wants=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
|
||||||
|
User=netbox
|
||||||
|
Group=netbox
|
||||||
|
PIDFile=/var/tmp/netbox.pid
|
||||||
|
WorkingDirectory=/opt/netbox
|
||||||
|
|
||||||
|
ExecStart=/opt/netbox/venv/bin/uwsgi --master --wsgi-file netbox/netbox/wsgi.py uwsgi.ini
|
||||||
|
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=30
|
||||||
|
PrivateTmp=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
Alias=netbox.service
|
||||||
|
WantedBy=multi-user.target
|
22
type/__netbox_uwsgi/files/uwsgi.ini.sh
Executable file
22
type/__netbox_uwsgi/files/uwsgi.ini.sh
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
# Generates uwsgi config
|
||||||
|
# see https://uwsgi-docs.readthedocs.io/en/latest/Options.html
|
||||||
|
|
||||||
|
# fix missing $__explorer
|
||||||
|
# see https://code.ungleich.ch/ungleich-public/cdist/-/issues/834
|
||||||
|
__explorer="$__global/explorer"
|
||||||
|
|
||||||
|
# size workes by cpu
|
||||||
|
cores="$(cat "$__explorer/cpu_cores")"
|
||||||
|
|
||||||
|
|
||||||
|
cat << EOF
|
||||||
|
[uwsgi]
|
||||||
|
; socket to bind
|
||||||
|
socket = $HOST
|
||||||
|
|
||||||
|
; processes and threads
|
||||||
|
processes = $(( 2*cores + 1 ))
|
||||||
|
threads = 2
|
||||||
|
EOF
|
35
type/__netbox_uwsgi/gencode-remote
Executable file
35
type/__netbox_uwsgi/gencode-remote
Executable file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
# not installed
|
||||||
|
if ! [ -s "$__object/explorer/installed" ]; then
|
||||||
|
echo "/opt/netbox/venv/bin/pip3 install uwsgi"
|
||||||
|
do_restart=yes
|
||||||
|
printf "installed\n" >> "$__messages_out"
|
||||||
|
|
||||||
|
# updates available
|
||||||
|
elif [ -s "$__object/explorer/upgradeable" ]; then
|
||||||
|
echo "/opt/netbox/venv/bin/pip3 install --upgrade uwsgi"
|
||||||
|
do_restart=yes
|
||||||
|
printf "upgraded\n" >> "$__messages_out"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# changed configuration
|
||||||
|
if grep -q "^__file/opt/netbox/uwsgi.ini:" "$__messages_in"; then
|
||||||
|
do_restart=yes
|
||||||
|
printf "configured\n" >> "$__messages_out"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# application
|
||||||
|
if grep -q "^__netbox:" "$__messages_in"; then
|
||||||
|
do_restart=yes
|
||||||
|
# no messages cause this is obvious
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# restart uwsgi
|
||||||
|
if [ "$do_restart" ]; then
|
||||||
|
cat << EOF
|
||||||
|
# Restart service
|
||||||
|
service uwsgi-netbox restart
|
||||||
|
EOF
|
||||||
|
fi
|
75
type/__netbox_uwsgi/man.rst
Normal file
75
type/__netbox_uwsgi/man.rst
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
cdist-type__netbox_uwsgi(7)
|
||||||
|
===========================
|
||||||
|
|
||||||
|
NAME
|
||||||
|
----
|
||||||
|
cdist-type__netbox_uwsgi - run netbox with uwsgi
|
||||||
|
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
-----------
|
||||||
|
This space intentionally left blank.
|
||||||
|
|
||||||
|
|
||||||
|
REQUIRED PARAMETERS
|
||||||
|
-------------------
|
||||||
|
None.
|
||||||
|
|
||||||
|
|
||||||
|
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``.
|
||||||
|
|
||||||
|
|
||||||
|
BOOLEAN PARAMETERS
|
||||||
|
------------------
|
||||||
|
None.
|
||||||
|
|
||||||
|
|
||||||
|
MESSAGES
|
||||||
|
--------
|
||||||
|
installed
|
||||||
|
The uwsgi service was installed.
|
||||||
|
|
||||||
|
upgraded
|
||||||
|
The uwsgi service was upgraded.
|
||||||
|
|
||||||
|
configured
|
||||||
|
The uwsgi configuration got updated.
|
||||||
|
|
||||||
|
In both cases, and at messages from the `__netbox` type, it restarts the
|
||||||
|
service to using the up-to-date version.
|
||||||
|
|
||||||
|
|
||||||
|
EXAMPLES
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: sh
|
||||||
|
|
||||||
|
# simple
|
||||||
|
__netbox $args
|
||||||
|
require="__netbox" __netbox_uwsgi
|
||||||
|
|
||||||
|
# with special bind
|
||||||
|
require="__netbox" __netbox_uwsgi --bind-to 0.0.0.0:3032 \
|
||||||
|
--bind-to 0.0.0.0:3033
|
||||||
|
|
||||||
|
|
||||||
|
SEE ALSO
|
||||||
|
--------
|
||||||
|
:strong:`TODO`\ (7)
|
||||||
|
|
||||||
|
|
||||||
|
AUTHORS
|
||||||
|
-------
|
||||||
|
Matthias Stecher <matthiasstecher@gmx.de>
|
||||||
|
|
||||||
|
|
||||||
|
COPYING
|
||||||
|
-------
|
||||||
|
Copyright \(C) 2020 Matthias Stecher. You can redistribute it
|
||||||
|
and/or modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
18
type/__netbox_uwsgi/manifest
Executable file
18
type/__netbox_uwsgi/manifest
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
HOST="$__object/parameter/bind-to"
|
||||||
|
export HOST
|
||||||
|
|
||||||
|
# process template
|
||||||
|
mkdir "$__object/files"
|
||||||
|
"$__type/files/uwsgi.ini.sh" > "$__object/files/uwsgi.ini"
|
||||||
|
|
||||||
|
# uwsgi config file
|
||||||
|
# TODO maybe patching with __key_value cause of .ini ?
|
||||||
|
__file /opt/netbox/uwsgi.ini \
|
||||||
|
--mode 644 --source "$__object/files/uwsgi.ini"
|
||||||
|
|
||||||
|
# install service file
|
||||||
|
__systemd_unit uwsgi-netbox.service \
|
||||||
|
--source "$__type/files/netbox.service" \
|
||||||
|
--enablement-state enabled --restart
|
1
type/__netbox_uwsgi/parameter/default/bind-to
Normal file
1
type/__netbox_uwsgi/parameter/default/bind-to
Normal file
|
@ -0,0 +1 @@
|
||||||
|
127.0.0.1:3031
|
1
type/__netbox_uwsgi/parameter/optional_multiple
Normal file
1
type/__netbox_uwsgi/parameter/optional_multiple
Normal file
|
@ -0,0 +1 @@
|
||||||
|
bind-to
|
Loading…
Reference in a new issue