Skip to content

Commit 173c530

Browse files
Merge pull request #4064 from netbox-community/3961-change-systemd-instructions
Fixes: #3961 - Update migrate-to-systemd.md documentation
2 parents 0a87df4 + d746448 commit 173c530

File tree

1 file changed

+28
-71
lines changed

1 file changed

+28
-71
lines changed

docs/installation/migrating-to-systemd.md

Lines changed: 28 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -12,89 +12,46 @@ Migration is not required, as supervisord will still continue to function.
1212

1313
### systemd configuration:
1414

15-
Copy or link contrib/netbox.service and contrib/netbox-rq.service to /etc/systemd/system/netbox.service and /etc/systemd/system/netbox-rq.service
15+
We'll use systemd to control the daemonization of NetBox services. First, copy `contrib/netbox.service` and `contrib/netbox-rq.service` to the `/etc/systemd/system/` directory:
1616

1717
```no-highlight
18-
# cp contrib/netbox.service /etc/systemd/system/netbox.service
19-
# cp contrib/netbox-rq.service /etc/systemd/system/netbox-rq.service
18+
# cp contrib/*.service /etc/systemd/system/
2019
```
2120

22-
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`:
21+
!!! note
22+
These service files assume that gunicorn is installed at `/usr/local/bin/gunicorn`. If the output of `which gunicorn` indicates a different path, you'll need to correct the `ExecStart` path in both files.
2323

24-
```no-highlight
25-
/usr/local/bin/gunicorn --pid ${PidPath} --pythonpath ${WorkingDirectory}/netbox --config ${ConfigPath} netbox.wsgi
26-
```
27-
28-
```no-highlight
29-
User=www-data
30-
Group=www-data
31-
```
32-
33-
Copy contrib/netbox.env to /etc/sysconfig/netbox.env
34-
35-
```no-highlight
36-
# cp contrib/netbox.env /etc/sysconfig/netbox.env
37-
```
38-
39-
Edit /etc/sysconfig/netbox.env and change the settings as required. Update the `WorkingDirectory` variable if needed.
40-
41-
```no-highlight
42-
# Name is the Process Name
43-
#
44-
Name = 'Netbox'
45-
46-
# ConfigPath is the path to the gunicorn config file.
47-
#
48-
ConfigPath=/opt/netbox/gunicorn.conf
49-
50-
# WorkingDirectory is the Working Directory for Netbox.
51-
#
52-
WorkingDirectory=/opt/netbox/
53-
54-
# PidPath is the path to the pid for the netbox WSGI
55-
#
56-
PidPath=/var/run/netbox.pid
57-
```
24+
!!! note
25+
You may need to modify the user that the systemd service runs as. Please verify the user for httpd on your specific release and edit both files to match your httpd service under user and group. The username could be "nobody", "nginx", "apache", "www-data" or any number of other usernames.
5826

59-
Copy contrib/gunicorn.conf to gunicorn.conf
27+
Then, start the `netbox` and `netbox-rq` services and enable them to initiate at boot time:
6028

6129
```no-highlight
62-
# cp contrib/gunicorn.conf to gunicorn.conf
30+
# systemctl daemon-reload
31+
# systemctl start netbox.service
32+
# systemctl start netbox-rq.service
33+
# systemctl enable netbox.service
34+
# systemctl enable netbox-rq.service
6335
```
6436

65-
Edit gunicorn.conf and change the settings as required.
37+
You can use the command `systemctl status netbox` to verify that the WSGI service is running:
6638

6739
```
68-
# Bind is the ip and port that the Netbox WSGI should bind to
69-
#
70-
bind='127.0.0.1:8001'
71-
72-
# Workers is the number of workers that GUnicorn should spawn.
73-
# Workers should be: cores * 2 + 1. So if you have 8 cores, it would be 17.
74-
#
75-
workers=3
76-
77-
# Threads
78-
# The number of threads for handling requests
79-
#
80-
threads=3
81-
82-
# Timeout is the timeout between gunicorn receiving a request and returning a response (or failing with a 500 error)
83-
#
84-
timeout=120
85-
86-
# ErrorLog
87-
# ErrorLog is the logfile for the ErrorLog
88-
#
89-
errorlog='/opt/netbox/netbox.log'
40+
# systemctl status netbox.service
41+
● netbox.service - NetBox WSGI Service
42+
Loaded: loaded (/etc/systemd/system/netbox.service; enabled; vendor preset: enabled)
43+
Active: active (running) since Thu 2019-12-12 19:23:40 UTC; 25s ago
44+
Docs: https://netbox.readthedocs.io/en/stable/
45+
Main PID: 11993 (gunicorn)
46+
Tasks: 6 (limit: 2362)
47+
CGroup: /system.slice/netbox.service
48+
├─11993 /usr/bin/python3 /usr/local/bin/gunicorn --pid /var/tmp/netbox.pid --pythonpath /opt/netbox/...
49+
├─12015 /usr/bin/python3 /usr/local/bin/gunicorn --pid /var/tmp/netbox.pid --pythonpath /opt/netbox/...
50+
├─12016 /usr/bin/python3 /usr/local/bin/gunicorn --pid /var/tmp/netbox.pid --pythonpath /opt/netbox/...
51+
...
9052
```
9153

92-
Finally, start the `netbox` and `netbox-rq` services and enable them to initiate at boot time:
54+
At this point, you should be able to connect to the 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.
9355

94-
```no-highlight
95-
# systemctl daemon-reload
96-
# systemctl start netbox.service
97-
# systemctl start netbox-rq.service
98-
# systemctl enable netbox.service
99-
# systemctl enable netbox-rq.service
100-
```
56+
!!! info
57+
Please keep in mind that the configurations provided here are bare minimums required to get NetBox up and running. You may want to make adjustments to better suit your production environment.

0 commit comments

Comments
 (0)