__netbox: use __pyenv and remove obsolete netbox stop

Now, the python venv is now created via `pyvenv` or `python3 -m venv`
instead of the legacy `virtualenv`. For this, not all python processes
from the venv need to be stopped.

Migration from previous versions of this type may be difficult, but
solvable if the venv will be recreated.
This commit is contained in:
matze 2020-10-17 10:16:25 +02:00
parent 72f2996c50
commit 144cae3b79
2 changed files with 9 additions and 25 deletions

View File

@ -24,26 +24,7 @@ cd "\$tmpdir"
curl -sS -L '$url' > '$archive' curl -sS -L '$url' > '$archive'
tar xf '$archive' tar xf '$archive'
EOF
# Stop everything in the pyenv to update
cat << EOF
# Try to stop everything in the venv (ignore non-existant services)
systemctl -q stop netbox gunicorn-netbox uwsgi-netbox || true
# kill and poll till all venv processes end
# at least if they are called with full path in the cmd (like in the services)
pids="\$( ps -axo pid,cmd | awk '\$2 ~ "^/opt/netbox/venv/"{print \$1}' )"
if [ "\$pids" ]; then
kill \$pids
while ps -axo pid,cmd | awk '\$2 ~ "^/opt/netbox/venv/"{print \$1}' | grep -q . ; do
sleep 0.5
done
fi
EOF
cat << EOF
# backup requirement files # backup requirement files
if [ -f /opt/netbox/requirements.txt ]; then if [ -f /opt/netbox/requirements.txt ]; then
cp /opt/netbox/requirements.txt /opt/netbox/old-requirements.txt cp /opt/netbox/requirements.txt /opt/netbox/old-requirements.txt
@ -61,9 +42,7 @@ ln -fs /opt/netbox/cdist/configuration.py '$install_dir/netbox/configuration.py'
ln -fs /opt/netbox/cdist/ldap_config.py '$install_dir/netbox/ldap_config.py' ln -fs /opt/netbox/cdist/ldap_config.py '$install_dir/netbox/ldap_config.py'
# Setup & enter python virtualenv. # virtualenv is given already by __pyvenv, just using it
# forcing python3 to be sure (till python4 gets released ..)
virtualenv -p python3 /opt/netbox/venv
# Uninstall packages not required anymore # Uninstall packages not required anymore
# if versions not be shortend, they will be ignored by pip, but not by comm # if versions not be shortend, they will be ignored by pip, but not by comm
@ -112,6 +91,7 @@ rm -rf "\$tmpdir"
# Save version after successful installation # Save version after successful installation
printf "%s\\n" "$VERSION" > /opt/netbox/cdist/version printf "%s\\n" "$VERSION" > /opt/netbox/cdist/version
EOF EOF
# meta # meta
@ -127,10 +107,12 @@ if grep -q "^__file/opt/netbox/" "$__messages_in"; then
fi fi
# check for changes # Check for changes
if [ "$changes" = "yes" ]; then if [ "$changes" = "yes" ]; then
# to avoid database corruption at config changes, both services must be # After the upstream upgrade.sh script, it's ok to migrate while the
# stopped at the same time (noted in the manual, too). # application is running ;)
# restarting after changes
cat << EOF cat << EOF
# Restart service. All required services are included with netbox.service. # Restart service. All required services are included with netbox.service.
systemctl restart netbox systemctl restart netbox

View File

@ -187,6 +187,8 @@ fi
# Create system user used to run netbox. # Create system user used to run netbox.
__user netbox --system --home /opt/netbox --create-home __user netbox --system --home /opt/netbox --create-home
# Generate python environment (user will be set by gencode-remote)
require="__user/netbox" __pyvenv /opt/netbox/venv/
# Generate and upload netbox configuration. # Generate and upload netbox configuration.
mkdir -p "$__object/files" mkdir -p "$__object/files"