__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:
parent
5d437839f6
commit
dd167f075d
8 changed files with 41 additions and 11 deletions
|
@ -1,8 +1,11 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=NetBox Request Queue Worker
|
Description=NetBox Request Queue Worker
|
||||||
Documentation=https://netbox.readthedocs.io/en/stable/
|
Documentation=https://netbox.readthedocs.io/en/stable/
|
||||||
After=network-online.target
|
PartOf=netbox.service
|
||||||
Wants=network-online.target
|
Wants=network.target
|
||||||
|
After=netbox.service
|
||||||
|
After=network.target
|
||||||
|
After=redis-server.service postgresql.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=NetBox Service Wrapper
|
Description=NetBox Service Wrapper
|
||||||
Documentation=https://netbox.readthedocs.io/en/stable/
|
Documentation=https://netbox.readthedocs.io/en/stable/
|
||||||
After=network.target
|
|
||||||
Wants=network.target
|
Wants=network.target
|
||||||
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
|
|
|
@ -105,9 +105,10 @@ fi
|
||||||
|
|
||||||
# check for changes
|
# check for changes
|
||||||
if [ "$changes" = "yes" ]; then
|
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
|
cat << EOF
|
||||||
# Restart service.
|
# Restart service. All required services are included with netbox.service.
|
||||||
service netbox restart
|
systemctl restart netbox
|
||||||
service netbox-rq restart
|
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -12,7 +12,11 @@ This (singleton) type installs and configures a NetBox instance, a web
|
||||||
application to help manage and document computer networks.
|
application to help manage and document computer networks.
|
||||||
|
|
||||||
It installs it with the user ``netbox`` at ``/opt/netbox`` with `python-venv`.
|
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
|
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`.
|
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>`
|
<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.
|
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
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
Description=NetBox Gunicorn WSGI Service
|
Description=NetBox Gunicorn WSGI Service
|
||||||
Documentation=https://netbox.readthedocs.io/en/stable/
|
Documentation=https://netbox.readthedocs.io/en/stable/
|
||||||
PartOf=netbox.service
|
PartOf=netbox.service
|
||||||
|
Requires=netbox-rq.service
|
||||||
|
Wants=network.target
|
||||||
After=netbox.service
|
After=netbox.service
|
||||||
After=network.target
|
After=network.target
|
||||||
Wants=network.target
|
After=redis-server.service postgresql.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
|
|
|
@ -34,7 +34,7 @@ case "$state" in
|
||||||
if [ "$do_restart" ] && [ "$state" != "disabled" ]; then
|
if [ "$do_restart" ] && [ "$state" != "disabled" ]; then
|
||||||
cat << EOF
|
cat << EOF
|
||||||
# Restart service
|
# Restart service
|
||||||
service gunicorn-netbox restart
|
systemctl restart gunicorn-netbox
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
Description=Netbox uWSGI WSGI Service
|
Description=Netbox uWSGI WSGI Service
|
||||||
Documentation=https://netbox.readthedocs.io/en/stable/
|
Documentation=https://netbox.readthedocs.io/en/stable/
|
||||||
PartOf=netbox.service
|
PartOf=netbox.service
|
||||||
|
Requires=netbox-rq.service
|
||||||
|
Wants=network.target
|
||||||
After=netbox.service
|
After=netbox.service
|
||||||
After=network.target
|
After=network.target
|
||||||
Wants=network.target
|
After=redis-server.service postgresql.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
|
|
|
@ -30,7 +30,7 @@ case "$state" in
|
||||||
if [ "$do_restart" ] && [ "$state" != "disabled" ]; then
|
if [ "$do_restart" ] && [ "$state" != "disabled" ]; then
|
||||||
cat << EOF
|
cat << EOF
|
||||||
# Restart service
|
# Restart service
|
||||||
service uwsgi-netbox restart
|
systemctl restart uwsgi-netbox
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in a new issue