From 5b1e856c45b147797d367026748069311b8e7e2f Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 15 Mar 2015 15:05:11 +0200 Subject: [PATCH] removed the automatic update functionality as it was buggy and unreliable --- motioneye.py | 1 - settings_default.py | 3 - src/handlers.py | 2 +- src/motionctl.py | 8 +- src/update.py | 181 +------------------------------------------- static/js/main.js | 8 +- 6 files changed, 14 insertions(+), 189 deletions(-) diff --git a/motioneye.py b/motioneye.py index 089e7e0..fea033e 100755 --- a/motioneye.py +++ b/motioneye.py @@ -46,7 +46,6 @@ def _configure_settings(): set_default_setting('LOG_PATH', os.path.join(settings.PROJECT_PATH, 'log')) set_default_setting('MEDIA_PATH', os.path.join(settings.PROJECT_PATH, 'media')) set_default_setting('MOTION_BINARY', None) - set_default_setting('REPO', None) set_default_setting('LOG_LEVEL', logging.INFO) set_default_setting('LISTEN', '0.0.0.0') set_default_setting('PORT', 8765) diff --git a/settings_default.py b/settings_default.py index 50f708d..21c42c9 100644 --- a/settings_default.py +++ b/settings_default.py @@ -26,9 +26,6 @@ MEDIA_PATH = os.path.abspath(os.path.join(PROJECT_PATH, 'media')) # path to motion binary (automatically detected if not set) MOTION_BINARY = None -# repository details for software updating -REPO = ('ccrisan', 'motioneye') - # set to logging.DEBUG for verbose output LOG_LEVEL = logging.INFO diff --git a/src/handlers.py b/src/handlers.py index dc0bf95..5fa23b1 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -149,7 +149,7 @@ class MainHandler(BaseHandler): self.render('main.html', frame=False, version=motioneye.VERSION, - enable_update=bool(settings.REPO), + enable_update=False, enable_reboot=settings.ENABLE_REBOOT, main_sections=main_sections, camera_sections=camera_sections, diff --git a/src/motionctl.py b/src/motionctl.py index c910b93..93eb44a 100644 --- a/src/motionctl.py +++ b/src/motionctl.py @@ -26,6 +26,7 @@ import time from tornado.httpclient import HTTPClient, AsyncHTTPClient, HTTPRequest import config +import powerctl import settings import utils @@ -166,7 +167,12 @@ def stop(): os.waitpid(pid, os.WNOHANG) # the process still did not exit - raise Exception('could not terminate the motion process') + if settings.ENABLE_REBOOT: + logging.error('could not terminate the motion process') + powerctl.reboot() + + else: + raise Exception('could not terminate the motion process') except OSError as e: if e.errno not in (errno.ESRCH, errno.ECHILD): diff --git a/src/update.py b/src/update.py index e373906..43f4115 100644 --- a/src/update.py +++ b/src/update.py @@ -15,27 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import datetime -import json import logging -import os.path -import shutil -import signal -import subprocess -import tempfile -import time -import urllib2 - -from tornado.ioloop import IOLoop - -import settings - - -_BITBUCKET_ROOT_URL = 'https://bitbucket.org' -_BITBUCKET_DOWNLOAD_URL = '%(root)s/%(owner)s/%(repo)s/get/%(version)s.tar.gz' -_BITBUCKET_LIST_TAGS_URL = '%(root)s/api/1.0/repositories/%(owner)s/%(repo)s/tags' - -_UPDATE_PATHS = ['src', 'static', 'templates', 'motioneye.py'] # versions @@ -47,28 +27,6 @@ def get_version(): def get_all_versions(): - url = _BITBUCKET_LIST_TAGS_URL % { - 'root': _BITBUCKET_ROOT_URL, - 'owner': settings.REPO[0], - 'repo': settings.REPO[1]} - - url += '?_=' + str(int(time.time())) # prevents caching - - try: - logging.debug('fetching %(url)s...' % {'url': url}) - - response = urllib2.urlopen(url, timeout=settings.REMOTE_REQUEST_TIMEOUT) - response = json.load(response) - versions = response.keys() - - logging.debug('available versions: %(versions)s' % { - 'versions': ', '.join(versions)}) - - return sorted(versions, cmp=compare_versions) - - except Exception as e: - logging.error('could not get versions: %(msg)s' % {'msg': unicode(e)}, exc_info=True) - return [] @@ -99,142 +57,7 @@ def compare_versions(version1, version2): return 0 -# updating - -def download(version): - url = _BITBUCKET_DOWNLOAD_URL % { - 'root': _BITBUCKET_ROOT_URL, - 'owner': settings.REPO[0], - 'repo': settings.REPO[1], - 'version': version} - - url += '?_=' + str(int(time.time())) # prevents caching - - try: - logging.debug('downloading %(url)s...' % {'url': url}) - - response = urllib2.urlopen(url, timeout=settings.REMOTE_REQUEST_TIMEOUT) - data = response.read() - - except Exception as e: - logging.error('could not download update: %(msg)s' % {'msg': unicode(e)}) - - raise - - path = tempfile.mkdtemp() - path = os.path.join(path, version + '.tar.gz') - - logging.debug('writing archive to %(path)s...' % {'path': path}) - - try: - with open(path, 'w') as f: - f.write(data) - - except Exception as e: - logging.error('could not download update: %(msg)s' % {'msg': unicode(e)}) - - raise - - return path - - -def cleanup(path): - try: - shutil.rmtree(path) - - except Exception as e: - logging.error('could cleanup update directory: %(msg)s' % {'msg': unicode(e)}) - - def perform_update(version): - logging.info('updating to version %(version)s...' % {'version': version}) + logging.error('updating is not implemented') - try: - # make sure the partition where motionEye resides is writable - path = os.path.abspath(settings.PROJECT_PATH) - if settings.ENABLE_REBOOT: - try: - df_lines = subprocess.check_output('df %s' % path, shell=True).split('\n') - last_line = [l for l in df_lines if l.strip()][-1] - mount_point = last_line.split()[-1] - - os.system('mount -o remount,rw %s' % mount_point) - - except Exception as e: - logging.error('failed to remount root partition rw: %s' % e, exc_info=True) - - if not os.access(path, os.W_OK): - raise Exception('path "%s" is not writable' % path) - - # download the archive - archive = download(version) - temp_path = os.path.dirname(archive) - - # extract the archive - logging.debug('extracting archive %(archive)s...' % {'archive': archive}) - os.system('tar zxf %(archive)s -C %(path)s' % { - 'archive': archive, 'path': temp_path}) - - # kill all the subprocesses - try: - children_pids = [int(p) for p in subprocess.check_output('ps -o pid --no-headers --ppid %s' % os.getpid(), shell=True).split() if p] - for pid in children_pids: - try: - os.kill(pid, signal.SIGKILL) - logging.debug('killed process %d' % pid) - - except Exception as e: - if getattr(e, 'errno', None) == 3: # no such process - continue - - else: - logging.error('failed to kill process %d: %s' % (pid, e)) - - except Exception as e: - logging.error('failed to kill children processes: %s' % e) - - # determine the root path of the extracted archive - root_name = [f for f in os.listdir(temp_path) if os.path.isdir(os.path.join(temp_path, f))][0] - root_path = os.path.join(temp_path, root_name) - - for p in _UPDATE_PATHS: - src = os.path.join(root_path, p) - dst = os.path.join(settings.PROJECT_PATH, p) - - logging.debug('copying %(src)s over %(dst)s...' % {'src': src, 'dst': dst}) - - if os.path.isdir(dst): - shutil.rmtree(dst) - - if os.path.isdir(src): - shutil.copytree(src, dst) - - else: - shutil.copy(src, dst) - - # remove the temporary update directory - logging.debug('removing %(path)s...' % {'path': temp_path}) - cleanup(temp_path) - - logging.info('updating done') - - if settings.ENABLE_REBOOT: - def call_reboot(): - logging.info('rebooting') - os.system('reboot') - - IOLoop.instance().add_timeout(datetime.timedelta(seconds=2), call_reboot) - - else: - from tornado import autoreload - - # this will reload the interpreter - logging.info('reloading python interpreter...') - autoreload._reload() - - return True - - except Exception as e: - logging.error('could not perform update: %(msg)s' % {'msg': unicode(e)}, exc_info=True) - - return False + return False diff --git a/static/js/main.js b/static/js/main.js index 16869a9..6289b5f 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1920,7 +1920,7 @@ function doUpdate() { showModalDialog('
Updating. This may take a few minutes.
'); ajax('POST', baseUri + 'update/?version=' + data.update_version, null, function () { var count = 0; - function checkServerUpdate() { + function checkServer() { ajax('GET', baseUri + 'config/0/get/', null, function () { runAlertDialog('motionEye was successfully updated!', function () { @@ -1928,9 +1928,9 @@ function doUpdate() { }); }, function () { - if (count < 25) { + if (count < 60) { count += 1; - setTimeout(checkServerUpdate, 2000); + setTimeout(checkServer, 5000); } else { runAlertDialog('Update failed!', function () { @@ -1941,7 +1941,7 @@ function doUpdate() { ); } - setTimeout(checkServerUpdate, 10000); + setTimeout(checkServer, 10000); }, function (e) { /* error */ runAlertDialog('The update process has failed!', function () { -- 2.39.5