Closes #2902 - Migrate to systemd from supervisord

This commit is contained in:
dansheps 2019-02-15 13:30:49 -06:00
parent 971f3cd63c
commit ae6316839b
9 changed files with 295 additions and 25 deletions

View File

@ -2,6 +2,7 @@ v2.5.7 (FUTURE)
## Enhancements
* [#2902](https://github.com/digitalocean/netbox/issues/2902) - Replace supervisord with systemd
* [#2357](https://github.com/digitalocean/netbox/issues/2357) - Enable filtering of devices by rack face
* [#2903](https://github.com/digitalocean/netbox/issues/2903) - Clarify purpose of tags field on interface edit form

24
contrib/netbox-rq.service Normal file
View File

@ -0,0 +1,24 @@
[Unit]
Description=Netbox RQ Worker
Documentation=https://netbox.readthedocs.io/en/stable/
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/netbox.env
User=www-data
Group=www-data
WorkingDirectory=$WorkingDirectory
ExecStart=/usr/bin/python3 $WorkingDirectory/netbox/manage.py rqworker
Restart=on-failure
RestartSec=30
PrivateTmp=true
[Install]
WantedBy=multi-user.target

43
contrib/netbox.env Normal file
View File

@ -0,0 +1,43 @@
# Name is the Process Name
#
Name = 'Netbox'
# GUExec is the gunicorn executable path
#
GUExec=/bin/gunicorn
# WorkingDirectory is the Working Directory for Netbox.
#
WorkingDirectory=/usr/local/netbox/
# PidPath is the path to the pid for the netbox WSGI
#
PidPath=/var/run/netbox.pid
# Bind is the ip and port that the Netbox WSGI should bind to
#
Bind='127.0.0.1:8001'
# Workers is the number of workers that GUnicorn should spawn.
# Workers should be: cores * 2 + 1. So if you have 8 cores, it would be 17.
#
Workers=3
# Threads
# The number of threads for handling requests
#
Threads=3
# Timeout is the timeout
#
Timeout=120
# ErrorLog
# ErrorLog is the logfile for the ErrorLog
#
ErrorLog='/usr/local/netbox/netbox.log'
# ExtraArgs
# ExtraArgs is a string of extra arguments for Gunicorn
#
ExtraArgs='--capture-output'

24
contrib/netbox.service Normal file
View File

@ -0,0 +1,24 @@
[Unit]
Description=Netbox WSGI
Documentation=https://netbox.readthedocs.io/en/stable/
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/netbox.env
User=www-data
Group=www-data
PIDFile=${PidPath}
WorkingDirectory=${WorkingDirectory}
ExecStart=/usr/bin/gunicorn --pid ${PidPath} --bind ${Bind} --workers ${Workers} --threads ${Threads} --timeout ${Timeout} --error-log ${ErrorLog} --pythonpath ${WorkingDirectory}/netbox ${ExtraArgs} netbox.wsgi
Restart=on-failure
RestartSec=30
PrivateTmp=true
[Install]
WantedBy=multi-user.target

24
contrib/netbox@.service Normal file
View File

@ -0,0 +1,24 @@
[Unit]
Description=Netbox WSGI
Documentation=https://netbox.readthedocs.io/en/stable/
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/netbox.%i.env
User=www-data
Group=www-data
PIDFile=${PidPath}
WorkingDirectory=${WorkingDirectory}
ExecStart=/usr/bin/gunicorn --pid ${PidPath} --bind ${Bind} --workers ${Workers} --threads ${Threads} --timeout ${Timeout} --error-log ${ErrorLog} --pythonpath ${WorkingDirectory}/netbox ${ExtraArgs} netbox.wsgi
Restart=on-failure
RestartSec=30
PrivateTmp=true
[Install]
WantedBy=multi-user.target

View File

@ -108,42 +108,95 @@ Install gunicorn:
# pip3 install gunicorn
```
Save the following configuration in the root netbox installation path as `gunicorn_config.py` (e.g. `/opt/netbox/gunicorn_config.py` per our example installation). Be sure to verify the location of the gunicorn executable on your server (e.g. `which gunicorn`) and to update the `pythonpath` variable if needed. If using CentOS/RHEL, change the username from `www-data` to `nginx` or `apache`.
# systemd configuration
Copy or link contrib/netbox.service and contrib/netbox-rq.service to /etc/systemd/system/netbox.service and /etc/systemd/system/netbox-rq.service
```no-highlight
command = '/usr/bin/gunicorn'
pythonpath = '/opt/netbox/netbox'
bind = '127.0.0.1:8001'
workers = 3
user = 'www-data'
# copy contrib/netbox.service to /etc/systemd/system/netbox.service
# copy contrib/netbox-rq.service to /etc/systemd/system/netbox-rq.service
```
# supervisord Installation
Install supervisor:
Edit /etc/systemd/system/netbox.service and /etc/systemd/system/netbox-rq.service Be sure to verify the location of the gunicorn executable on your server (e.g. `which gunicorn`). If using CentOS/RHEL. Change the username from `www-data` to `nginx` or `apache`:
```no-highlight
# apt-get install -y supervisor
/usr/bin/gunicorn --pid ${PidPath} --bind ${Bind} --workers ${Workers} --threads ${Threads} --timeout ${Timeout} --error-log ${ErrorLog} --pythonpath ${WorkingDirectory}/netbox ${ExtraArgs} netbox.wsgi
```
Save the following as `/etc/supervisor/conf.d/netbox.conf`. Update the `command` and `directory` paths as needed. If using CentOS/RHEL, change the username from `www-data` to `nginx` or `apache`.
```no-highlight
[program:netbox]
command = gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
directory = /opt/netbox/netbox/
user = www-data
[program:netbox-rqworker]
command = python3 /opt/netbox/netbox/manage.py rqworker
directory = /opt/netbox/netbox/
user = www-data
User=www-data
Group=www-data
```
Then, restart the supervisor service to detect and run the gunicorn service:
Copy contrib/netbox.env to /etc/sysconfig/netbox.env
```no-highlight
# service supervisor restart
# mkdir /etc/sysconfig/netbox.env
# copy contrib/netbox.env to /etc/sysconfig/netbox.env
```
Edit /etc/sysconfig/netbox.env and change the settings as required. Update the `WorkingDirectory` variable if needed.
```no-highlight
# Name is the Process Name
#
Name = 'Netbox'
# GUExec is the gunicorn executable path
#
GUExec=/bin/gunicorn
# WorkingDirectory is the Working Directory for Netbox.
#
WorkingDirectory=/usr/local/netbox/
# PidPath is the path to the pid for the netbox WSGI
#
PidPath=/var/run/netbox.pid
# Bind is the ip and port that the Netbox WSGI should bind to
#
Bind='127.0.0.1:8001'
# Workers is the number of workers that GUnicorn should spawn.
# Workers should be: cores * 2 + 1. So if you have 8 cores, it would be 17.
#
Workers=3
# Threads
# The number of threads for handling requests
#
Threads=3
# Timeout is the timeout
#
Timeout=120
# ErrorLog
# ErrorLog is the logfile for the ErrorLog
#
ErrorLog='/usr/local/netbox/netbox.log'
# ExtraArgs
# ExtraArgs is a string of extra arguments for Gunicorn
#
ExtraArgs='--capture-output'
```
Then, restart the systemd daemon service to detect the netbox service and start the netbox service:
```no-highlight
# systemctl daemon-reload
# systemctl start netbox.service
# systemctl enable netbox.service
```
If using webhooks, also start the Redis worker:
```no-highlight
# systemctl start netbox-rq.service
# systemctl enable netbox-rq.service
```
At this point, you should be able to connect to the nginx HTTP service at the server name or IP address you provided. If you are unable to connect, check that the nginx service is running and properly configured. If you receive a 502 (bad gateway) error, this indicates that gunicorn is misconfigured or not running.

View File

@ -12,3 +12,5 @@ The following sections detail how to set up a new instance of NetBox:
If you are upgrading from an existing installation, please consult the [upgrading guide](upgrading.md).
NetBox v2.5 and later requires Python 3.5 or higher. Please see the instructions for [migrating to Python 3](migrating-to-python3.md) if you are still using Python 2.
Netbox v2.5.7 and later moved to using systemd instead of supervisord. Please see the instructions for [migrating to systemd](migrating-to-systemd.md) if you are still using supervisord.

View File

@ -0,0 +1,99 @@
# Migration
## Ubuntu
### Remove supervisord:
```no-highlight
# apt-get remove -y supervisord
```
### systemd configuration:
Copy or link contrib/netbox.service and contrib/netbox-rq.service to /etc/systemd/system/netbox.service and /etc/systemd/system/netbox-rq.service
```no-highlight
# copy contrib/netbox.service to /etc/systemd/system/netbox.service
# copy contrib/netbox-rq.service to /etc/systemd/system/netbox-rq.service
```
Edit /etc/systemd/system/netbox.service and /etc/systemd/system/netbox-rq.service. Be sure to verify the location of the gunicorn executable on your server (e.g. `which gunicorn`). If using CentOS/RHEL. Change the username from `www-data` to `nginx` or `apache`:
```no-highlight
/usr/bin/gunicorn --pid ${PidPath} --bind ${Bind} --workers ${Workers} --threads ${Threads} --timeout ${Timeout} --error-log ${ErrorLog} --pythonpath ${WorkingDirectory}/netbox ${ExtraArgs} netbox.wsgi
```
```no-highlight
User=www-data
Group=www-data
```
Copy contrib/netbox.env to /etc/sysconfig/netbox.env
```no-highlight
# mkdir /etc/sysconfig/netbox.env
# copy contrib/netbox.env to /etc/sysconfig/netbox.env
```
Edit /etc/sysconfig/netbox.env and change the settings as required. Update the `WorkingDirectory` variable if needed.
```no-highlight
# Name is the Process Name
#
Name = 'Netbox'
# GUExec is the gunicorn executable path
#
GUExec=/bin/gunicorn
# WorkingDirectory is the Working Directory for Netbox.
#
WorkingDirectory=/usr/local/netbox/
# PidPath is the path to the pid for the netbox WSGI
#
PidPath=/var/run/netbox.pid
# Bind is the ip and port that the Netbox WSGI should bind to
#
Bind='127.0.0.1:8001'
# Workers is the number of workers that GUnicorn should spawn.
# Workers should be: cores * 2 + 1. So if you have 8 cores, it would be 17.
#
Workers=3
# Threads
# The number of threads for handling requests
#
Threads=3
# Timeout is the timeout
#
Timeout=120
# ErrorLog
# ErrorLog is the logfile for the ErrorLog
#
ErrorLog='/usr/local/netbox/netbox.log'
# ExtraArgs
# ExtraArgs is a string of extra arguments for Gunicorn
#
ExtraArgs='--capture-output'
```
Then, restart the systemd daemon service to detect the netbox service and start the netbox service:
```no-highlight
# systemctl daemon-reload
# systemctl start netbox.service
# systemctl enable netbox.service
```
If using webhooks, also start the Redis worker:
```no-highlight
# systemctl start netbox-rq.service
# systemctl enable netbox-rq.service
```

View File

@ -83,11 +83,11 @@ This script:
Finally, restart the WSGI service to run the new code. If you followed this guide for the initial installation, this is done using `supervisorctl`:
```no-highlight
# sudo supervisorctl restart netbox
# sudo systemctl restart netbox
```
If using webhooks, also restart the Redis worker:
```no-highlight
# sudo supervisorctl restart netbox-rqworker
# sudo systemctl restart netbox-rqworker
```