check for updates and offer option option to restart
This commit is contained in:
parent
06d74f809d
commit
0bd359f89d
5 changed files with 109 additions and 14 deletions
3
ctl
3
ctl
|
@ -73,7 +73,8 @@ if [ "$1" == "restart" ]; then
|
|||
"$0" start
|
||||
exit $?
|
||||
else
|
||||
exit 1
|
||||
"$0" start
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
if [ "$1" == "open" ]; then
|
||||
|
|
33
oml/api.py
33
oml/api.py
|
@ -10,6 +10,8 @@ import ox
|
|||
from oxtornado import actions
|
||||
|
||||
|
||||
import settings
|
||||
|
||||
import item.api
|
||||
import user.api
|
||||
|
||||
|
@ -76,3 +78,34 @@ def autocompleteFolder(data):
|
|||
'items': ox.sorted_strings(folders)
|
||||
}
|
||||
actions.register(autocompleteFolder, cache=False)
|
||||
|
||||
def getVersion(data):
|
||||
'''
|
||||
check if new version is available
|
||||
'''
|
||||
response = {
|
||||
'current': settings.MINOR_VERSION,
|
||||
'upgrade': False,
|
||||
}
|
||||
if not os.path.exists(os.path.join(settings.updates_path, 'release.json')):
|
||||
return response
|
||||
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
|
||||
return response
|
||||
with open(os.path.join(settings.updates_path, 'release.json')) as fd:
|
||||
release = json.load(fd)
|
||||
current = settings.release['modules']['openmedialibrary']['version']
|
||||
response['current'] = current
|
||||
new = release['modules']['openmedialibrary']['version']
|
||||
response['new'] = new
|
||||
response['update'] = current < new
|
||||
return response
|
||||
actions.register(getVersion, cache=False)
|
||||
|
||||
def restart(data):
|
||||
'''
|
||||
restart (and upgrade if upgrades are available)
|
||||
'''
|
||||
#subprocess.Popen(['./ctl', 'restart'], preexec_fn=os.setpgrp, close_fds=True)
|
||||
subprocess.Popen(['./ctl', 'restart'], close_fds=True)
|
||||
return {}
|
||||
actions.register(restart, cache=False)
|
||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import division, print_function
|
|||
|
||||
import os
|
||||
import sys
|
||||
import signal
|
||||
|
||||
from tornado.httpserver import HTTPServer
|
||||
from tornado.ioloop import IOLoop
|
||||
|
@ -94,14 +95,20 @@ def run():
|
|||
host = settings.server['address']
|
||||
url = 'http://%s:%s/' % (host, settings.server['port'])
|
||||
print('open browser at %s' % url)
|
||||
|
||||
def shutdown():
|
||||
if state.downloads:
|
||||
state.downloads.join()
|
||||
if state.tasks:
|
||||
state.tasks.join()
|
||||
if state.nodes:
|
||||
state.nodes.join()
|
||||
http_server.stop()
|
||||
|
||||
signal.signal(signal.SIGTERM, shutdown)
|
||||
|
||||
try:
|
||||
state.main.start()
|
||||
except:
|
||||
print('shutting down...')
|
||||
|
||||
if state.downloads:
|
||||
state.downloads.join()
|
||||
if state.tasks:
|
||||
state.tasks.join()
|
||||
if state.nodes:
|
||||
state.nodes.join()
|
||||
shutdown()
|
||||
|
|
|
@ -56,6 +56,7 @@ def check():
|
|||
old = settings.release['modules']['openmedialibrary']['version']
|
||||
new = release['modules']['openmedialibrary']['version']
|
||||
return verify(release) and old < new
|
||||
return False
|
||||
|
||||
def download():
|
||||
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
|
||||
|
|
|
@ -14,7 +14,8 @@ oml.ui.appDialog = function() {
|
|||
|
||||
$panel = Ox.TabPanel({
|
||||
content: function(id) {
|
||||
var $logo = Ox.Element(),
|
||||
var $content = Ox.Element(),
|
||||
$logo = Ox.Element(),
|
||||
$text = Ox.Element()
|
||||
.addClass('OxTextPage'),
|
||||
title = Ox.getObjectById(
|
||||
|
@ -33,6 +34,47 @@ oml.ui.appDialog = function() {
|
|||
height: '192px'
|
||||
})
|
||||
.appendTo($logo);
|
||||
if (id == 'update') {
|
||||
$content.html('<h1><b>' + title + '</b></h1>');
|
||||
oml.api.getVersion(function(response) {
|
||||
if (response.data.update) {
|
||||
Ox.Element()
|
||||
.css({
|
||||
paddingTop: '4px',
|
||||
paddingBottom: '16px'
|
||||
})
|
||||
.html('A new version of Open Media Library is available')
|
||||
.appendTo($content);
|
||||
Ox.Button({
|
||||
id: 'update',
|
||||
title: Ox._('Install Now')
|
||||
}).bindEvent({
|
||||
click: function() {
|
||||
this.options({
|
||||
disabled: true,
|
||||
title: 'Installing...'
|
||||
});
|
||||
oml.api.restart(function(response) {
|
||||
if (response.status.code == 200) {
|
||||
setTimeout(reload, 500);
|
||||
}
|
||||
});
|
||||
}
|
||||
}).appendTo($content);
|
||||
} else if (response.data.current == 'git') {
|
||||
Ox.Element()
|
||||
.html('To update a development version, run ./ctl update')
|
||||
.appendTo($content);
|
||||
} else {
|
||||
Ox.Element()
|
||||
.html('No updates available')
|
||||
.appendTo($content);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$content.html('<h1><b>' + title + '</b></h1>'
|
||||
+ '<p>The lazy brown fox jumped over the lazy black fox, but otherwise not really much happened here since you last checked.');
|
||||
}
|
||||
$('<div>')
|
||||
.css({
|
||||
position: 'absolute',
|
||||
|
@ -41,10 +83,7 @@ oml.ui.appDialog = function() {
|
|||
top: '16px',
|
||||
overflowY: 'auto'
|
||||
})
|
||||
.html(
|
||||
'<h1><b>' + title + '</b></h1>'
|
||||
+ '<p>The lazy brown fox jumped over the lazy black fox, but otherwise not really much happened here since you last checked.'
|
||||
)
|
||||
.append($content)
|
||||
.appendTo($text);
|
||||
return Ox.SplitPanel({
|
||||
elements: [
|
||||
|
@ -103,6 +142,20 @@ oml.ui.appDialog = function() {
|
|||
$panel.selectTab(section);
|
||||
};
|
||||
|
||||
function reload() {
|
||||
var ws = new WebSocket('ws:' + document.location.host + '/ws');
|
||||
ws.onopen = function(event) {
|
||||
document.location.href = document.location.protocol + '//' + document.location.host;
|
||||
};
|
||||
ws.onerror = function(event) {
|
||||
ws.close();
|
||||
};
|
||||
ws.onclose = function(event) {
|
||||
console.log('waiting...');
|
||||
setTimeout(reload, 500);
|
||||
};
|
||||
}
|
||||
|
||||
return that;
|
||||
|
||||
};
|
Loading…
Reference in a new issue