Testing restarter
This commit is contained in:
@ -22,12 +22,7 @@ if sys.platform == 'win32':
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class IrisCore(object):
|
||||
|
||||
version = 0
|
||||
if sys.platform == 'win32':
|
||||
is_root = ctypes.windll.shell32.IsUserAnAdmin() != 0
|
||||
else:
|
||||
is_root = os.geteuid() == 0
|
||||
spotify_token = False
|
||||
queue_metadata = {}
|
||||
connections = {}
|
||||
@ -463,6 +458,7 @@ class IrisCore(object):
|
||||
|
||||
response = {
|
||||
'config': {
|
||||
"is_root": self.is_root(),
|
||||
"spotify_username": spotify_username,
|
||||
"country": self.config['iris']['country'],
|
||||
"locale": self.config['iris']['locale'],
|
||||
@ -499,7 +495,7 @@ class IrisCore(object):
|
||||
'version': {
|
||||
'current': self.version,
|
||||
'latest': latest_version,
|
||||
'is_root': self.is_root,
|
||||
'is_root': self.is_root(),
|
||||
'upgrade_available': upgrade_available
|
||||
}
|
||||
}
|
||||
@ -508,18 +504,19 @@ class IrisCore(object):
|
||||
else:
|
||||
return response
|
||||
|
||||
def perform_upgrade(self, *args, **kwargs):
|
||||
def upgrade(self, *args, **kwargs):
|
||||
callback = kwargs.get('callback', False)
|
||||
|
||||
try:
|
||||
subprocess.check_call(["pip", "install", "--upgrade", "Mopidy-Iris"])
|
||||
subprocess.check_call(["sudo", "pip", "install", "--upgrade", "mopidy-iris"])
|
||||
response = {
|
||||
'result': "Upgrade started"
|
||||
'message': "Upgrade completed, restarting..."
|
||||
}
|
||||
if (callback):
|
||||
callback(response)
|
||||
else:
|
||||
return response
|
||||
|
||||
self.restart()
|
||||
return response
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
error = {
|
||||
@ -531,7 +528,23 @@ class IrisCore(object):
|
||||
return error
|
||||
|
||||
def restart(self, *args, **kwargs):
|
||||
os.execl(sys.executable, *([sys.executable]+sys.argv))
|
||||
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
|
||||
|
||||
|
||||
##
|
||||
@ -925,6 +938,18 @@ class IrisCore(object):
|
||||
http_client.fetch(request, callback=callback)
|
||||
|
||||
|
||||
|
||||
|
||||
##
|
||||
# Detect if we're running as root
|
||||
##
|
||||
def is_root(self):
|
||||
if sys.platform == 'win32':
|
||||
return ctypes.windll.shell32.IsUserAnAdmin() != 0
|
||||
else:
|
||||
return os.geteuid() == 0
|
||||
|
||||
|
||||
##
|
||||
# Simple test method
|
||||
##
|
||||
|
||||
@ -4730,6 +4730,7 @@ exports.setUsername = setUsername;
|
||||
exports.connect = connect;
|
||||
exports.disconnect = disconnect;
|
||||
exports.startUpgrade = startUpgrade;
|
||||
exports.restartMopidy = restartMopidy;
|
||||
exports.getConnections = getConnections;
|
||||
exports.connectionAdded = connectionAdded;
|
||||
exports.connectionChanged = connectionChanged;
|
||||
@ -4788,7 +4789,13 @@ function disconnect() {
|
||||
|
||||
function startUpgrade() {
|
||||
return {
|
||||
type: 'START_UPGRADE'
|
||||
type: 'PUSHER_START_UPGRADE'
|
||||
};
|
||||
}
|
||||
|
||||
function restartMopidy() {
|
||||
return {
|
||||
type: 'PUSHER_RESTART_MOPIDY'
|
||||
};
|
||||
}
|
||||
|
||||
@ -51129,14 +51136,7 @@ var PusherMiddleware = function () {
|
||||
case 'PUSHER_START_UPGRADE':
|
||||
_reactGa2.default.event({ category: 'Pusher', action: 'Upgrade', label: '' });
|
||||
request(store, 'upgrade').then(function (response) {
|
||||
if (response.upgrade_successful) {
|
||||
store.dispatch(uiActions.createNotification({ content: 'Upgrade complete' }));
|
||||
} else {
|
||||
store.dispatch(uiActions.createNotification({ content: 'Upgrade failed, please upgrade manually', type: 'bad' }));
|
||||
}
|
||||
|
||||
response.type = 'PUSHER_VERSION';
|
||||
store.dispatch(response);
|
||||
store.dispatch(uiActions.createNotification({ content: response.message }));
|
||||
}, function (error) {
|
||||
store.dispatch(coreActions.handleException('Could not start upgrade', error));
|
||||
});
|
||||
@ -51300,6 +51300,11 @@ var PusherMiddleware = function () {
|
||||
window.location.reload(true);
|
||||
break;
|
||||
|
||||
case 'PUSHER_RESTART_MOPIDY':
|
||||
store.dispatch(uiActions.createNotification({ content: 'Restarting Mopidy...' }));
|
||||
request(store, 'restart');
|
||||
break;
|
||||
|
||||
case 'PUSHER_VERSION':
|
||||
_reactGa2.default.event({ category: 'Pusher', action: 'Version', label: action.version.current });
|
||||
|
||||
@ -68903,6 +68908,9 @@ var Settings = function (_React$Component) {
|
||||
{ className: 'input' },
|
||||
_react2.default.createElement(_ConfirmationButton2.default, { className: 'destructive', content: 'Reset all settings', confirmingContent: 'Are you sure?', onConfirm: function onConfirm() {
|
||||
return _this2.resetAllSettings();
|
||||
} }),
|
||||
_react2.default.createElement(_ConfirmationButton2.default, { className: 'destructive', content: 'Restart server', confirmingContent: 'Are you sure?', onConfirm: function onConfirm() {
|
||||
return _this2.props.pusherActions.restartMopidy();
|
||||
} })
|
||||
)
|
||||
),
|
||||
@ -69202,27 +69210,28 @@ var VersionManager = function (_React$Component) {
|
||||
value: function renderUpgradeButton() {
|
||||
var _this2 = this;
|
||||
|
||||
return _react2.default.createElement(
|
||||
'button',
|
||||
{ className: 'productive', onClick: function onClick() {
|
||||
return _this2.props.pusherActions.startUpgrade();
|
||||
} },
|
||||
'Upgrade to ',
|
||||
this.props.pusher.version.latest
|
||||
);
|
||||
|
||||
if (this.props.pusher.upgrading) {
|
||||
return _react2.default.createElement(
|
||||
'button',
|
||||
{ className: 'outline', disabled: true },
|
||||
{ className: 'productive working', disabled: true },
|
||||
_react2.default.createElement(_reactFontawesome2.default, { name: 'circle-o-notch', spin: true }),
|
||||
'\xA0 Upgrading'
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.props.pusher.version.is_root) {
|
||||
return _react2.default.createElement(
|
||||
'button',
|
||||
{ className: 'outline', disabled: true },
|
||||
'Not running as root'
|
||||
);
|
||||
}
|
||||
|
||||
if (this.props.pusher.version.upgrade_available) {
|
||||
return _react2.default.createElement(
|
||||
'button',
|
||||
{ className: 'primary', onClick: function onClick() {
|
||||
{ className: 'productive', onClick: function onClick() {
|
||||
return _this2.props.pusherActions.startUpgrade();
|
||||
} },
|
||||
'Upgrade to ',
|
||||
@ -69232,8 +69241,8 @@ var VersionManager = function (_React$Component) {
|
||||
|
||||
return _react2.default.createElement(
|
||||
'button',
|
||||
{ className: 'outline', disabled: true },
|
||||
'No updates available'
|
||||
{ className: 'secondary', disabled: true },
|
||||
'Already up-to-date'
|
||||
);
|
||||
}
|
||||
}, {
|
||||
@ -69242,13 +69251,13 @@ var VersionManager = function (_React$Component) {
|
||||
return _react2.default.createElement(
|
||||
'span',
|
||||
{ className: 'version-manager' },
|
||||
this.renderUpgradeButton(),
|
||||
_react2.default.createElement(
|
||||
'span',
|
||||
{ className: 'description' },
|
||||
null,
|
||||
this.props.pusher.version.current,
|
||||
' installed'
|
||||
)
|
||||
),
|
||||
this.renderUpgradeButton()
|
||||
);
|
||||
}
|
||||
}]);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -73,7 +73,7 @@
|
||||
|
||||
// Release details
|
||||
// These are automatically injected to built HTML
|
||||
var build = "1523668283";
|
||||
var build = "1523743020";
|
||||
var version = "3.16.3";
|
||||
|
||||
// Construct the script tag
|
||||
|
||||
@ -15,9 +15,11 @@ class VersionManager extends React.Component{
|
||||
}
|
||||
|
||||
renderUpgradeButton(){
|
||||
return <button className="productive" onClick={() => this.props.pusherActions.startUpgrade()}>Upgrade to { this.props.pusher.version.latest }</button>
|
||||
|
||||
if (this.props.pusher.upgrading){
|
||||
return (
|
||||
<button className="outline" disabled>
|
||||
<button className="productive working" disabled>
|
||||
<FontAwesome name="circle-o-notch" spin />
|
||||
|
||||
Upgrading
|
||||
@ -25,22 +27,18 @@ class VersionManager extends React.Component{
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.props.pusher.version.is_root){
|
||||
return <button className="outline" disabled>Not running as root</button>
|
||||
}
|
||||
|
||||
if (this.props.pusher.version.upgrade_available){
|
||||
return <button className="primary" onClick={() => this.props.pusherActions.startUpgrade()}>Upgrade to { this.props.pusher.version.latest }</button>
|
||||
return <button className="productive" onClick={() => this.props.pusherActions.startUpgrade()}>Upgrade to { this.props.pusher.version.latest }</button>
|
||||
}
|
||||
|
||||
return <button className="outline" disabled>No updates available</button>
|
||||
return <button className="secondary" disabled>Already up-to-date</button>
|
||||
}
|
||||
|
||||
render(){
|
||||
return (
|
||||
<span className="version-manager">
|
||||
{ this.renderUpgradeButton() }
|
||||
<span className="description">{ this.props.pusher.version.current } installed</span>
|
||||
<span>{ this.props.pusher.version.current } installed</span>
|
||||
{this.renderUpgradeButton()}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
@ -31,7 +31,13 @@ export function disconnect(){
|
||||
|
||||
export function startUpgrade(){
|
||||
return {
|
||||
type: 'START_UPGRADE'
|
||||
type: 'PUSHER_START_UPGRADE'
|
||||
}
|
||||
}
|
||||
|
||||
export function restartMopidy(){
|
||||
return {
|
||||
type: 'PUSHER_RESTART_MOPIDY'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -270,16 +270,9 @@ const PusherMiddleware = (function(){
|
||||
request(store, 'upgrade')
|
||||
.then(
|
||||
response => {
|
||||
if (response.upgrade_successful){
|
||||
store.dispatch(uiActions.createNotification({content: 'Upgrade complete'}));
|
||||
} else {
|
||||
store.dispatch(uiActions.createNotification({content: 'Upgrade failed, please upgrade manually', type: 'bad'}));
|
||||
}
|
||||
|
||||
response.type = 'PUSHER_VERSION'
|
||||
store.dispatch(response)
|
||||
store.dispatch(uiActions.createNotification({content: response.message}));
|
||||
},
|
||||
error => {
|
||||
error => {
|
||||
store.dispatch(coreActions.handleException(
|
||||
'Could not start upgrade',
|
||||
error
|
||||
@ -503,6 +496,11 @@ const PusherMiddleware = (function(){
|
||||
window.location.reload(true);
|
||||
break
|
||||
|
||||
case 'PUSHER_RESTART_MOPIDY':
|
||||
store.dispatch(uiActions.createNotification({content: 'Restarting Mopidy...'}));
|
||||
request(store, 'restart');
|
||||
break
|
||||
|
||||
case 'PUSHER_VERSION':
|
||||
ReactGA.event({ category: 'Pusher', action: 'Version', label: action.version.current })
|
||||
|
||||
|
||||
@ -266,6 +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()} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user