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.Core.Configuration;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Lifecycle.Commands;
namespace NzbDrone.Api.System
{
@ -15,12 +17,14 @@ namespace NzbDrone.Api.System
private readonly IRouteCacheProvider _routeCacheProvider;
private readonly IConfigFileProvider _configFileProvider;
private readonly IDatabase _database;
private readonly ILifecycleService _lifecycleService;
public SystemModule(IAppFolderInfo appFolderInfo,
IRuntimeInfo runtimeInfo,
IRouteCacheProvider routeCacheProvider,
IConfigFileProvider configFileProvider,
IDatabase database)
IDatabase database,
ILifecycleService lifecycleService)
: base("system")
{
_appFolderInfo = appFolderInfo;
@ -28,8 +32,11 @@ namespace NzbDrone.Api.System
_routeCacheProvider = routeCacheProvider;
_configFileProvider = configFileProvider;
_database = database;
_lifecycleService = lifecycleService;
Get["/status"] = x => GetStatus();
Get["/routes"] = x => GetRoutes();
Post["/shutdown"] = x => Shutdown();
Post["/restart"] = x => Restart();
}
private Response GetStatus()
@ -62,5 +69,18 @@ namespace NzbDrone.Api.System
{
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.EnvironmentInfo;
using NzbDrone.Common.Processes;
@ -9,40 +10,43 @@ using IServiceProvider = NzbDrone.Common.IServiceProvider;
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 IRuntimeInfo _runtimeInfo;
private readonly IServiceProvider _serviceProvider;
private readonly IProcessProvider _processProvider;
private readonly Logger _logger;
public LifecycleService(IEventAggregator eventAggregator,
IRuntimeInfo runtimeInfo,
IServiceProvider serviceProvider,
IProcessProvider processProvider,
Logger logger)
{
_eventAggregator = eventAggregator;
_runtimeInfo = runtimeInfo;
_serviceProvider = serviceProvider;
_processProvider = processProvider;
_logger = logger;
}
public void Execute(ShutdownCommand message)
public void Shutdown()
{
_logger.Info("Shutdown requested.");
_eventAggregator.PublishEvent(new ApplicationShutdownRequested());
if (_runtimeInfo.IsWindowsService)
{
_serviceProvider.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME);
}
}
public void Execute(RestartCommand message)
public void Restart()
{
_logger.Info("Restart requested.");
@ -53,5 +57,15 @@ namespace NzbDrone.Core.Lifecycle
_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.Windows.Forms;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Processes;
using NzbDrone.Host;
namespace NzbDrone.SysTray
@ -14,13 +15,17 @@ namespace NzbDrone.SysTray
public class SystemTrayApp : Form, ISystemTrayApp
{
private readonly IBrowserService _browserService;
private readonly IRuntimeInfo _runtimeInfo;
private readonly IProcessProvider _processProvider;
private readonly NotifyIcon _trayIcon = new NotifyIcon();
private readonly ContextMenu _trayMenu = new ContextMenu();
public SystemTrayApp(IBrowserService browserService)
public SystemTrayApp(IBrowserService browserService, IRuntimeInfo runtimeInfo, IProcessProvider processProvider)
{
_browserService = browserService;
_runtimeInfo = runtimeInfo;
_processProvider = processProvider;
}
public void Start()
@ -98,6 +103,11 @@ namespace NzbDrone.SysTray
private void OnApplicationExit(object sender, EventArgs e)
{
if (_runtimeInfo.RestartPending)
{
_processProvider.SpawnNewProcess(_runtimeInfo.ExecutingApplication, "--restart --nobrowser");
}
DisposeTrayIcon();
}

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

Loading…
Cancel
Save