Skip to content

Commit

Permalink
update - fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
superstes committed Oct 27, 2021
1 parent 9d5b690 commit a53d5e6
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
30 changes: 16 additions & 14 deletions code/web/base/ga/subviews/system/update.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import user_passes_test
import requests
from threading import Thread

from core.utils.test import test_tcp_stream

Expand Down Expand Up @@ -89,7 +90,10 @@ def update_start(request, current_version):
f"ga_update_path_log={get_server_config(setting='path_log')}\n"
)

web_subprocess(f'sudo systemctl start {config.UPDATE_SERVICE}.service --no-block')
def start():
web_subprocess(f'sudo systemctl start {config.UPDATE_SERVICE}.service')

Thread(target=start()).start()
return redirect('/system/update/status/')

except KeyError as error:
Expand All @@ -101,24 +105,22 @@ def update_status_view(request):
status = 'Running'
reload_time = 5
redirect_time = 30
log_data = str_to_list(web_subprocess(config.LOG_SERVICE_LOG_STATUS % config.UPDATE_SERVICE))
log_data = str_to_list(web_subprocess(f"{config.LOG_SERVICE_LOG_STATUS % config.UPDATE_SERVICE} | grep ' {config.UPDATE_SERVICE}\\['"))
update_status = web_subprocess(command=f"systemctl is-active {config.UPDATE_SERVICE}.service")

if log_data[2].find('activating') == -1:
if update_status.find('activating') == -1:
reload_time = 0
redirect_time = 0
status = 'Finished'

if log_data[-3].find('Succeeded') != -1:
status = 'Finished successfully!'
status = 'Finished with unidentified result!'

elif log_data[2].find('failed') != -1:
status = 'Failed!'
for line in log_data[-6:-2]:
if line.find('Update failed') != -1:
status = 'Failed!'
break

else:
for line in log_data[-5:-2]:
if line.find('failed') != -1 or line.find('Failed') != -1:
status = 'Failed'
break
elif line.find('Update succeeded') != -1:
status = 'Finished successfully!'
break

return render(request, 'system/update/status.html', context={
'request': request, 'title': 'System Update Status', 'log_data': log_data, 'reload_time': reload_time, 'status': status, 'redirect_time': redirect_time,
Expand Down
3 changes: 3 additions & 0 deletions code/web/base/ga/templates/info/update.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="alert alert-info" id="downloadStarted" style="display:none;">
Update started - redirecting! (<i>this can take ~1 minute</i>)
</div>
1 change: 1 addition & 0 deletions code/web/base/ga/templates/system/update/offline.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
</div>
<input type="hidden" name="type" value="offline" />
{% include "../../btn/start.html" %}
{% include "../../info/update.html" %}
</form>
{% endblock %}
4 changes: 1 addition & 3 deletions code/web/base/ga/templates/system/update/online.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
{% include "../../btn/start.html" %}
</form>
<br>
<div class="alert alert-info" id="downloadStarted" style="display:none;">
Update download started!
</div>
{% include "../../info/update.html" %}
{% else %}
{% include "../../error/online_update.html" %}
{% endif %}
Expand Down
5 changes: 1 addition & 4 deletions code/web/base/ga/templates/system/update/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ <h2>Log data:</h2>
<li class="ga-file-content-line">{{ line }}</li>
{% endfor %}
</ol>
<div class="alert alert-warning">
If the update fails hard you might need to read the update logs via:<br>
'journalctl -u ga_update.service --no-pager --full -n{LINECOUNT}'
</div>
{% include "../../warn/update_status.html" %}
{% include "../../js/auto_reload.html" %}
{% if redirect_time != 0 %}
<script>
Expand Down
7 changes: 7 additions & 0 deletions code/web/base/ga/templates/warn/update_status.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<br><br>
<div class="alert alert-warning">
This update page might fail to load/time-out while updating.<br>
In that case => just refresh the page after some (<i>~1-5</i>) minutes.<br><br>
If the update fails hard you might need to read the update logs via:<br>
'journalctl -u ga_update.service --no-pager --full -n{LINECOUNT}'
</div>
4 changes: 2 additions & 2 deletions setup/roles/update/tasks/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ansible.builtin.set_fact:
ga_remove_core_venv: true
changed_when: false
when: ga_raw_core_venv_version.stdout|float < ga_python_version|float
when: ga_raw_core_venv_version.stdout is version(ga_python_version, '<')

- name: Getting python-version of web-venv
ansible.builtin.shell: "{{ ga_update_path_home_web }}/venv/bin/python3 --version | cut -d ' ' -f2"
Expand All @@ -20,4 +20,4 @@
ansible.builtin.set_fact:
ga_remove_web_venv: true
changed_when: false
when: ga_raw_web_venv_version.stdout|float < ga_python_version|float
when: ga_raw_web_venv_version.stdout is version(ga_python_version, '<')

0 comments on commit a53d5e6

Please sign in to comment.