Просмотр исходного кода

Update upgrade script & instructions to better accomodate moving to a venv

Jeremy Stretch 6 лет назад
Родитель
Сommit
1abc82e718
2 измененных файлов с 19 добавлено и 3 удалено
  1. 3 0
      docs/installation/upgrading.md
  2. 16 3
      upgrade.sh

+ 3 - 0
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

+ 16 - 3
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"