From c78df40cb005a13595446a93fe80785c9dd404e3 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Feb 2020 11:40:31 -0500 Subject: [PATCH 01/12] Refactor installtion docs --- docs/additional-features/napalm.md | 2 +- docs/installation/1-postgresql.md | 19 ++++---- docs/installation/2-redis.md | 22 +++++++++ .../installation/{2-netbox.md => 3-netbox.md} | 46 ++++++++++--------- .../{3-http-daemon.md => 4-http-daemon.md} | 10 ++-- docs/installation/{4-ldap.md => 5-ldap.md} | 16 +++---- docs/installation/index.md | 7 +-- mkdocs.yml | 21 +++++---- 8 files changed, 86 insertions(+), 57 deletions(-) create mode 100644 docs/installation/2-redis.md rename docs/installation/{2-netbox.md => 3-netbox.md} (94%) rename docs/installation/{3-http-daemon.md => 4-http-daemon.md} (98%) rename docs/installation/{4-ldap.md => 5-ldap.md} (96%) diff --git a/docs/additional-features/napalm.md b/docs/additional-features/napalm.md index c8e8b8b3a..304d892c4 100644 --- a/docs/additional-features/napalm.md +++ b/docs/additional-features/napalm.md @@ -3,7 +3,7 @@ NetBox supports integration with the [NAPALM automation](https://napalm-automation.net/) library. NAPALM allows NetBox to fetch live data from devices and return it to a requester via its REST API. !!! info - To enable the integration, the NAPALM library must be installed. See [installation steps](../../installation/2-netbox/#napalm-automation-optional) for more information. + To enable the integration, the NAPALM library must be installed. See [installation steps](../../installation/3-netbox/#napalm-automation-optional) for more information. ``` GET /api/dcim/devices/1/napalm/?method=get_environment diff --git a/docs/installation/1-postgresql.md b/docs/installation/1-postgresql.md index 376a62ae2..f6f217994 100644 --- a/docs/installation/1-postgresql.md +++ b/docs/installation/1-postgresql.md @@ -1,14 +1,13 @@ -NetBox requires a PostgreSQL database to store data. This can be hosted locally or on a remote server. (Please note that MySQL is not supported, as NetBox leverages PostgreSQL's built-in [network address types](https://www.postgresql.org/docs/current/static/datatype-net-types.html).) - -!!! note - The installation instructions provided here have been tested to work on Ubuntu 18.04 and CentOS 7.5. The particular commands needed to install dependencies on other distributions may vary significantly. Unfortunately, this is outside the control of the NetBox maintainers. Please consult your distribution's documentation for assistance with any errors. +This section entails the installation and configuration of a local PostgreSQL database. If you already have a PostgreSQL database service in place, skip to [the next section](2-redis.md). !!! warning - NetBox requires PostgreSQL 9.4 or higher. + NetBox requires PostgreSQL 9.4 or higher. Please note that MySQL and other relational databases are **not** supported. -# Installation +The installation instructions provided here have been tested to work on Ubuntu 18.04 and CentOS 7.5. The particular commands needed to install dependencies on other distributions may vary significantly. Unfortunately, this is outside the control of the NetBox maintainers. Please consult your distribution's documentation for assistance with any errors. -**Ubuntu** +## Installation + +#### Ubuntu If a recent enough version of PostgreSQL is not available through your distribution's package manager, you'll need to install it from an official [PostgreSQL repository](https://wiki.postgresql.org/wiki/Apt). @@ -17,7 +16,7 @@ If a recent enough version of PostgreSQL is not available through your distribut # apt-get install -y postgresql libpq-dev ``` -**CentOS** +#### CentOS CentOS 7.5 does not ship with a recent enough version of PostgreSQL, so it will need to be installed from an external repository. The instructions below show the installation of PostgreSQL 9.6. @@ -41,7 +40,7 @@ Then, start the service and enable it to run at boot: # systemctl enable postgresql-9.6 ``` -# Database Creation +## Database Creation At a minimum, we need to create a database for NetBox and assign it a username and password for authentication. This is done with the following commands. @@ -62,6 +61,8 @@ GRANT postgres=# \q ``` +## Verify Service Status + You can verify that authentication works issuing the following command and providing the configured password. (Replace `localhost` with your database server if using a remote database.) ```no-highlight diff --git a/docs/installation/2-redis.md b/docs/installation/2-redis.md new file mode 100644 index 000000000..0ef7de78a --- /dev/null +++ b/docs/installation/2-redis.md @@ -0,0 +1,22 @@ +[Redis](https://redis.io/) is an in-memory key-value store which NetBox employs for caching and queuing. This section entails the installation and configuration of a local Redis instance. If you already have a Redis service in place, skip to [the next section](3-netbox.md). + +#### Ubuntu + +```no-highlight +# apt-get install -y redis-server +``` + +#### CentOS + +```no-highlight +# yum install -y redis +``` + +## Verify Service Status + +Use the `redis-cli` utility to ensure the Redis service is functional: + +```no-highlight +$ redis-cli ping +PONG +``` diff --git a/docs/installation/2-netbox.md b/docs/installation/3-netbox.md similarity index 94% rename from docs/installation/2-netbox.md rename to docs/installation/3-netbox.md index cbe2c70c0..5c29b3996 100644 --- a/docs/installation/2-netbox.md +++ b/docs/installation/3-netbox.md @@ -1,25 +1,27 @@ -# Installation - This section of the documentation discusses installing and configuring the NetBox application. Begin by installing all system packages required by NetBox and its dependencies: -**Ubuntu** +## Install System Packages + +#### Ubuntu ```no-highlight -# apt-get install -y python3 python3-pip python3-dev build-essential libxml2-dev libxslt1-dev libffi-dev libpq-dev libssl-dev redis-server zlib1g-dev +# apt-get install -y python3 python3-pip python3-dev build-essential libxml2-dev libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev ``` -**CentOS** +#### CentOS ```no-highlight # yum install -y epel-release -# yum install -y gcc python36 python36-devel python36-setuptools libxml2-devel libxslt-devel libffi-devel openssl-devel redhat-rpm-config redis +# yum install -y gcc python36 python36-devel python36-setuptools libxml2-devel libxslt-devel libffi-devel openssl-devel redhat-rpm-config # easy_install-3.6 pip # ln -s /usr/bin/python3.6 /usr/bin/python3 ``` +## Download NetBox + You may opt to install NetBox either from a numbered release or by cloning the master branch of its repository on GitHub. -## Option A: Download a Release +### Option A: Download a Release Download the [latest stable release](https://github.com/netbox-community/netbox/releases) from GitHub as a tarball or ZIP archive and extract it to your desired path. In this example, we'll use `/opt/netbox`. @@ -31,7 +33,7 @@ Download the [latest stable release](https://github.com/netbox-community/netbox/ # cd /opt/netbox/ ``` -## Option B: Clone the Git Repository +### Option B: Clone the Git Repository Create the base directory for the NetBox installation. For this guide, we'll use `/opt/netbox`. @@ -41,13 +43,13 @@ Create the base directory for the NetBox installation. For this guide, we'll use If `git` is not already installed, install it: -**Ubuntu** +#### Ubuntu ```no-highlight # apt-get install -y git ``` -**CentOS** +#### CentOS ```no-highlight # yum install -y git @@ -71,7 +73,7 @@ Checking connectivity... done. `# chown -R netbox:netbox /opt/netbox/netbox/media/` -# Install Python Packages +## Install Python Packages Install the required Python packages using pip. (If you encounter any compilation errors during this step, ensure that you've installed all of the system dependencies listed above.) @@ -82,7 +84,7 @@ Install the required Python packages using pip. (If you encounter any compilatio !!! note If you encounter errors while installing the required packages, check that you're running a recent version of pip (v9.0.1 or higher) with the command `pip3 -V`. -## NAPALM Automation (Optional) +### NAPALM Automation (Optional) NetBox supports integration with the [NAPALM automation](https://napalm-automation.net/) library. NAPALM allows NetBox to fetch live data from devices and return it to a requester via its REST API. Installation of NAPALM is optional. To enable it, install the `napalm` package using pip or pip3: @@ -90,7 +92,7 @@ NetBox supports integration with the [NAPALM automation](https://napalm-automati # pip3 install napalm ``` -## Remote File Storage (Optional) +### Remote File Storage (Optional) By default, NetBox will use the local filesystem to storage uploaded files. To use a remote filesystem, install the [`django-storages`](https://django-storages.readthedocs.io/en/stable/) library and configure your [desired backend](../../configuration/optional-settings/#storage_backend) in `configuration.py`. @@ -98,7 +100,7 @@ By default, NetBox will use the local filesystem to storage uploaded files. To u # pip3 install django-storages ``` -# Configuration +## Configuration Move into the NetBox configuration directory and make a copy of `configuration.example.py` named `configuration.py`. @@ -114,7 +116,7 @@ Open `configuration.py` with your preferred editor and set the following variabl * `REDIS` * `SECRET_KEY` -## ALLOWED_HOSTS +### ALLOWED_HOSTS This is a list of the valid hostnames by which this server can be reached. You must specify at least one name or IP address. @@ -124,7 +126,7 @@ Example: ALLOWED_HOSTS = ['netbox.example.com', '192.0.2.123'] ``` -## DATABASE +### DATABASE This parameter holds the database configuration details. You must define the username and password used when you configured PostgreSQL. If the service is running on a remote host, replace `localhost` with its address. See the [configuration documentation](../../configuration/required-settings/#database) for more detail on individual parameters. @@ -141,7 +143,7 @@ DATABASE = { } ``` -## REDIS +### REDIS Redis is a in-memory key-value store required as part of the NetBox installation. It is used for features such as webhooks and caching. Redis typically requires minimal configuration; the values below should suffice for most installations. See the [configuration documentation](../../configuration/required-settings/#redis) for more detail on individual parameters. @@ -166,7 +168,7 @@ REDIS = { } ``` -## SECRET_KEY +### SECRET_KEY Generate a random secret key of at least 50 alphanumeric characters. This key must be unique to this installation and must not be shared outside the local system. @@ -175,7 +177,7 @@ You may use the script located at `netbox/generate_secret_key.py` to generate a !!! note In the case of a highly available installation with multiple web servers, `SECRET_KEY` must be identical among all servers in order to maintain a persistent user session state. -# Run Database Migrations +## Run Database Migrations Before NetBox can run, we need to install the database schema. This is done by running `python3 manage.py migrate` from the `netbox` directory (`/opt/netbox/netbox/` in our example): @@ -194,7 +196,7 @@ Running migrations: If this step results in a PostgreSQL authentication error, ensure that the username and password created in the database match what has been specified in `configuration.py` -# Create a Super User +## Create a Super User NetBox does not come with any predefined user accounts. You'll need to create a super user to be able to log into NetBox: @@ -207,7 +209,7 @@ Password (again): Superuser created successfully. ``` -# Collect Static Files +## Collect Static Files ```no-highlight # python3 manage.py collectstatic --no-input @@ -215,7 +217,7 @@ Superuser created successfully. 959 static files copied to '/opt/netbox/netbox/static'. ``` -# Test the Application +## Test the Application At this point, NetBox should be able to run. We can verify this by starting a development instance: diff --git a/docs/installation/3-http-daemon.md b/docs/installation/4-http-daemon.md similarity index 98% rename from docs/installation/3-http-daemon.md rename to docs/installation/4-http-daemon.md index 4225f8413..c50d71e4c 100644 --- a/docs/installation/3-http-daemon.md +++ b/docs/installation/4-http-daemon.md @@ -3,9 +3,9 @@ We'll set up a simple WSGI front end using [gunicorn](http://gunicorn.org/) for !!! info For the sake of brevity, only Ubuntu 18.04 instructions are provided here, but this sort of web server and WSGI configuration is not unique to NetBox. Please consult your distribution's documentation for assistance if needed. -# Web Server Installation +## HTTP Daemon Installation -## Option A: nginx +### Option A: nginx The following will serve as a minimal nginx configuration. Be sure to modify your server name and installation path appropriately. @@ -52,7 +52,7 @@ Restart the nginx service to use the new configuration. To enable SSL, consider this guide on [securing nginx with Let's Encrypt](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04). -## Option B: Apache +### Option B: Apache ```no-highlight # apt-get install -y apache2 libapache2-mod-wsgi-py3 @@ -102,7 +102,7 @@ To enable SSL, consider this guide on [securing Apache with Let's Encrypt](https !!! note Certain components of NetBox (such as the display of rack elevation diagrams) rely on the use of embedded objects. Ensure that your HTTP server configuration does not override the `X-Frame-Options` response header set by NetBox. -# gunicorn Installation +## gunicorn Installation Install gunicorn: @@ -119,7 +119,7 @@ Copy `/opt/netbox/contrib/gunicorn.py` to `/opt/netbox/gunicorn.py`. We make a c You may wish to edit this file to change the bound IP address or port number, or to make performance-related adjustments. -# systemd configuration +## systemd configuration 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: diff --git a/docs/installation/4-ldap.md b/docs/installation/5-ldap.md similarity index 96% rename from docs/installation/4-ldap.md rename to docs/installation/5-ldap.md index 953d3cb28..0a5a4f76a 100644 --- a/docs/installation/4-ldap.md +++ b/docs/installation/5-ldap.md @@ -1,8 +1,8 @@ This guide explains how to implement LDAP authentication using an external server. User authentication will fall back to built-in Django users in the event of a failure. -# Requirements +## Install Requirements -## Install openldap-devel +#### Install openldap-devel On Ubuntu: @@ -16,17 +16,17 @@ On CentOS: sudo yum install -y openldap-devel ``` -## Install django-auth-ldap +#### Install django-auth-ldap ```no-highlight pip3 install django-auth-ldap ``` -# Configuration +## Configuration Create a file in the same directory as `configuration.py` (typically `netbox/netbox/`) named `ldap_config.py`. Define all of the parameters required below in `ldap_config.py`. Complete documentation of all `django-auth-ldap` configuration options is included in the project's [official documentation](http://django-auth-ldap.readthedocs.io/). -## General Server Configuration +### General Server Configuration !!! info When using Windows Server 2012 you may need to specify a port on `AUTH_LDAP_SERVER_URI`. Use `3269` for secure, or `3268` for non-secure. @@ -54,7 +54,7 @@ LDAP_IGNORE_CERT_ERRORS = True STARTTLS can be configured by setting `AUTH_LDAP_START_TLS = True` and using the `ldap://` URI scheme. -## User Authentication +### User Authentication !!! info When using Windows Server 2012, `AUTH_LDAP_USER_DN_TEMPLATE` should be set to None. @@ -79,7 +79,7 @@ AUTH_LDAP_USER_ATTR_MAP = { } ``` -# User Groups for Permissions +## User Groups for Permissions !!! info When using Microsoft Active Directory, support for nested groups can be activated by using `NestedGroupOfNamesType()` instead of `GroupOfNamesType()` for `AUTH_LDAP_GROUP_TYPE`. You will also need to modify the import line to use `NestedGroupOfNamesType` instead of `GroupOfNamesType` . @@ -121,7 +121,7 @@ AUTH_LDAP_CACHE_TIMEOUT = 3600 !!! warning Authentication will fail if the groups (the distinguished names) do not exist in the LDAP directory. -# Troubleshooting LDAP +## Troubleshooting LDAP `supervisorctl restart netbox` restarts the Netbox service, and initiates any changes made to `ldap_config.py`. If there are syntax errors present, the NetBox process will not spawn an instance, and errors should be logged to `/var/log/supervisor/`. diff --git a/docs/installation/index.md b/docs/installation/index.md index 59631bf7a..8df387ca8 100644 --- a/docs/installation/index.md +++ b/docs/installation/index.md @@ -3,9 +3,10 @@ The following sections detail how to set up a new instance of NetBox: 1. [PostgreSQL database](1-postgresql.md) -2. [NetBox components](2-netbox.md) -3. [HTTP daemon](3-http-daemon.md) -4. [LDAP authentication](4-ldap.md) (optional) +1. [Redis](2-redis.md) +3. [NetBox components](3-netbox.md) +4. [HTTP daemon](4-http-daemon.md) +5. [LDAP authentication](5-ldap.md) (optional) # Upgrading diff --git a/mkdocs.yml b/mkdocs.yml index 4ba91dfe5..6de4b532f 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,15 +1,21 @@ -site_name: NetBox -theme: readthedocs +site_name: NetBox Documentation +site_url: https://netbox.readthedocs.io/ repo_url: https://github.com/netbox-community/netbox +theme: + name: readthedocs + navigation_depth: 3 +markdown_extensions: + - admonition: -pages: +nav: - Introduction: 'index.md' - Installation: - Installing NetBox: 'installation/index.md' - 1. PostgreSQL: 'installation/1-postgresql.md' - - 2. NetBox: 'installation/2-netbox.md' - - 3. HTTP Daemon: 'installation/3-http-daemon.md' - - 4. LDAP (Optional): 'installation/4-ldap.md' + - 2. Redis: 'installation/2-redis.md' + - 3. NetBox: 'installation/3-netbox.md' + - 4. HTTP Daemon: 'installation/4-http-daemon.md' + - 5. LDAP (Optional): 'installation/5-ldap.md' - Upgrading NetBox: 'installation/upgrading.md' - Migrating to Python3: 'installation/migrating-to-python3.md' - Migrating to systemd: 'installation/migrating-to-systemd.md' @@ -76,6 +82,3 @@ pages: - Version 1.2: 'release-notes/version-1.2.md' - Version 1.1: 'release-notes/version-1.1.md' - Version 1.0: 'release-notes/version-1.0.md' - -markdown_extensions: - - admonition: From 1b64f67f2b830e8913a0c05603126d0fd5f78710 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Feb 2020 12:28:35 -0500 Subject: [PATCH 02/12] Update installation instructions to use a Python virtual environment --- base_requirements.txt | 4 +++ contrib/netbox-rq.service | 2 +- contrib/netbox.service | 2 +- docs/installation/3-netbox.md | 44 ++++++++++++++++-------------- docs/installation/4-http-daemon.md | 4 +-- requirements.txt | 1 + 6 files changed, 33 insertions(+), 24 deletions(-) diff --git a/base_requirements.txt b/base_requirements.txt index ed42b6c08..e1c29a2a2 100644 --- a/base_requirements.txt +++ b/base_requirements.txt @@ -98,3 +98,7 @@ redis # SVG image rendering (used for rack elevations) # https://github.com/mozman/svgwrite svgwrite + +# Python package management tool +# https://pythonwheels.com/ +wheel diff --git a/contrib/netbox-rq.service b/contrib/netbox-rq.service index 7a300a195..58662dccf 100644 --- a/contrib/netbox-rq.service +++ b/contrib/netbox-rq.service @@ -12,7 +12,7 @@ Group=www-data WorkingDirectory=/opt/netbox -ExecStart=/usr/bin/python3 /opt/netbox/netbox/manage.py rqworker +ExecStart=/opt/netbox/venv/bin/python3 /opt/netbox/netbox/manage.py rqworker Restart=on-failure RestartSec=30 diff --git a/contrib/netbox.service b/contrib/netbox.service index 3cc9069c6..076879254 100644 --- a/contrib/netbox.service +++ b/contrib/netbox.service @@ -12,7 +12,7 @@ Group=www-data PIDFile=/var/tmp/netbox.pid WorkingDirectory=/opt/netbox -ExecStart=/usr/local/bin/gunicorn --pid /var/tmp/netbox.pid --pythonpath /opt/netbox/netbox --config /opt/netbox/gunicorn.py netbox.wsgi +ExecStart=/opt/netbox/venv/bin/gunicorn --pid /var/tmp/netbox.pid --pythonpath /opt/netbox/netbox --config /opt/netbox/gunicorn.py netbox.wsgi Restart=on-failure RestartSec=30 diff --git a/docs/installation/3-netbox.md b/docs/installation/3-netbox.md index 5c29b3996..b58391769 100644 --- a/docs/installation/3-netbox.md +++ b/docs/installation/3-netbox.md @@ -5,7 +5,7 @@ This section of the documentation discusses installing and configuring the NetBo #### Ubuntu ```no-highlight -# apt-get install -y python3 python3-pip python3-dev build-essential libxml2-dev libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev +# apt-get install -y python3 python3-pip python3-venv python3-dev build-essential libxml2-dev libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev ``` #### CentOS @@ -73,31 +73,35 @@ Checking connectivity... done. `# chown -R netbox:netbox /opt/netbox/netbox/media/` -## Install Python Packages +## Set Up Python Environment -Install the required Python packages using pip. (If you encounter any compilation errors during this step, ensure that you've installed all of the system dependencies listed above.) +We'll use a Python [virtual environment](https://docs.python.org/3.6/tutorial/venv.html) to ensure NetBox's required packages don't conflict with anything in the base system. This will create a directory named `venv` in our NetBox root. ```no-highlight -# pip3 install -r requirements.txt +# python3 -m venv /opt/netbox/venv ``` -!!! note - If you encounter errors while installing the required packages, check that you're running a recent version of pip (v9.0.1 or higher) with the command `pip3 -V`. - -### NAPALM Automation (Optional) - -NetBox supports integration with the [NAPALM automation](https://napalm-automation.net/) library. NAPALM allows NetBox to fetch live data from devices and return it to a requester via its REST API. Installation of NAPALM is optional. To enable it, install the `napalm` package using pip or pip3: +Next, activate the virtual environment and install the required Python packages. You should see your console prompt change to indicate the active environment. (Activating the virtual environment updates your command shell to use the local copy of Python that we just installed for NetBox instead of the system's Python interpreter.) ```no-highlight -# pip3 install napalm +# source venv/bin/activate +(venv) # pip3 install -r requirements.txt ``` -### Remote File Storage (Optional) +#### NAPALM Automation (Optional) + +NetBox supports integration with the [NAPALM automation](https://napalm-automation.net/) library. NAPALM allows NetBox to fetch live data from devices and return it to a requester via its REST API. Installation of NAPALM is optional. To enable it, install the `napalm` package: + +```no-highlight +(venv) # pip3 install napalm +``` + +#### Remote File Storage (Optional) By default, NetBox will use the local filesystem to storage uploaded files. To use a remote filesystem, install the [`django-storages`](https://django-storages.readthedocs.io/en/stable/) library and configure your [desired backend](../../configuration/optional-settings/#storage_backend) in `configuration.py`. ```no-highlight -# pip3 install django-storages +(venv) # pip3 install django-storages ``` ## Configuration @@ -105,8 +109,8 @@ By default, NetBox will use the local filesystem to storage uploaded files. To u Move into the NetBox configuration directory and make a copy of `configuration.example.py` named `configuration.py`. ```no-highlight -# cd netbox/netbox/ -# cp configuration.example.py configuration.py +(venv) # cd netbox/netbox/ +(venv) # cp configuration.example.py configuration.py ``` Open `configuration.py` with your preferred editor and set the following variables: @@ -182,8 +186,8 @@ You may use the script located at `netbox/generate_secret_key.py` to generate a Before NetBox can run, we need to install the database schema. This is done by running `python3 manage.py migrate` from the `netbox` directory (`/opt/netbox/netbox/` in our example): ```no-highlight -# cd /opt/netbox/netbox/ -# python3 manage.py migrate +(venv) # cd /opt/netbox/netbox/ +(venv) # python3 manage.py migrate Operations to perform: Apply all migrations: dcim, sessions, admin, ipam, utilities, auth, circuits, contenttypes, extras, secrets, users Running migrations: @@ -201,7 +205,7 @@ If this step results in a PostgreSQL authentication error, ensure that the usern NetBox does not come with any predefined user accounts. You'll need to create a super user to be able to log into NetBox: ```no-highlight -# python3 manage.py createsuperuser +(venv) # python3 manage.py createsuperuser Username: admin Email address: admin@example.com Password: @@ -212,7 +216,7 @@ Superuser created successfully. ## Collect Static Files ```no-highlight -# python3 manage.py collectstatic --no-input +(venv) # python3 manage.py collectstatic --no-input 959 static files copied to '/opt/netbox/netbox/static'. ``` @@ -222,7 +226,7 @@ Superuser created successfully. At this point, NetBox should be able to run. We can verify this by starting a development instance: ```no-highlight -# python3 manage.py runserver 0.0.0.0:8000 --insecure +(venv) # python3 manage.py runserver 0.0.0.0:8000 --insecure Performing system checks... System check identified no issues (0 silenced). diff --git a/docs/installation/4-http-daemon.md b/docs/installation/4-http-daemon.md index c50d71e4c..43206b26e 100644 --- a/docs/installation/4-http-daemon.md +++ b/docs/installation/4-http-daemon.md @@ -104,10 +104,10 @@ To enable SSL, consider this guide on [securing Apache with Let's Encrypt](https ## gunicorn Installation -Install gunicorn: +Check that the Python virtual environment created in [the previous step](3-netbox.md#set-up-python-environment) is still active, and install the `gunicorn` Python package. (If the virtual environment is not active, activate it with the command `source /opt/netbox/venv/bin/activate`.) ```no-highlight -# pip3 install gunicorn +(venv) # pip3 install gunicorn ``` Copy `/opt/netbox/contrib/gunicorn.py` to `/opt/netbox/gunicorn.py`. We make a copy of this file to ensure that any changes to it do not get overwritten by a future upgrade. diff --git a/requirements.txt b/requirements.txt index b0b1b971d..3b04494ed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,3 +23,4 @@ pycryptodome==3.9.4 PyYAML==5.3 redis==3.3.11 svgwrite==1.3.1 +wheel==0.34.2 From 0851b97ba5445583a9c8452009b5b45a2e9f110e Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Feb 2020 13:54:07 -0500 Subject: [PATCH 03/12] Update the upgrade script & instructions to use a virtual environment --- base_requirements.txt | 4 +++ docs/installation/4-http-daemon.md | 15 ++------ docs/installation/upgrading.md | 26 ++++++++++---- requirements.txt | 1 + upgrade.sh | 58 +++++++++++++++--------------- 5 files changed, 55 insertions(+), 49 deletions(-) diff --git a/base_requirements.txt b/base_requirements.txt index e1c29a2a2..ab33b1c06 100644 --- a/base_requirements.txt +++ b/base_requirements.txt @@ -58,6 +58,10 @@ djangorestframework # https://github.com/axnsan12/drf-yasg drf-yasg[validation] +# WSGI HTTP server +# https://gunicorn.org/ +gunicorn + # Platform-agnostic template rendering engine # https://github.com/pallets/jinja Jinja2 diff --git a/docs/installation/4-http-daemon.md b/docs/installation/4-http-daemon.md index 43206b26e..065c63b12 100644 --- a/docs/installation/4-http-daemon.md +++ b/docs/installation/4-http-daemon.md @@ -102,15 +102,9 @@ To enable SSL, consider this guide on [securing Apache with Let's Encrypt](https !!! note Certain components of NetBox (such as the display of rack elevation diagrams) rely on the use of embedded objects. Ensure that your HTTP server configuration does not override the `X-Frame-Options` response header set by NetBox. -## gunicorn Installation +## gunicorn Configuration -Check that the Python virtual environment created in [the previous step](3-netbox.md#set-up-python-environment) is still active, and install the `gunicorn` Python package. (If the virtual environment is not active, activate it with the command `source /opt/netbox/venv/bin/activate`.) - -```no-highlight -(venv) # pip3 install gunicorn -``` - -Copy `/opt/netbox/contrib/gunicorn.py` to `/opt/netbox/gunicorn.py`. We make a copy of this file to ensure that any changes to it do not get overwritten by a future upgrade. +Copy `/opt/netbox/contrib/gunicorn.py` to `/opt/netbox/gunicorn.py`. (We make a copy of this file to ensure that any changes to it do not get overwritten by a future upgrade.) ```no-highlight # cd /opt/netbox @@ -119,7 +113,7 @@ Copy `/opt/netbox/contrib/gunicorn.py` to `/opt/netbox/gunicorn.py`. We make a c You may wish to edit this file to change the bound IP address or port number, or to make performance-related adjustments. -## systemd configuration +## systemd Configuration 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: @@ -127,9 +121,6 @@ We'll use systemd to control the daemonization of NetBox services. First, copy ` # cp contrib/*.service /etc/systemd/system/ ``` -!!! note - 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. - Then, start the `netbox` and `netbox-rq` services and enable them to initiate at boot time: ```no-highlight diff --git a/docs/installation/upgrading.md b/docs/installation/upgrading.md index e5cf93a28..101ec9c36 100644 --- a/docs/installation/upgrading.md +++ b/docs/installation/upgrading.md @@ -1,12 +1,12 @@ -# Review the Release Notes +## Review the Release Notes Prior to upgrading your NetBox instance, be sure to carefully review all [release notes](../../release-notes/) that have been published since your current version was released. Although the upgrade process typically does not involve additional work, certain releases may introduce breaking or backward-incompatible changes. These are called out in the release notes under the version in which the change went into effect. -# Install the Latest Code +## Install the Latest Code As with the initial installation, you can upgrade NetBox by either downloading the latest release package or by cloning the `master` branch of the git repository. -## Option A: Download a Release +### Option A: Download a Release Download the [latest stable release](https://github.com/netbox-community/netbox/releases) from GitHub as a tarball or ZIP archive. Extract it to your desired path. In this example, we'll use `/opt/netbox`. @@ -34,7 +34,7 @@ Be sure to replicate your uploaded media as well. (The exact action necessary wi Also make sure to copy over any reports that you've made. Note that if you made them in a separate directory (`/opt/netbox-reports` for example), then you will not need to copy them - the config file that you copied earlier will point to the correct location. ```no-highlight -# cp -r /opt/netbox-X.Y.X/netbox/reports /opt/netbox/netbox/reports/ +# cp -r /opt/netbox-X.Y.Z/netbox/reports /opt/netbox/netbox/reports/ ``` If you followed the original installation guide to set up gunicorn, be sure to copy its configuration as well: @@ -49,7 +49,7 @@ Copy the LDAP configuration if using LDAP: # cp netbox-X.Y.Z/netbox/netbox/ldap_config.py netbox/netbox/netbox/ldap_config.py ``` -## Option B: Clone the Git Repository (latest master release) +### Option B: Clone the Git Repository (latest master release) This guide assumes that NetBox is installed at `/opt/netbox`. Pull down the most recent iteration of the master branch: @@ -60,7 +60,19 @@ This guide assumes that NetBox is installed at `/opt/netbox`. Pull down the most # git status ``` -# Run the Upgrade Script +## Rebuild the Virtual Environment + +Destroy and recreate the Python virtual environment. This ensures that an up-to-date version of each dependency is installed while and that any obsolete packages are no longer present. + +```no-highlight +# cd /opt/netbox +# rm -rf venv +# python3 -m venv venv +# source venv/bin/activate +(venv) # pip3 install -r requirements.txt +``` + +## Run the Upgrade Script Once the new code is in place, run the upgrade script (which may need to be run as root depending on how your environment is configured). @@ -82,7 +94,7 @@ This script: This may occur due to semantic differences in environment, and can be safely ignored. Never attempt to create new migrations unless you are intentionally modifying the database schema. -# Restart the WSGI Service +## Restart the WSGI Service Finally, restart the WSGI services to run the new code. If you followed this guide for the initial installation, this is done using `systemctl: diff --git a/requirements.txt b/requirements.txt index 3b04494ed..d8e704874 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,6 +13,7 @@ django-taggit-serializer==0.1.7 django-timezone-field==4.0 djangorestframework==3.10.3 drf-yasg[validation]==1.17.0 +gunicorn==20.0.4 Jinja2==2.10.3 Markdown==2.6.11 netaddr==0.7.19 diff --git a/upgrade.sh b/upgrade.sh index 2ff585e8d..72e465661 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -1,52 +1,50 @@ #!/bin/bash # This script will prepare NetBox to run after the code has been upgraded to # its most recent release. -# -# Once the script completes, remember to restart the WSGI service (e.g. -# gunicorn or uWSGI). cd "$(dirname "$0")" +VIRTUALENV="$(pwd -P)/venv" -PYTHON="python3" -PIP="pip3" +# Remove the existing virtual environment (if any) +if [ -d "$VIRTUALENV" ]; then + COMMAND="rm -rf ${VIRTUALENV}" + echo "Removing old virtual environment..." + eval $COMMAND +fi -# Uninstall any Python packages which are no longer needed -COMMAND="${PIP} uninstall -r old_requirements.txt -y" -echo "Removing old Python packages ($COMMAND)..." +# Create a new virtual environment +COMMAND="/usr/bin/python3 -m venv ${VIRTUALENV}" +echo "Creating a new virtual environment at ${VIRTUALENV}..." eval $COMMAND -# Install any new Python packages -COMMAND="${PIP} install -r requirements.txt --upgrade" -echo "Updating required Python packages ($COMMAND)..." -eval $COMMAND +# Activate the virtual environment +source "${VIRTUALENV}/bin/activate" -# Validate Python dependencies -COMMAND="${PIP} check" -echo "Validating Python dependencies ($COMMAND)..." -eval $COMMAND || ( - echo "******** PLEASE FIX THE DEPENDENCIES BEFORE CONTINUING ********" - echo "* Manually install newer version(s) of the highlighted packages" - echo "* so that 'pip3 check' passes. For more information see:" - echo "* https://github.com/pypa/pip/issues/988" - exit 1 -) +# Install Python packages +COMMAND="pip3 install -r requirements.txt" +echo "Installing Python packages ($COMMAND)..." +eval $COMMAND # Apply any database migrations -COMMAND="${PYTHON} netbox/manage.py migrate" +COMMAND="python3 netbox/manage.py migrate" echo "Applying database migrations ($COMMAND)..." eval $COMMAND -# Delete any stale content types -COMMAND="${PYTHON} netbox/manage.py remove_stale_contenttypes --no-input" -echo "Removing stale content types ($COMMAND)..." -eval $COMMAND - # Collect static files -COMMAND="${PYTHON} netbox/manage.py collectstatic --no-input" +COMMAND="python3 netbox/manage.py collectstatic --no-input" echo "Collecting static files ($COMMAND)..." eval $COMMAND +# Delete any stale content types +COMMAND="python3 netbox/manage.py remove_stale_contenttypes --no-input" +echo "Removing stale content types ($COMMAND)..." +eval $COMMAND + # Clear all cached data -COMMAND="${PYTHON} netbox/manage.py invalidate all" +COMMAND="python3 netbox/manage.py invalidate all" echo "Clearing cache data ($COMMAND)..." eval $COMMAND + +echo "Upgrade complete! Don't forget to restart the NetBox services:" +echo " sudo systemctl restart netbox" +echo " sudo systemctl restart netbox-rq" From 2ee06c13f9bd38c0b4fa77282ee287a52112d215 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Feb 2020 13:56:44 -0500 Subject: [PATCH 04/12] Remove Python 2 migration guide --- docs/installation/index.md | 2 -- docs/installation/migrating-to-python3.md | 38 ----------------------- mkdocs.yml | 1 - 3 files changed, 41 deletions(-) delete mode 100644 docs/installation/migrating-to-python3.md diff --git a/docs/installation/index.md b/docs/installation/index.md index 8df387ca8..082c94ec3 100644 --- a/docs/installation/index.md +++ b/docs/installation/index.md @@ -12,6 +12,4 @@ 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.9 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. diff --git a/docs/installation/migrating-to-python3.md b/docs/installation/migrating-to-python3.md deleted file mode 100644 index 2c2c2b917..000000000 --- a/docs/installation/migrating-to-python3.md +++ /dev/null @@ -1,38 +0,0 @@ -# Migration - -!!! warning - As of version 2.5, NetBox no longer supports Python 2. Python 3 is required to run any 2.5 release or later. - -## Ubuntu - -Remove the Python2 version of gunicorn: - -```no-highlight -# pip uninstall -y gunicorn -``` - -Install Python3 and pip3, Python's package management tool: - -```no-highlight -# apt-get update -# apt-get install -y python3 python3-dev python3-setuptools -# easy_install3 pip -``` - -Install the Python3 packages required by NetBox: - -```no-highlight -# pip3 install -r requirements.txt -``` - -Replace gunicorn with the Python3 version: - -```no-highlight -# pip3 install gunicorn -``` - -If using LDAP authentication, install the `django-auth-ldap` package: - -```no-highlight -# pip3 install django-auth-ldap -``` diff --git a/mkdocs.yml b/mkdocs.yml index 6de4b532f..cf45b89ae 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -17,7 +17,6 @@ nav: - 4. HTTP Daemon: 'installation/4-http-daemon.md' - 5. LDAP (Optional): 'installation/5-ldap.md' - Upgrading NetBox: 'installation/upgrading.md' - - Migrating to Python3: 'installation/migrating-to-python3.md' - Migrating to systemd: 'installation/migrating-to-systemd.md' - Configuration: - Configuring NetBox: 'configuration/index.md' From 015a339202193633f10cfd9e958407d56c87f639 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Feb 2020 14:09:27 -0500 Subject: [PATCH 05/12] Update systemd migration guide --- docs/installation/migrating-to-systemd.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/installation/migrating-to-systemd.md b/docs/installation/migrating-to-systemd.md index f5fcb7598..ff9e6cf0c 100644 --- a/docs/installation/migrating-to-systemd.md +++ b/docs/installation/migrating-to-systemd.md @@ -1,16 +1,17 @@ -# Migration - -Migration is not required, as supervisord will still continue to function. +This document contains instructions for migrating from a legacy NetBox deployment using [supervisor](http://supervisord.org/) to a systemd-based approach. ## Ubuntu -### Remove supervisord: +### Uninstall supervisord: ```no-highlight # apt-get remove -y supervisord ``` -### systemd configuration: +### Configure systemd: + +!!! note + These instructions assume the presence of a Python virtual environment at `/opt/netbox/venv`. If you have not created this environment, please refer to the [installation instructions](3-netbox.md#set-up-python-environment) for direction. 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: @@ -19,10 +20,7 @@ We'll use systemd to control the daemonization of NetBox services. First, copy ` ``` !!! note - 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. - -!!! note - 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. + 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 something else. Then, start the `netbox` and `netbox-rq` services and enable them to initiate at boot time: @@ -51,7 +49,7 @@ You can use the command `systemctl status netbox` to verify that the WSGI servic ... ``` -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. +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. Issue the command `journalctl -xe` to see why the services were unable to start. !!! info 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. From 798ecfc8f0467d2cee47e617825bb4aa16c63a96 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Feb 2020 14:09:54 -0500 Subject: [PATCH 06/12] Clean up the upgrade guide --- docs/installation/upgrading.md | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/docs/installation/upgrading.md b/docs/installation/upgrading.md index 101ec9c36..c7d9977cc 100644 --- a/docs/installation/upgrading.md +++ b/docs/installation/upgrading.md @@ -60,21 +60,9 @@ This guide assumes that NetBox is installed at `/opt/netbox`. Pull down the most # git status ``` -## Rebuild the Virtual Environment - -Destroy and recreate the Python virtual environment. This ensures that an up-to-date version of each dependency is installed while and that any obsolete packages are no longer present. - -```no-highlight -# cd /opt/netbox -# rm -rf venv -# python3 -m venv venv -# source venv/bin/activate -(venv) # pip3 install -r requirements.txt -``` - ## Run the Upgrade Script -Once the new code is in place, run the upgrade script (which may need to be run as root depending on how your environment is configured). +Once the new code is in place, run the upgrade script: ```no-highlight # ./upgrade.sh @@ -82,7 +70,8 @@ Once the new code is in place, run the upgrade script (which may need to be run This script: -* Installs or upgrades any new required Python packages +* Destroys and rebuilds the Python virtual environment +* Installs all required Python packages * Applies any database migrations that were included in the release * Collects all static files to be served by the HTTP service @@ -94,9 +83,9 @@ This script: This may occur due to semantic differences in environment, and can be safely ignored. Never attempt to create new migrations unless you are intentionally modifying the database schema. -## Restart the WSGI Service +## Restart the NetBox Services -Finally, restart the WSGI services to run the new code. If you followed this guide for the initial installation, this is done using `systemctl: +Finally, restart the gunicorn and RQ services: ```no-highlight # sudo systemctl restart netbox @@ -104,4 +93,4 @@ Finally, restart the WSGI services to run the new code. If you followed this gui ``` !!! note - It's possible you are still using supervisord instead of the linux native systemd. If you are still using supervisord you can restart the services by either restarting supervisord or by using supervisorctl to restart netbox. + It's possible you are still using supervisord instead of systemd. If so, please see the instructions for [migrating to systemd](migrating-to-systemd.md). From be9df3c07d3d7c4d36c125bc070080bcf1666e1d Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Feb 2020 14:38:25 -0500 Subject: [PATCH 07/12] Simplify the systemctl commands --- docs/installation/4-http-daemon.md | 6 ++---- docs/installation/migrating-to-systemd.md | 6 ++---- docs/installation/upgrading.md | 3 +-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/docs/installation/4-http-daemon.md b/docs/installation/4-http-daemon.md index 065c63b12..7e19a6b69 100644 --- a/docs/installation/4-http-daemon.md +++ b/docs/installation/4-http-daemon.md @@ -125,10 +125,8 @@ Then, start the `netbox` and `netbox-rq` services and enable them to initiate at ```no-highlight # systemctl daemon-reload -# systemctl start netbox.service -# systemctl start netbox-rq.service -# systemctl enable netbox.service -# systemctl enable netbox-rq.service +# systemctl start netbox netbox-rq +# systemctl enable netbox netbox-rq ``` You can use the command `systemctl status netbox` to verify that the WSGI service is running: diff --git a/docs/installation/migrating-to-systemd.md b/docs/installation/migrating-to-systemd.md index ff9e6cf0c..34ce70bb6 100644 --- a/docs/installation/migrating-to-systemd.md +++ b/docs/installation/migrating-to-systemd.md @@ -26,10 +26,8 @@ Then, start the `netbox` and `netbox-rq` services and enable them to initiate at ```no-highlight # systemctl daemon-reload -# systemctl start netbox.service -# systemctl start netbox-rq.service -# systemctl enable netbox.service -# systemctl enable netbox-rq.service +# systemctl start netbox netbox-rq +# systemctl enable netbox netbox-rq ``` You can use the command `systemctl status netbox` to verify that the WSGI service is running: diff --git a/docs/installation/upgrading.md b/docs/installation/upgrading.md index c7d9977cc..b4f19a87d 100644 --- a/docs/installation/upgrading.md +++ b/docs/installation/upgrading.md @@ -88,8 +88,7 @@ This script: Finally, restart the gunicorn and RQ services: ```no-highlight -# sudo systemctl restart netbox -# sudo systemctl restart netbox-rq +# sudo systemctl restart netbox netbox-rq ``` !!! note From 1abc82e7185826e08ae185a6344e89cd084f2a8c Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Feb 2020 15:26:12 -0500 Subject: [PATCH 08/12] Update upgrade script & instructions to better accomodate moving to a venv --- docs/installation/upgrading.md | 3 +++ upgrade.sh | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/installation/upgrading.md b/docs/installation/upgrading.md index b4f19a87d..bf6497f6d 100644 --- a/docs/installation/upgrading.md +++ b/docs/installation/upgrading.md @@ -85,6 +85,9 @@ This script: ## Restart the NetBox Services +!!! warning + If you are upgrading from an installation that does not use a Python virtual environment, you'll need to update the systemd service files to reference the new Python and gunicorn executables before restarting the services. These are located in `/opt/netbox/venv/bin/`. See the example service files in `/opt/netbox/contrib/` for reference. + Finally, restart the gunicorn and RQ services: ```no-highlight diff --git a/upgrade.sh b/upgrade.sh index 72e465661..f672d4c90 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -10,12 +10,18 @@ if [ -d "$VIRTUALENV" ]; then COMMAND="rm -rf ${VIRTUALENV}" echo "Removing old virtual environment..." eval $COMMAND +else + WARN_MISSING_VENV=1 fi # Create a new virtual environment COMMAND="/usr/bin/python3 -m venv ${VIRTUALENV}" echo "Creating a new virtual environment at ${VIRTUALENV}..." -eval $COMMAND +eval $COMMAND || ( + echo "Failed to create the virtual environment. Check that you have the" + echo "required system packages installed." + exit 1 +) # Activate the virtual environment source "${VIRTUALENV}/bin/activate" @@ -45,6 +51,13 @@ COMMAND="python3 netbox/manage.py invalidate all" echo "Clearing cache data ($COMMAND)..." eval $COMMAND +if [ WARN_MISSING_VENV ]; then + echo "No existing virtual environment was detected. A new one has been" + echo "created. Update your systemd service files to reflect the new" + echo "executables." + echo " Python: ${VIRTUALENV}/bin/python" + echo " gunicorn: ${VIRTUALENV}/bin/gunicorn" +fi + echo "Upgrade complete! Don't forget to restart the NetBox services:" -echo " sudo systemctl restart netbox" -echo " sudo systemctl restart netbox-rq" +echo " sudo systemctl restart netbox netbox-rq" From 64c9bf27c10e88a27b7f58c0ca8405bbf8606163 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Feb 2020 15:34:42 -0500 Subject: [PATCH 09/12] Fix exit statement in upgrade script --- upgrade.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/upgrade.sh b/upgrade.sh index f672d4c90..aab7a6919 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -17,11 +17,11 @@ fi # Create a new virtual environment COMMAND="/usr/bin/python3 -m venv ${VIRTUALENV}" echo "Creating a new virtual environment at ${VIRTUALENV}..." -eval $COMMAND || ( +eval $COMMAND || { echo "Failed to create the virtual environment. Check that you have the" echo "required system packages installed." exit 1 -) +} # Activate the virtual environment source "${VIRTUALENV}/bin/activate" From 215dbef7a04c90f8f84720361bba1e0c7a736306 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Feb 2020 15:40:05 -0500 Subject: [PATCH 10/12] Improved formatting of upgrade script messages --- upgrade.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/upgrade.sh b/upgrade.sh index aab7a6919..977d9684d 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -18,8 +18,10 @@ fi COMMAND="/usr/bin/python3 -m venv ${VIRTUALENV}" echo "Creating a new virtual environment at ${VIRTUALENV}..." eval $COMMAND || { - echo "Failed to create the virtual environment. Check that you have the" - echo "required system packages installed." + echo "--------------------------------------------------------------------" + echo "ERROR: Failed to create the virtual environment. Check that you have" + echo "the required system packages installed." + echo "--------------------------------------------------------------------" exit 1 } @@ -52,11 +54,13 @@ echo "Clearing cache data ($COMMAND)..." eval $COMMAND if [ WARN_MISSING_VENV ]; then - echo "No existing virtual environment was detected. A new one has been" - echo "created. Update your systemd service files to reflect the new" + echo "--------------------------------------------------------------------" + echo "WARNING: No existing virtual environment was detected. A new one has" + echo "been created. Update your systemd service files to reflect the new" echo "executables." echo " Python: ${VIRTUALENV}/bin/python" echo " gunicorn: ${VIRTUALENV}/bin/gunicorn" + echo "--------------------------------------------------------------------" fi echo "Upgrade complete! Don't forget to restart the NetBox services:" From 56c26f80b306e143ba9f6d930e7663838934be86 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Feb 2020 15:56:26 -0500 Subject: [PATCH 11/12] Changelog for #3949 --- docs/release-notes/version-2.7.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/release-notes/version-2.7.md b/docs/release-notes/version-2.7.md index 62b85bc83..fe8a02190 100644 --- a/docs/release-notes/version-2.7.md +++ b/docs/release-notes/version-2.7.md @@ -1,5 +1,11 @@ # v2.7.9 (FUTURE) +**Note:** This release will deploy a Python virtual environment on upgrade in the `venv/` directory. This will require modifying the paths to your Python and gunicorn executables in the systemd service files. For more detail, please see the [upgrade instructions](https://netbox.readthedocs.io/en/stable/installation/upgrading/). + +## Enhancements + +* [#3949](https://github.com/netbox-community/netbox/issues/3949) - Revised the installation docs and upgrade script to employ a Python virtual environment + ## Bug Fixes * [#4277](https://github.com/netbox-community/netbox/issues/4277) - Fix filtering of clusters by tenant From 87c914bece5fa5425244c0c051370ff5f68dfa18 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Feb 2020 15:59:26 -0500 Subject: [PATCH 12/12] Reorganize .gitignore; add /venv/ --- .gitignore | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 66a8b13e8..485b46d59 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.pyc +*.swp /netbox/netbox/configuration.py /netbox/netbox/ldap_config.py /netbox/reports/* @@ -6,15 +7,14 @@ /netbox/scripts/* !/netbox/scripts/__init__.py /netbox/static -.idea +/venv/ /*.sh !upgrade.sh fabfile.py -*.swp -gunicorn_config.py gunicorn.py netbox.log netbox.pid .DS_Store -.vscode +.idea .coverage +.vscode