__netbox*: fix service restart order

Cause of corrupt databases if the services are restarted incorrectly,
the order and dependencies are adjusted. Now, the `netbox-rq` service
will be included in restarts of `netbox` and required for the WSGI
servers that it must running.

For these changes, the restart command of `__netbox` was adjusted. The
other ones where edited too, to use the same command.

All services now require redis and postgresql to be started before them
to prevent any start order issues.

If someone asked for what the RQ worker is required, see here:
 https://netbox.readthedocs.io/en/stable/additional-features/webhooks/#webhook-processing
This commit is contained in:
matze 2020-09-09 19:08:46 +02:00
parent 5d437839f6
commit dd167f075d
8 changed files with 41 additions and 11 deletions

View File

@ -1,8 +1,11 @@
[Unit]
Description=NetBox Request Queue Worker
Documentation=https://netbox.readthedocs.io/en/stable/
After=network-online.target
Wants=network-online.target
PartOf=netbox.service
Wants=network.target
After=netbox.service
After=network.target
After=redis-server.service postgresql.service
[Service]
Type=simple

View File

@ -1,8 +1,8 @@
[Unit]
Description=NetBox Service Wrapper
Documentation=https://netbox.readthedocs.io/en/stable/
After=network.target
Wants=network.target
After=network.target
[Service]
Type=oneshot

View File

@ -105,9 +105,10 @@ fi
# check for changes
if [ "$changes" = "yes" ]; then
# to avoid database corruption at config changes, both services must be
# stopped at the same time (noted in the manual, too).
cat << EOF
# Restart service.
service netbox restart
service netbox-rq restart
# Restart service. All required services are included with netbox.service.
systemctl restart netbox
EOF
fi

View File

@ -12,7 +12,11 @@ This (singleton) type installs and configures a NetBox instance, a web
application to help manage and document computer networks.
It installs it with the user ``netbox`` at ``/opt/netbox`` with `python-venv`.
It setup systemd unit files for the services `netbox` and `netbox-rq`. To
It setup systemd unit files for the services `netbox` and `netbox-rq`. The
`netbox` service only wrap all netbox related services, e.g. restarting and
so one will be delegated to all related services.
The application is still not accessable because WSGI server is required. To
access the application through WSGI, uWSGI or Gunicorn can be used. The setup
can be done via there own types `__netbox_gunicorn` and `__netbox_uwsgi`.
@ -229,6 +233,24 @@ If you not setup ldap authentification, you may be interested into how to
<https://netbox.readthedocs.io/en/stable/installation/3-netbox/#create-a-super-user>`
directly on the machine to be able to access and use NetBox.
If you change a configuration, the database may go corrupt if two instances of
the application are running with different configurations at the same time.
This most commonly happens when the WSGI server and RQ-worker restarts after a
configuration change. This occours in the following case for example:
.. code-block:: sh
systemctl restart gunicorn-netbox # WSGI-server already online with new
# configuration after this command.
systemctl restart netbox-rq # RQ-Worker still worked with the old
# configuration till here.
This type handles the restart of both services correctly to avoid such database
corruptions. To safely manual restart the whole netbox instance manual, simply
restart all services in one ``systemctl restart netbox`` command, as it ensures
that first all services are shut down before starting one of them. The service
``netbox`` wraps all required services that are available.
SEE ALSO
--------

View File

@ -2,9 +2,11 @@
Description=NetBox Gunicorn WSGI Service
Documentation=https://netbox.readthedocs.io/en/stable/
PartOf=netbox.service
Requires=netbox-rq.service
Wants=network.target
After=netbox.service
After=network.target
Wants=network.target
After=redis-server.service postgresql.service
[Service]
Type=simple

View File

@ -34,7 +34,7 @@ case "$state" in
if [ "$do_restart" ] && [ "$state" != "disabled" ]; then
cat << EOF
# Restart service
service gunicorn-netbox restart
systemctl restart gunicorn-netbox
EOF
fi
;;

View File

@ -2,9 +2,11 @@
Description=Netbox uWSGI WSGI Service
Documentation=https://netbox.readthedocs.io/en/stable/
PartOf=netbox.service
Requires=netbox-rq.service
Wants=network.target
After=netbox.service
After=network.target
Wants=network.target
After=redis-server.service postgresql.service
[Service]
Type=simple

View File

@ -30,7 +30,7 @@ case "$state" in
if [ "$do_restart" ] && [ "$state" != "disabled" ]; then
cat << EOF
# Restart service
service uwsgi-netbox restart
systemctl restart uwsgi-netbox
EOF
fi
;;