From 1abc82e7185826e08ae185a6344e89cd084f2a8c Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Feb 2020 15:26:12 -0500 Subject: [PATCH] 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"