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
|
"$0" start
|
||||||
exit $?
|
exit $?
|
||||||
else
|
else
|
||||||
exit 1
|
"$0" start
|
||||||
|
exit $?
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ "$1" == "open" ]; then
|
if [ "$1" == "open" ]; then
|
||||||
|
|
33
oml/api.py
33
oml/api.py
|
@ -10,6 +10,8 @@ import ox
|
||||||
from oxtornado import actions
|
from oxtornado import actions
|
||||||
|
|
||||||
|
|
||||||
|
import settings
|
||||||
|
|
||||||
import item.api
|
import item.api
|
||||||
import user.api
|
import user.api
|
||||||
|
|
||||||
|
@ -76,3 +78,34 @@ def autocompleteFolder(data):
|
||||||
'items': ox.sorted_strings(folders)
|
'items': ox.sorted_strings(folders)
|
||||||
}
|
}
|
||||||
actions.register(autocompleteFolder, cache=False)
|
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 os
|
||||||
import sys
|
import sys
|
||||||
|
import signal
|
||||||
|
|
||||||
from tornado.httpserver import HTTPServer
|
from tornado.httpserver import HTTPServer
|
||||||
from tornado.ioloop import IOLoop
|
from tornado.ioloop import IOLoop
|
||||||
|
@ -94,14 +95,20 @@ def run():
|
||||||
host = settings.server['address']
|
host = settings.server['address']
|
||||||
url = 'http://%s:%s/' % (host, settings.server['port'])
|
url = 'http://%s:%s/' % (host, settings.server['port'])
|
||||||
print('open browser at %s' % url)
|
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:
|
try:
|
||||||
state.main.start()
|
state.main.start()
|
||||||
except:
|
except:
|
||||||
print('shutting down...')
|
print('shutting down...')
|
||||||
|
shutdown()
|
||||||
if state.downloads:
|
|
||||||
state.downloads.join()
|
|
||||||
if state.tasks:
|
|
||||||
state.tasks.join()
|
|
||||||
if state.nodes:
|
|
||||||
state.nodes.join()
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ def check():
|
||||||
old = settings.release['modules']['openmedialibrary']['version']
|
old = settings.release['modules']['openmedialibrary']['version']
|
||||||
new = release['modules']['openmedialibrary']['version']
|
new = release['modules']['openmedialibrary']['version']
|
||||||
return verify(release) and old < new
|
return verify(release) and old < new
|
||||||
|
return False
|
||||||
|
|
||||||
def download():
|
def download():
|
||||||
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
|
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
|
||||||
|
|
|
@ -14,7 +14,8 @@ oml.ui.appDialog = function() {
|
||||||
|
|
||||||
$panel = Ox.TabPanel({
|
$panel = Ox.TabPanel({
|
||||||
content: function(id) {
|
content: function(id) {
|
||||||
var $logo = Ox.Element(),
|
var $content = Ox.Element(),
|
||||||
|
$logo = Ox.Element(),
|
||||||
$text = Ox.Element()
|
$text = Ox.Element()
|
||||||
.addClass('OxTextPage'),
|
.addClass('OxTextPage'),
|
||||||
title = Ox.getObjectById(
|
title = Ox.getObjectById(
|
||||||
|
@ -33,6 +34,47 @@ oml.ui.appDialog = function() {
|
||||||
height: '192px'
|
height: '192px'
|
||||||
})
|
})
|
||||||
.appendTo($logo);
|
.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>')
|
$('<div>')
|
||||||
.css({
|
.css({
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
@ -41,10 +83,7 @@ oml.ui.appDialog = function() {
|
||||||
top: '16px',
|
top: '16px',
|
||||||
overflowY: 'auto'
|
overflowY: 'auto'
|
||||||
})
|
})
|
||||||
.html(
|
.append($content)
|
||||||
'<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.'
|
|
||||||
)
|
|
||||||
.appendTo($text);
|
.appendTo($text);
|
||||||
return Ox.SplitPanel({
|
return Ox.SplitPanel({
|
||||||
elements: [
|
elements: [
|
||||||
|
@ -103,6 +142,20 @@ oml.ui.appDialog = function() {
|
||||||
$panel.selectTab(section);
|
$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;
|
return that;
|
||||||
|
|
||||||
};
|
};
|
Loading…
Reference in a new issue