(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
# 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
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)
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:
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 () {