diff --git a/app/templates/github_trigger_upgrade.html b/app/templates/github_trigger_upgrade.html index f5226ecc..fc6bbf0d 100644 --- a/app/templates/github_trigger_upgrade.html +++ b/app/templates/github_trigger_upgrade.html @@ -74,6 +74,12 @@
Need to manually refresh the Python packages without upgrading? Click the below to trigger a refresh without pulling + new code from GitHub
++ Update/Install Missing Python Packages +
+ {% if allow_git_branch_switching %}+ You have triggered a manual reload of the Python packages required by Fermentrack. Please wait several minutes + for this refresh to complete and for Fermentrack to relaunch before proceeding. +
+ ++ Once complete, you can view the upgrade log to see + what was installed/updated. +
+ + +{% endblock %} + + + +{% block scripts %} +{% endblock %} \ No newline at end of file diff --git a/app/views.py b/app/views.py index 72a4d797..e5b1460e 100644 --- a/app/views.py +++ b/app/views.py @@ -540,6 +540,20 @@ def github_trigger_force_upgrade(request): +@login_required +@site_is_configured +def trigger_requirements_reload(request): + # TODO - Add permission check here + + # All that this view does is trigger the utils/fix_python_requirements.sh shell script and return a message letting + # the user know that Fermentrack will take a few minutes to restart. + cmd = "nohup utils/fix_python_requirements.sh &" + messages.success(request, "Triggered a reload of your Python packages") + subprocess.call(cmd, shell=True) + + return render(request, template_name="trigger_requirements_reload.html", context={}) + + def login(request, next=None): if not next: if 'next' in request.GET: diff --git a/docs/source/gravitysensors/tilt.rst b/docs/source/gravitysensors/tilt.rst index d811bfd8..f95fbfc1 100644 --- a/docs/source/gravitysensors/tilt.rst +++ b/docs/source/gravitysensors/tilt.rst @@ -103,7 +103,12 @@ Although all Python packages should be automatically installed as part of the in packages come out of sync for a variety of reasons. If you are missing packages they will need to be installed for Fermentrack to properly interface with your Tilt. -.. todo:: Enrich this with steps for resolving missing Python packages +A manual refresh of the Python packages can be triggered from the GitHub upgrade page without updating Fermentrack from +GitHub. To trigger a refresh: +#. Log into Fermentrack +#. Click the 'gear' icon in the upper right hand corner of the page +#. Click 'Update from GitHub' +#. Click the 'Update/Install Missing Python Packages' button diff --git a/fermentrack_django/urls.py b/fermentrack_django/urls.py index 48477ad5..e6fa7ac0 100644 --- a/fermentrack_django/urls.py +++ b/fermentrack_django/urls.py @@ -31,6 +31,7 @@ url(r'^upgrade/$', app.views.github_trigger_upgrade, name='github_trigger_upgrade'), url(r'^upgrade/force/$', app.views.github_trigger_force_upgrade, name='github_trigger_force_upgrade'), + url(r'^upgrade/reload/$', app.views.trigger_requirements_reload, name='trigger_requirements_reload'), ### Device Views url(r'^devices/$', app.views.device_lcd_list, name='device_lcd_list'), diff --git a/gravity/templates/gravity/gravity_manage_tilt.html b/gravity/templates/gravity/gravity_manage_tilt.html index 6907e050..f0f4a2f1 100644 --- a/gravity/templates/gravity/gravity_manage_tilt.html +++ b/gravity/templates/gravity/gravity_manage_tilt.html @@ -143,7 +143,11 @@If you are having difficulty getting/keeping your Tilt connected, click here to debug the connection.
+If you are having difficulty getting/keeping your Bluetooth Tilt connected, click the button below to launch the Tilt test script.
+ ++ Troubleshoot Tilt Connection +
{% endif %} diff --git a/gravity/templates/gravity/gravity_tilt_test.html b/gravity/templates/gravity/gravity_tilt_test.html index 394900ab..433aca3a 100644 --- a/gravity/templates/gravity/gravity_tilt_test.html +++ b/gravity/templates/gravity/gravity_tilt_test.html @@ -25,8 +25,8 @@Package Name | -OK? | +Package Name | +OK? |
---|
+ Several of the system packages listed above are required for all of the Python packages to install. If you + do not first install the missing system packages you may be unable to fix other errors that appear on this + page. Thankfully, installing these missing packages is pretty simple. Information on how to resolve this + can be found in the Fermentrack documentation. +
+ {% endif %}{# has_apt_packages #} + + {% else %}@@ -46,6 +59,8 @@
@@ -72,10 +87,10 @@
Package Name | -Required Version | -Installed Version | -OK? | +Package Name | +Required Version | +Installed Version | +OK? |
---|
+ One or more of the Python packages required for Fermentrack's Tilt support to function are either + missing or at an incorrect version. + {% if not has_apt_packages %} + This may be caused by missing system packages. Before proceeding, please ensure that all required + system packages (see the earlier test) are installed. + {% endif %} + The easiest way to resolve this is to trigger a manual refresh of the Python requirements. To do this, + click the button below. If this does not resolve your missing packages check the + upgrade log to see what is happening. +
+ ++ Update/Install Missing Python Packages +
+ {% endif %} + {% else %} -This is a fairly serious error, as it implies that your python packages are not being kept up-to-date. - Check the upgrade log to see what is happening. + If there are missing system packages (above) resolve those before proceeding. Next, attempt a + manual refresh (below) of the Python requirements to see if the 'packaging' module can be installed. If + neither of these resolve this issue, check the + upgrade log to see what is happening. +
+ {% endif %} diff --git a/utils/fix_python_requirements.sh b/utils/fix_python_requirements.sh new file mode 100755 index 00000000..51ef6349 --- /dev/null +++ b/utils/fix_python_requirements.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +# Defaults +SILENT=0 +CIRCUSCTL="python3 -m circus.circusctl --timeout 10" + +# Colors (for printinfo/error/warn below) +green=$(tput setaf 76) +red=$(tput setaf 1) +tan=$(tput setaf 3) +reset=$(tput sgr0) + + + +printinfo() { + if [ ${SILENT} -eq 0 ] + then + printf "::: ${green}%s${reset}\n" "$@" + fi +} + + +printwarn() { + if [ ${SILENT} -eq 0 ] + then + printf "${tan}*** WARNING: %s${reset}\n" "$@" + fi +} + + +printerror() { + if [ ${SILENT} -eq 0 ] + then + printf "${red}*** ERROR: %s${reset}\n" "$@" + fi +} + + + +exec > >(tee -i log/upgrade.log) + + +printinfo "Re-installing Python packages from requirements.txt" +# First, launch the virtualenv +source ~/venv/bin/activate # Assuming the directory based on a normal install with Fermentrack-tools + +# Given that this script can be called by the webapp proper, give it 2 seconds to finish sending a reply to the +# user if he/she initiated an upgrade through the webapp. +printinfo "Waiting 1 second for Fermentrack to send updates if triggered from the web..." +sleep 1s + +# Next, kill the running Fermentrack instance using circus +printinfo "Stopping circus..." +$CIRCUSCTL stop &>> log/upgrade.log + +# Install everything from requirements.txt +printinfo "Updating requirements via pip3..." +pip3 install -U -r requirements.txt --upgrade &>> log/upgrade.log + +# Migrate to create/adjust anything necessary in the database +printinfo "Running manage.py migrate..." +python3 manage.py migrate &>> log/upgrade.log + +# Migrate to create/adjust anything necessary in the database +printinfo "Running manage.py collectstatic..." +python3 manage.py collectstatic --noinput >> /dev/null + + +# Finally, relaunch the Fermentrack instance using circus +printinfo "Relaunching circus..." +$CIRCUSCTL reloadconfig &>> log/upgrade.log +$CIRCUSCTL start &>> log/upgrade.log +printinfo "Complete!"