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