__netbox: add wrapper service to manage the wsgi services

The wrapper service will "control" the services added from the
__netbox_* types to provide a general interface. This is more dynamic
than the alias approach used previously. Through this, it is possible
to handle multiple wsgi services for netbox - if this works ..

See as a reference:
  http://alesnosek.com/blog/2016/12/04/controlling-a-multi-service-application-with-systemd/
This commit is contained in:
matze 2020-09-01 10:02:08 +02:00
parent 1ef4420c53
commit 9d8b3ebe74
9 changed files with 25 additions and 22 deletions

View file

@ -0,0 +1,12 @@
[Unit]
Description=NetBox Service Wrapper
Documentation=https://netbox.readthedocs.io/en/stable/
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

View file

@ -98,6 +98,7 @@ fi
if [ "$changes" = "yes" ]; then
cat << EOF
# Restart service.
service netbox restart
service netbox-rq restart
EOF
fi

View file

@ -204,7 +204,9 @@ $SECRET_KEY
SECRET
# Upload systemd unit for worker service
__systemd_unit netbox-rq.service \
--source "$__type/files/netbox-rq.service" \
--enablement-state enabled
# Upload systemd unit for worker and wsgi service
for unit in netbox netbox-rq; do
__systemd_unit $unit.service \
--source "$__type/files/$unit.service" \
--enablement-state enabled
done

View file

@ -1,6 +1,8 @@
[Unit]
Description=NetBox Gunicorn WSGI Service
Documentation=https://netbox.readthedocs.io/en/stable/
PartOf=netbox.service
After=netbox.service
After=network-online.target
Wants=network-online.target
@ -19,5 +21,4 @@ RestartSec=30
PrivateTmp=true
[Install]
Alias=netbox.service
WantedBy=multi-user.target

View file

@ -19,12 +19,6 @@ if grep -q "^__file/opt/netbox/gunicorn.py:" "$__messages_in"; then
printf "configured\n" >> "$__messages_out"
fi
# application
if grep -q "^__netbox:" "$__messages_in"; then
do_restart=yes
# no message cause it should be obvious
fi
# restart gunicorn
if [ "$do_restart" ]; then

View file

@ -37,8 +37,7 @@ updated $old to $new
configured
Configuration for gunicorn changed.
In both cases, and at messages from the `__netbox` type, it restarts the
service to using the up-to-date version.
In both cases, it restarts the service to use the up-to-date version.
EXAMPLES

View file

@ -1,6 +1,8 @@
[Unit]
Description=Netbox uWSGI WSGI Service
Documentation=https://netbox.readthedocs.io/en/stable/
PartOf=netbox.service
After=netbox.service
After=network-online.target
Wants=network-online.target
@ -19,5 +21,4 @@ RestartSec=30
PrivateTmp=true
[Install]
Alias=netbox.service
WantedBy=multi-user.target

View file

@ -19,12 +19,6 @@ if grep -q "^__file/opt/netbox/uwsgi.ini:" "$__messages_in"; then
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

View file

@ -39,8 +39,7 @@ 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.
In all cases, it restarts the service to use the up-to-date version.
EXAMPLES