System script, implement deley to alert other users; UI

This commit is contained in:
James Barnsley
2018-04-17 15:58:39 +12:00
parent 23dd955d6d
commit c48d07a8cd
10 changed files with 25481 additions and 23589 deletions

View File

@ -504,37 +504,83 @@ class IrisCore(object):
else:
return response
def start_upgrade(self, *args, **kwargs):
def upgrade(self, *args, **kwargs):
callback = kwargs.get('callback', False)
self.broadcast(data={
'method': "upgrading",
'method': "upgrade_started",
'params': {}
})
# Run the system task
path = os.path.dirname(__file__)
subprocess.Popen(["sudo "+path+"/system.sh upgrade"], shell=True)
# Make sure we can run as sudo without password
# TODO: Test cross-platform??
permission_check = str(subprocess.call(["sudo -n "+path+"/system.sh"], shell=True)).lower()
if "password is required" in permission_check:
error = {
'message': "Permission denied",
'description': "Password-less access to "+path+"/system.sh was refused. Check your /etc/sudoers file."
}
if (callback):
callback(False, error)
return
else:
return error
response = {
'message': "Upgrade started, server will restart when completed"
}
# Start the upgrade
output = subprocess.call(["sudo "+path+"/system.sh upgrade"], shell=True)
# Callbacks can be made, while our script continues to run
if (callback):
callback(response)
else:
return response
response = {
'message': "Upgrade complete, restarting server",
'data': {
'output': output
}
}
# And now restart
subprocess.Popen(["sudo "+path+"/system.sh restart"], shell=True)
# Now we can return for simple requests
response = {
'message': "Upgrade complete, restarting server",
'data': {
'output': output
}
}
return response
def restart(self, *args, **kwargs):
callback = kwargs.get('callback', False)
self.broadcast(data={
'method': "restarting",
'method': "restart_started",
'params': {}
})
# Run the system task
path = os.path.dirname(__file__)
# Make sure we can run as sudo without password
# TODO: Test cross-platform??
permission_check = str(subprocess.call(["sudo -n "+path+"/system.sh"], shell=True)).lower()
if "password is required" in permission_check:
error = {
'message': "Permission denied",
'data': {
'description': "Password-less access to "+path+"/system.sh was refused. Check your /etc/sudoers file."
}
}
if (callback):
callback(False, error)
return
else:
return error
subprocess.Popen(["sudo "+path+"/system.sh restart"], shell=True)
response = {

View File

@ -170,7 +170,7 @@ class HttpHandler(tornado.web.RequestHandler):
getattr(mem.iris, slug)(request=self.request, callback=lambda response, error=False: self.handle_result(id=id, method=slug, response=response, error=error))
else:
self.handle_result(id=self.request_id, error={'code': 32601, 'message': "Method "+slug+" does not exist"})
self.handle_result(id=id, error={'code': 32601, 'message': "Method "+slug+" does not exist"})
return
@tornado.web.asynchronous

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -73,7 +73,7 @@
// Release details
// These are automatically injected to built HTML
var build = "1523861573";
var build = "1523910942";
var version = "3.16.3";
// Construct the script tag

View File

@ -1,12 +1,15 @@
#!/bin/bash
if [ $1 = "upgrade" ]; then
if [[ $1 = "upgrade" ]]; then
UPGRADE=$(pip install --upgrade mopidy-iris)
RESTART=$(service mopidy restart)
echo -e "$UPGRADE"
elif [ $1 = "restart" ]; then
RESTART=$(service mopidy restart)
elif [[ $1 = "restart" ]]; then
sleep 5
RESTART=$(service mopidy restart)
echo -e "$RESTART"
fi
exit 0

View File

@ -14,6 +14,24 @@ export function connect(){
}
}
export function connecting(){
return {
type: 'MOPIDY_CONNECTING'
}
}
export function upgradeStarted(){
return {
type: 'MOPIDY_UPGRADE_STARTED'
}
}
export function restartStarted(){
return {
type: 'MOPIDY_RESTART_STARTED'
}
}
export function disconnect(){
return {
type: 'MOPIDY_DISCONNECT'

View File

@ -8,10 +8,10 @@ export default function reducer(mopidy = {}, action){
case 'MOPIDY_CONNECTING':
return Object.assign({}, mopidy, { connected: false, connecting: true });
case 'PUSHER_RESTART_MOPIDY':
return Object.assign({}, mopidy, { connected: false, connecting: true, restarting: true });
case 'MOPIDY_RESTART_STARTED':
return Object.assign({}, mopidy, { restarting: true });
case 'PUSHER_START_UPGRADE':
case 'MOPIDY_UPGRADE_STARTED':
return Object.assign({}, mopidy, { upgrading: true });
case 'MOPIDY_CONNECTED':

View File

@ -4,6 +4,7 @@ import ReactGA from 'react-ga'
var helpers = require('../../helpers.js')
var coreActions = require('../core/actions.js')
var uiActions = require('../ui/actions.js')
var mopidyActions = require('../mopidy/actions.js')
var pusherActions = require('./actions.js')
var lastfmActions = require('../lastfm/actions.js')
var spotifyActions = require('../spotify/actions.js')
@ -92,9 +93,15 @@ const PusherMiddleware = (function(){
case 'radio_stopped':
store.dispatch(pusherActions.radioStopped());
break;
case 'restart':
case 'refresh':
window.location.reload(true);
break;
case 'update_started':
store.dispatch(uiActions.createNotification({content: 'Update running...', type: 'info'}));
break;
case 'restart_started':
store.dispatch(uiActions.createNotification({content: 'Restarting...', type: 'info'}));
break;
}
}
}
@ -483,27 +490,26 @@ const PusherMiddleware = (function(){
request(store, 'restart')
.then(
response => {
// No notification required
store.dispatch(mopidyActions.restartStarted());
},
error => {
store.dispatch(uiActions.createNotification({content: error.message, type: 'bad'}));
store.dispatch(uiActions.createNotification({content: error.message, description: (error.description ? error.description : null), type: 'bad'}));
}
);
next(action);
break
case 'PUSHER_START_UPGRADE':
case 'PUSHER_UPGRADE':
ReactGA.event({ category: 'Pusher', action: 'Upgrade', label: '' });
request(store, 'start_upgrade')
request(store, 'upgrade')
.then(
response => {
// No notification required
store.dispatch(mopidyActions.upgradeStarted());
},
error => {
store.dispatch(uiActions.createNotification({content: error.message, type: 'bad'}));
}
);
next(action);
break;
case 'PUSHER_VERSION':

View File

@ -7,7 +7,6 @@ import FontAwesome from 'react-fontawesome'
import ConfirmationButton from '../components/ConfirmationButton'
import PusherConnectionList from '../components/PusherConnectionList'
import VersionManager from '../components/VersionManager'
import Header from '../components/Header'
import Parallax from '../components/Parallax'
import Icon from '../components/Icon'