Restart/shutdown messages

Restart/Shutodwn no longer use commands (should fix issues with restarts failing)
pull/2/head
Mark McDowall 11 years ago
parent d43e9785d5
commit 94f9db940b

@ -5,6 +5,8 @@ using NzbDrone.Api.Extensions;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Lifecycle.Commands;
namespace NzbDrone.Api.System namespace NzbDrone.Api.System
{ {
@ -15,12 +17,14 @@ namespace NzbDrone.Api.System
private readonly IRouteCacheProvider _routeCacheProvider; private readonly IRouteCacheProvider _routeCacheProvider;
private readonly IConfigFileProvider _configFileProvider; private readonly IConfigFileProvider _configFileProvider;
private readonly IDatabase _database; private readonly IDatabase _database;
private readonly ILifecycleService _lifecycleService;
public SystemModule(IAppFolderInfo appFolderInfo, public SystemModule(IAppFolderInfo appFolderInfo,
IRuntimeInfo runtimeInfo, IRuntimeInfo runtimeInfo,
IRouteCacheProvider routeCacheProvider, IRouteCacheProvider routeCacheProvider,
IConfigFileProvider configFileProvider, IConfigFileProvider configFileProvider,
IDatabase database) IDatabase database,
ILifecycleService lifecycleService)
: base("system") : base("system")
{ {
_appFolderInfo = appFolderInfo; _appFolderInfo = appFolderInfo;
@ -28,8 +32,11 @@ namespace NzbDrone.Api.System
_routeCacheProvider = routeCacheProvider; _routeCacheProvider = routeCacheProvider;
_configFileProvider = configFileProvider; _configFileProvider = configFileProvider;
_database = database; _database = database;
_lifecycleService = lifecycleService;
Get["/status"] = x => GetStatus(); Get["/status"] = x => GetStatus();
Get["/routes"] = x => GetRoutes(); Get["/routes"] = x => GetRoutes();
Post["/shutdown"] = x => Shutdown();
Post["/restart"] = x => Restart();
} }
private Response GetStatus() private Response GetStatus()
@ -62,5 +69,18 @@ namespace NzbDrone.Api.System
{ {
return _routeCacheProvider.GetCache().Values.AsResponse(); return _routeCacheProvider.GetCache().Values.AsResponse();
} }
private Response Shutdown()
{
_lifecycleService.Shutdown();
return "".AsResponse();
} }
private Response Restart()
{
_lifecycleService.Restart();
return "".AsResponse();
} }
}
}

@ -1,4 +1,5 @@
using NLog; using System;
using NLog;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Processes; using NzbDrone.Common.Processes;
@ -9,29 +10,32 @@ using IServiceProvider = NzbDrone.Common.IServiceProvider;
namespace NzbDrone.Core.Lifecycle namespace NzbDrone.Core.Lifecycle
{ {
public class LifecycleService: IExecute<ShutdownCommand>, IExecute<RestartCommand> public interface ILifecycleService
{
void Shutdown();
void Restart();
}
public class LifecycleService : ILifecycleService, IExecute<ShutdownCommand>, IExecute<RestartCommand>
{ {
private readonly IEventAggregator _eventAggregator; private readonly IEventAggregator _eventAggregator;
private readonly IRuntimeInfo _runtimeInfo; private readonly IRuntimeInfo _runtimeInfo;
private readonly IServiceProvider _serviceProvider; private readonly IServiceProvider _serviceProvider;
private readonly IProcessProvider _processProvider;
private readonly Logger _logger; private readonly Logger _logger;
public LifecycleService(IEventAggregator eventAggregator, public LifecycleService(IEventAggregator eventAggregator,
IRuntimeInfo runtimeInfo, IRuntimeInfo runtimeInfo,
IServiceProvider serviceProvider, IServiceProvider serviceProvider,
IProcessProvider processProvider,
Logger logger) Logger logger)
{ {
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_runtimeInfo = runtimeInfo; _runtimeInfo = runtimeInfo;
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_processProvider = processProvider;
_logger = logger; _logger = logger;
} }
public void Execute(ShutdownCommand message) public void Shutdown()
{ {
_logger.Info("Shutdown requested."); _logger.Info("Shutdown requested.");
_eventAggregator.PublishEvent(new ApplicationShutdownRequested()); _eventAggregator.PublishEvent(new ApplicationShutdownRequested());
@ -42,7 +46,7 @@ namespace NzbDrone.Core.Lifecycle
} }
} }
public void Execute(RestartCommand message) public void Restart()
{ {
_logger.Info("Restart requested."); _logger.Info("Restart requested.");
@ -53,5 +57,15 @@ namespace NzbDrone.Core.Lifecycle
_serviceProvider.Restart(ServiceProvider.NZBDRONE_SERVICE_NAME); _serviceProvider.Restart(ServiceProvider.NZBDRONE_SERVICE_NAME);
} }
} }
public void Execute(ShutdownCommand message)
{
Shutdown();
}
public void Execute(RestartCommand message)
{
Restart();
}
} }
} }

@ -2,6 +2,7 @@
using System.ComponentModel; using System.ComponentModel;
using System.Windows.Forms; using System.Windows.Forms;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Processes;
using NzbDrone.Host; using NzbDrone.Host;
namespace NzbDrone.SysTray namespace NzbDrone.SysTray
@ -14,13 +15,17 @@ namespace NzbDrone.SysTray
public class SystemTrayApp : Form, ISystemTrayApp public class SystemTrayApp : Form, ISystemTrayApp
{ {
private readonly IBrowserService _browserService; private readonly IBrowserService _browserService;
private readonly IRuntimeInfo _runtimeInfo;
private readonly IProcessProvider _processProvider;
private readonly NotifyIcon _trayIcon = new NotifyIcon(); private readonly NotifyIcon _trayIcon = new NotifyIcon();
private readonly ContextMenu _trayMenu = new ContextMenu(); private readonly ContextMenu _trayMenu = new ContextMenu();
public SystemTrayApp(IBrowserService browserService) public SystemTrayApp(IBrowserService browserService, IRuntimeInfo runtimeInfo, IProcessProvider processProvider)
{ {
_browserService = browserService; _browserService = browserService;
_runtimeInfo = runtimeInfo;
_processProvider = processProvider;
} }
public void Start() public void Start()
@ -98,6 +103,11 @@ namespace NzbDrone.SysTray
private void OnApplicationExit(object sender, EventArgs e) private void OnApplicationExit(object sender, EventArgs e)
{ {
if (_runtimeInfo.RestartPending)
{
_processProvider.SpawnNewProcess(_runtimeInfo.ExecutingApplication, "--restart --nobrowser");
}
DisposeTrayIcon(); DisposeTrayIcon();
} }

@ -1,18 +1,20 @@
'use strict'; 'use strict';
define( define(
[ [
'jquery',
'backbone', 'backbone',
'marionette', 'marionette',
'System/Info/SystemInfoLayout', 'System/Info/SystemInfoLayout',
'System/Logs/LogsLayout', 'System/Logs/LogsLayout',
'System/Update/UpdateLayout', 'System/Update/UpdateLayout',
'Commands/CommandController' 'Shared/Messenger'
], function (Backbone, ], function ($,
Backbone,
Marionette, Marionette,
SystemInfoLayout, SystemInfoLayout,
LogsLayout, LogsLayout,
UpdateLayout, UpdateLayout,
CommandController) { Messenger) {
return Marionette.Layout.extend({ return Marionette.Layout.extend({
template: 'System/SystemLayoutTemplate', template: 'System/SystemLayoutTemplate',
@ -90,14 +92,26 @@ define(
}, },
_shutdown: function () { _shutdown: function () {
CommandController.Execute('shutdown', { $.ajax({
name : 'shutdown' url: window.NzbDrone.ApiRoot + '/system/shutdown',
type: 'POST'
});
Messenger.show({
message: 'NzbDrone will shutdown shortly',
type: 'info'
}); });
}, },
_restart: function () { _restart: function () {
CommandController.Execute('restart', { $.ajax({
name : 'restart' url: window.NzbDrone.ApiRoot + '/system/restart',
type: 'POST'
});
Messenger.show({
message: 'NzbDrone will restart shortly',
type: 'info'
}); });
} }
}); });

Loading…
Cancel
Save