Bundle sudo actions into system task for cleaner permissions - some users may not be comfortable with this
This commit is contained in:
@ -504,47 +504,45 @@ class IrisCore(object):
|
||||
else:
|
||||
return response
|
||||
|
||||
def upgrade(self, *args, **kwargs):
|
||||
def start_upgrade(self, *args, **kwargs):
|
||||
callback = kwargs.get('callback', False)
|
||||
|
||||
try:
|
||||
subprocess.check_call(["sudo", "pip", "install", "--upgrade", "mopidy-iris"])
|
||||
response = {
|
||||
'message': "Upgrade completed, restarting..."
|
||||
}
|
||||
if (callback):
|
||||
callback(response)
|
||||
self.broadcast(data={
|
||||
'method': "upgrading",
|
||||
'params': {}
|
||||
})
|
||||
|
||||
self.restart()
|
||||
# Run the system task
|
||||
subprocess.Popen(["sudo /home/iris/system.sh upgrade"], shell=True)
|
||||
|
||||
response = {
|
||||
'message': "Upgrade completed, restarting..."
|
||||
}
|
||||
if (callback):
|
||||
callback(response)
|
||||
else:
|
||||
return response
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
error = {
|
||||
'result': "Could not start upgrade"
|
||||
}
|
||||
if (callback):
|
||||
callback(False, error)
|
||||
else:
|
||||
return error
|
||||
|
||||
def restart(self, *args, **kwargs):
|
||||
callback = kwargs.get('callback', False)
|
||||
|
||||
# Send callback if we have one, otherwise don't bother. We can't return anything
|
||||
# when we're rebooting ourselves...
|
||||
if (callback):
|
||||
result = {
|
||||
'message': "Restarting... please wait"
|
||||
}
|
||||
callback(result)
|
||||
|
||||
self.broadcast(data={
|
||||
'method': "restarting",
|
||||
'params': {}
|
||||
})
|
||||
|
||||
subprocess.Popen(["sudo /etc/init.d/mopidy restart"], shell=True)
|
||||
return
|
||||
subprocess.Popen(["sudo /home/iris/system.sh restart"], shell=True)
|
||||
|
||||
# Send callback if we have one, otherwise don't bother. We can't return anything
|
||||
# when we're rebooting ourselves...
|
||||
response = {
|
||||
'message': "Restarting... please wait"
|
||||
}
|
||||
if (callback):
|
||||
callback(response)
|
||||
else:
|
||||
return response
|
||||
|
||||
|
||||
##
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -52,10 +52,22 @@ export default class ConfirmationButton extends React.Component{
|
||||
if (this.state.confirming){
|
||||
className += ' confirming';
|
||||
content = this.props.confirmingContent;
|
||||
if (this.state.timing_out ) className += ' timing-out';
|
||||
if (this.state.timing_out){
|
||||
className += ' timing-out';
|
||||
}
|
||||
}
|
||||
|
||||
if (this.props.className ) className += ' '+this.props.className
|
||||
if (this.props.working){
|
||||
className += ' working';
|
||||
|
||||
if (this.props.workingContent){
|
||||
content = this.props.workingContent;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.props.className){
|
||||
className += ' '+this.props.className;
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
|
||||
@ -8,8 +8,11 @@ export default function reducer(mopidy = {}, action){
|
||||
case 'MOPIDY_CONNECTING':
|
||||
return Object.assign({}, mopidy, { connected: false, connecting: true });
|
||||
|
||||
case 'MOPIDY_RESTARTING':
|
||||
return Object.assign({}, mopidy, { connected: false, connecting: true, restarting: true });
|
||||
|
||||
case 'MOPIDY_CONNECTED':
|
||||
return Object.assign({}, mopidy, { connected: true, connecting: false });
|
||||
return Object.assign({}, mopidy, { connected: true, connecting: false, restarting: false });
|
||||
|
||||
case 'MOPIDY_DISCONNECTED':
|
||||
return Object.assign({}, mopidy, { connected: false, connecting: false });
|
||||
|
||||
@ -265,23 +265,6 @@ const PusherMiddleware = (function(){
|
||||
})
|
||||
break;
|
||||
|
||||
case 'PUSHER_START_UPGRADE':
|
||||
ReactGA.event({ category: 'Pusher', action: 'Upgrade', label: '' })
|
||||
request(store, 'upgrade')
|
||||
.then(
|
||||
response => {
|
||||
store.dispatch(uiActions.createNotification({content: response.message}));
|
||||
},
|
||||
error => {
|
||||
store.dispatch(coreActions.handleException(
|
||||
'Could not start upgrade',
|
||||
error
|
||||
));
|
||||
}
|
||||
);
|
||||
return next(action);
|
||||
break;
|
||||
|
||||
case 'PUSHER_SET_USERNAME':
|
||||
request(store, 'set_username', {username: action.username})
|
||||
.then(
|
||||
@ -490,6 +473,19 @@ const PusherMiddleware = (function(){
|
||||
store.dispatch(uiActions.createNotification(data));
|
||||
break
|
||||
|
||||
case 'PUSHER_START_UPGRADE':
|
||||
ReactGA.event({ category: 'Pusher', action: 'Upgrade', label: '' })
|
||||
request(store, 'start_upgrade')
|
||||
.then(
|
||||
response => {
|
||||
store.dispatch(uiActions.createNotification({content: response.message}));
|
||||
},
|
||||
error => {
|
||||
store.dispatch(uiActions.createNotification({content: error.message, type: 'bad'}));
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
case 'PUSHER_RESTART':
|
||||
// Hard reload. This doesn't strictly clear the cache, but our compiler's
|
||||
// cache buster should handle that
|
||||
@ -497,8 +493,16 @@ const PusherMiddleware = (function(){
|
||||
break
|
||||
|
||||
case 'PUSHER_RESTART_MOPIDY':
|
||||
store.dispatch(uiActions.createNotification({content: 'Restarting Mopidy...'}));
|
||||
request(store, 'restart');
|
||||
store.dispatch({type: 'MOPIDY_RESTARTING'});
|
||||
request(store, 'restart')
|
||||
.then(
|
||||
response => {
|
||||
store.dispatch(uiActions.createNotification({content: response.message}));
|
||||
},
|
||||
error => {
|
||||
store.dispatch(uiActions.createNotification({content: error.message, type: 'bad'}));
|
||||
}
|
||||
);
|
||||
break
|
||||
|
||||
case 'PUSHER_VERSION':
|
||||
|
||||
@ -266,7 +266,7 @@ class Settings extends React.Component {
|
||||
<div className="name">Reset</div>
|
||||
<div className="input">
|
||||
<ConfirmationButton className="destructive" content="Reset all settings" confirmingContent="Are you sure?" onConfirm={() => this.resetAllSettings()} />
|
||||
<ConfirmationButton className="destructive" content="Restart server" confirmingContent="Are you sure?" onConfirm={() => this.props.pusherActions.restartMopidy()} />
|
||||
<ConfirmationButton className="destructive" content="Restart server" confirmingContent="Are you sure?" workingContent="Restarting" working={this.props.mopidy.restarting} onConfirm={() => this.props.pusherActions.restartMopidy()} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
19
system.sh
Executable file
19
system.sh
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
ACTION=$1
|
||||
|
||||
if [ $ACTION = "upgrade" ]; then
|
||||
UPGRADE=$(pip install --upgrade mopidy-iris)
|
||||
echo -e "$UPGRADE"
|
||||
|
||||
RESTART=$(service mopidy restart)
|
||||
echo -e "$RESTART"
|
||||
|
||||
elif [ $ACTION = "restart" ]; then
|
||||
|
||||
RESTART=$(service mopidy restart)
|
||||
echo -e "$RESTART"
|
||||
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user