Skip to content

Commit

Permalink
Closes netbox-community#2902 - Migrate to systemd from supervisord
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSheps committed Feb 15, 2019
1 parent 971f3cd commit 1eecb9b
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
24 changes: 24 additions & 0 deletions contrib/netbox-rq.service
@@ -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

User=$User
Group=$Group

WorkingDirectory=$WorkingDirectory

ExecStart=/usr/bin/python3 $WorkingDirectory/netbox/manage.py rqworker

Restart=on-failure
RestartSec=30
PrivateTmp=true

[Install]
WantedBy=multi-user.target
48 changes: 48 additions & 0 deletions contrib/netbox.env
@@ -0,0 +1,48 @@
# Name is the Process Name
#
Name = 'Netbox'

# WorkingDirectory is the Working Directory for Netbox.
#
WorkingDirectory='/usr/local/netbox/'

# User is the user the Netbox WSGI should run as
#
User='www-data'

# Group is the group the Netbox WSGI should run as
#
Group='www-data'


# 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'

# CaptureOutput
# CaptureOutput is a binary option about whether stdout/stderr should be sent to the ErrorLog
#
# CaptureOutput=False
24 changes: 24 additions & 0 deletions contrib/netbox@.service
@@ -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

User=$User
Group=$Group
PIDFile=$PidPath
WorkingDirectory=$WorkingDirectory

ExecStart=/usr/bin/gunicorn --pid $PidPath --bind $Bind --workers $Workers --timeout $Timeout --errorlog $ErrorLog --capture_output $CaptureOutput netbox.wsgi

Restart=on-failure
RestartSec=30
PrivateTmp=true

[Install]
WantedBy=multi-user.target
38 changes: 16 additions & 22 deletions docs/installation/3-http-daemon.md
Expand Up @@ -108,42 +108,36 @@ 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:
Copy contrib/netbox.env to /etc/sysconfig/netbox.env

```no-highlight
# apt-get install -y supervisor
# mkdir /etc/sysconfig/netbox.env
# copy contrib/netbox.env to /etc/sysconfig/netbox.env
```

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`.
Edit /etc/sysconfig/netbox.env and change the settings as required

```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
# vi /etc/sysconfig/netbox.env
```

Then, restart the supervisor service to detect and run the gunicorn service:
Then, restart the systemd daemon service to detect the netbox service and start the netbox service:

```no-highlight
# service supervisor restart
# systemctl daemon-reload
# systemctl start netbox.service
# systemctl enable netbox.service
# 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.
Expand Down
2 changes: 2 additions & 0 deletions docs/installation/index.md
Expand Up @@ -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.
41 changes: 41 additions & 0 deletions docs/installation/migrating-to-systemd.md
@@ -0,0 +1,41 @@
# 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
```

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

```no-highlight
# vi /etc/sysconfig/netbox.env
```

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
# systemctl start netbox-rq.service
# systemctl enable netbox-rq.service
```
4 changes: 2 additions & 2 deletions docs/installation/upgrading.md
Expand Up @@ -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
```

0 comments on commit 1eecb9b

Please sign in to comment.