added rw remounting of root partition before update
authorCalin Crisan <ccrisan@gmail.com>
Wed, 2 Jul 2014 11:28:56 +0000 (13:28 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Wed, 2 Jul 2014 11:43:32 +0000 (13:43 +0200)
src/handlers.py
src/server.py
src/update.py
static/js/main.js

index f9e5f012b7eea07f02f66eea06fc6559e5642d42..a317f6a528129cdeeaf579aae421aa53babcf508 100644 (file)
@@ -310,6 +310,7 @@ class ConfigHandler(BaseHandler):
             if reboot[0]:
                 if settings.ENABLE_REBOOT:
                     def call_reboot():
+                        logging.info('rebooting')
                         os.system('reboot')
                     
                     ioloop = IOLoop.instance()
index 181b45e77e52578af8c404e82360b784a19ee599..57153f254533199f6655687c8f5035b5ea926a1b 100644 (file)
@@ -51,7 +51,7 @@ application = Application(
         (r'^/update/?$', handlers.UpdateHandler),
         (r'^.*$', handlers.NotFoundHandler),
     ],
-    debug=True, # enables autoreload
+    debug=not settings.ENABLE_REBOOT, # enables autoreload when reboot is disabled
     log_function=log_request,
     static_path=settings.STATIC_PATH,
     static_url_prefix=settings.STATIC_URL
index 21d8c75951b13434d0f868a30248a570589e73ef..e053635e516199819bed4a3069a38eed9c0523e3 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 
+import datetime
 import json
 import logging
 import os.path
 import shutil
+import subprocess
 import tempfile
 import time
 import urllib2
 
+from tornado.ioloop import IOLoop
+
 import settings
 
 
@@ -141,19 +145,25 @@ def cleanup(path):
         logging.error('could cleanup update directory: %(msg)s' % {'msg': unicode(e)})
 
 
-def is_updatable():
-    # the parent directory of the project directory
-    # needs to be writable in order for the updating to be possible
-    
-    parent = os.path.dirname(settings.PROJECT_PATH)
-
-    return os.access(parent, os.W_OK)
-
-
 def perform_update(version):
     logging.info('updating to version %(version)s...' % {'version': version})
     
     try:
+        # make sure the partition where motionEye resides is writable
+        if settings.ENABLE_REBOOT:
+            try:
+                df_lines = subprocess.check_output('df %s' % settings.PROJECT_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(settings.PROJECT_PATH, os.W_OK):
+            raise Exception('path "%s" is not writable' % settings.PROJECT_PATH)
+        
         # download the archive
         archive = download(version)
         temp_path = os.path.dirname(archive)
@@ -188,6 +198,13 @@ def perform_update(version):
         
         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)
+        
         return True
     
     except Exception as e:
index e9bd2ba2eae6801914e664197e3e35423ff360f1..dc4fd38e10563160bb67ae0915dbaf915d988d70 100644 (file)
@@ -1039,11 +1039,29 @@ function doUpdate() {
                 showModalDialog('<div class="modal-progress"></div>');
                 ajax('POST', '/update/?version=' + data.update_version, null, function (result) {
                     if (result) {
-                        setTimeout(function () {
-                            runAlertDialog('motionEye was successfully updated!', function () {
-                                window.location.reload(true);
+                        var count = 0;
+                        function checkServer() {
+                            $.ajax({
+                                type: 'GET',
+                                url: '/config/0/get/',
+                                success: function () {
+                                    runAlertDialog('motionEye was successfully updated!', function () {
+                                        window.location.reload(true);
+                                    });
+                                },
+                                error: function () {
+                                    if (count < 25) {
+                                        count += 1;
+                                        setTimeout(checkServer, 2000);
+                                    }
+                                    else {
+                                        window.location.reload(true);
+                                    }
+                                }
                             });
-                        }, 10000);
+                        }
+                        
+                        setTimeout(checkServer, 15000);
                     }
                     else {
                         runAlertDialog('Update failed!', function () {