Skip to content

Commit

Permalink
remove polling and improve update-check and auto-update. Fixes #695
Browse files Browse the repository at this point in the history
  • Loading branch information
schakrava committed Aug 19, 2015
1 parent 38a83ea commit 8a5a768
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
<p>Rockstor is up-to-date. If you've updated recently, reload the browser<b>(Ctrl+Shift+R)</b> for latest UI changes.</p><br>
<% if (autoUpdateEnabled) { %>
<p>Rockstor is configured to check for updates once a day and automatically update itself. If you so choose, you can disable auto update.</p>
<p>Rockstor is configured to check for package updates and automatically upgrade on a daily basis. This will keep your system up to date. While it's not recommended, you can disable this feature and only update when you want to.</p>
<a id="disableAuto" class="btn btn-primary" title="Disable Auto Update">Disable auto update</a>
<% } else { %>
<p>Rockstor can be configured to check for updates once a day and automatically update itself. We recommend you enable auto update.</p>
<p>Rockstor can be configured to check for package updates and automatically upgrade on a daily basis. We recommend you enable this feature to keep your system up to date without delay.</p>
<a id="enableAuto" class="btn btn-primary" title="Enable Auto Update">Enable auto update</a>
<% } %>
<% } %>
Expand All @@ -39,7 +39,7 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4>RockStor is being updated to the latest version. Please wait... &nbsp;&nbsp; </h4>
<h4>RockStor is being updated to the latest version. Please wait... &nbsp;&nbsp; </h4>
</div>
<div class="modal-body">
<div style="text-align: center">
Expand Down
24 changes: 9 additions & 15 deletions src/rockstor/storageadmin/views/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from django.db import transaction
from share_helpers import sftp_snap_toggle
from oauth2_provider.ext.rest_framework import OAuth2Authentication
from system.pkg_mgmt import install_pkg
from system.pkg_mgmt import auto_update
import logging
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -217,27 +217,21 @@ def post(self, request, command):

if (command == 'enable-auto-update'):
try:
install_pkg('yum-cron')
systemctl('yum-cron', 'enable')
systemctl('yum-cron', 'start')
auto_update(enable=True)
return Response({'enabled': True, })
except Exception, e:
msg = ('Failed to enable auto update due to a low level error')
logger.exception(e)
msg = ('Failed to enable auto update due to this exception: '
'%s' % e.__str__())
handle_exception(Exception(msg), request)
finally:
return Response({'enabled': True, })

if (command == 'disable-auto-update'):
try:
systemctl('yum-cron', 'stop')
systemctl('yum-cron', 'disable')
auto_update(enable=False)
return Response({'enabled': False, })
except Exception, e:
msg = ('Failed to disable auto update due to a low level '
'error')
logger.exception(e)
msg = ('Failed to disable auto update due to this exception: '
'%s' % e.__str__())
handle_exception(Exception(msg), request)
finally:
return Response({'enabled': False, })

if (command == 'refresh-pool-state'):
for p in Pool.objects.all():
Expand Down
33 changes: 32 additions & 1 deletion src/rockstor/system/pkg_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,42 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

import os
import re
from tempfile import mkstemp
from shutil import move
from osi import run_command

from services import systemctl
import shutil

YUM = '/usr/bin/yum'


def install_pkg(name):
return run_command([YUM, '--setopt=timeout=600', '-y', 'install', name])

def auto_update(enable=True):
cfile = '/etc/yum/yum-cron.conf'
service = 'yum-cron'
fo, npath = mkstemp()
updated = False
with open(cfile) as ifo, open(npath, 'w') as tfo:
for line in ifo.readlines():
if (re.match('apply_updates = ', line) is not None):
if (enable):
tfo.write('apply_updates = yes\n')
else:
tfo.write('apply_updates = no\n')
updated = True
else:
tfo.write(line)
if (not updated):
raise Exception('apply_updates directive missing in %s, assuming its '
'is corrupt. No change made.' % cfile)
shutil.move(npath, cfile)
if (enable):
systemctl(service, 'enable')
systemctl(service, 'start')
else:
systemctl(service, 'stop')
systemctl(service, 'disable')

0 comments on commit 8a5a768

Please sign in to comment.