2016-07-01 13:21:51 -04:00
|
|
|
#!/bin/bash
|
2016-06-29 15:43:42 -04:00
|
|
|
# This script will prepare NetBox to run after the code has been upgraded to
|
|
|
|
# its most recent release.
|
|
|
|
|
2019-05-02 13:02:53 -05:00
|
|
|
cd "$(dirname "$0")"
|
2020-02-26 13:54:07 -05:00
|
|
|
VIRTUALENV="$(pwd -P)/venv"
|
|
|
|
|
|
|
|
# Remove the existing virtual environment (if any)
|
|
|
|
if [ -d "$VIRTUALENV" ]; then
|
|
|
|
COMMAND="rm -rf ${VIRTUALENV}"
|
|
|
|
echo "Removing old virtual environment..."
|
|
|
|
eval $COMMAND
|
2020-02-26 15:26:12 -05:00
|
|
|
else
|
|
|
|
WARN_MISSING_VENV=1
|
2020-02-26 13:54:07 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Create a new virtual environment
|
|
|
|
COMMAND="/usr/bin/python3 -m venv ${VIRTUALENV}"
|
|
|
|
echo "Creating a new virtual environment at ${VIRTUALENV}..."
|
2020-02-26 15:34:42 -05:00
|
|
|
eval $COMMAND || {
|
2020-02-26 15:40:05 -05:00
|
|
|
echo "--------------------------------------------------------------------"
|
|
|
|
echo "ERROR: Failed to create the virtual environment. Check that you have"
|
2020-03-04 12:20:06 -05:00
|
|
|
echo "the required system packages installed and the following path is"
|
|
|
|
echo "writable: ${VIRTUALENV}"
|
2020-02-26 15:40:05 -05:00
|
|
|
echo "--------------------------------------------------------------------"
|
2020-02-26 15:26:12 -05:00
|
|
|
exit 1
|
2020-02-26 15:34:42 -05:00
|
|
|
}
|
2017-10-09 17:40:15 -04:00
|
|
|
|
2020-02-26 13:54:07 -05:00
|
|
|
# Activate the virtual environment
|
|
|
|
source "${VIRTUALENV}/bin/activate"
|
2016-06-29 15:43:42 -04:00
|
|
|
|
2020-02-26 13:54:07 -05:00
|
|
|
# Install Python packages
|
|
|
|
COMMAND="pip3 install -r requirements.txt"
|
|
|
|
echo "Installing Python packages ($COMMAND)..."
|
|
|
|
eval $COMMAND
|
2019-10-23 17:12:32 -04:00
|
|
|
|
2016-06-29 15:43:42 -04:00
|
|
|
# Apply any database migrations
|
2020-02-26 13:54:07 -05:00
|
|
|
COMMAND="python3 netbox/manage.py migrate"
|
2017-05-18 14:53:35 -04:00
|
|
|
echo "Applying database migrations ($COMMAND)..."
|
2017-04-27 14:42:52 -04:00
|
|
|
eval $COMMAND
|
2016-06-29 15:43:42 -04:00
|
|
|
|
|
|
|
# Collect static files
|
2020-02-26 13:54:07 -05:00
|
|
|
COMMAND="python3 netbox/manage.py collectstatic --no-input"
|
2017-04-27 14:42:52 -04:00
|
|
|
echo "Collecting static files ($COMMAND)..."
|
|
|
|
eval $COMMAND
|
2020-01-15 08:57:00 -05:00
|
|
|
|
2020-02-26 13:54:07 -05:00
|
|
|
# Delete any stale content types
|
|
|
|
COMMAND="python3 netbox/manage.py remove_stale_contenttypes --no-input"
|
|
|
|
echo "Removing stale content types ($COMMAND)..."
|
|
|
|
eval $COMMAND
|
|
|
|
|
2020-03-04 10:29:22 -05:00
|
|
|
# Delete any expired user sessions
|
|
|
|
COMMAND="python3 netbox/manage.py clearsessions"
|
|
|
|
echo "Removing expired user sessions ($COMMAND)..."
|
|
|
|
eval $COMMAND
|
|
|
|
|
2020-01-15 08:57:00 -05:00
|
|
|
# Clear all cached data
|
2020-02-26 13:54:07 -05:00
|
|
|
COMMAND="python3 netbox/manage.py invalidate all"
|
2020-01-15 08:57:00 -05:00
|
|
|
echo "Clearing cache data ($COMMAND)..."
|
|
|
|
eval $COMMAND
|
2020-02-26 13:54:07 -05:00
|
|
|
|
2020-02-26 15:26:12 -05:00
|
|
|
if [ WARN_MISSING_VENV ]; then
|
2020-02-26 15:40:05 -05:00
|
|
|
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"
|
2020-03-04 12:20:06 -05:00
|
|
|
echo "Python and gunicorn executables."
|
|
|
|
echo ""
|
|
|
|
echo "netbox.service ExecStart:"
|
|
|
|
echo " ${VIRTUALENV}/bin/gunicorn"
|
|
|
|
echo ""
|
|
|
|
echo "netbox-rq.service ExecStart:"
|
|
|
|
echo " ${VIRTUALENV}/bin/python"
|
2020-03-04 17:19:16 -05:00
|
|
|
echo ""
|
|
|
|
echo "After modifying these files, reload the systemctl daemon:"
|
|
|
|
echo " > systemctl daemon-reload"
|
2020-02-26 15:40:05 -05:00
|
|
|
echo "--------------------------------------------------------------------"
|
2020-02-26 15:26:12 -05:00
|
|
|
fi
|
|
|
|
|
2020-02-26 13:54:07 -05:00
|
|
|
echo "Upgrade complete! Don't forget to restart the NetBox services:"
|
2020-03-04 17:19:16 -05:00
|
|
|
echo " > sudo systemctl restart netbox netbox-rq"
|