diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 9c77b8627e..e7a9c00c61 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -215,7 +215,7 @@ namespace MediaBrowser.Common.Implementations try { // Increase the max http request limit - ServicePointManager.DefaultConnectionLimit = Math.Min(48, ServicePointManager.DefaultConnectionLimit); + ServicePointManager.DefaultConnectionLimit = Math.Max(48, ServicePointManager.DefaultConnectionLimit); } catch (Exception ex) { diff --git a/MediaBrowser.Server.Implementations/WebSocket/AlchemyServer.cs b/MediaBrowser.Server.Implementations/WebSocket/AlchemyServer.cs index 251083dc28..8be35071ad 100644 --- a/MediaBrowser.Server.Implementations/WebSocket/AlchemyServer.cs +++ b/MediaBrowser.Server.Implementations/WebSocket/AlchemyServer.cs @@ -50,8 +50,6 @@ namespace MediaBrowser.Server.Implementations.WebSocket /// The port. public int Port { get; private set; } - private bool _hasStarted; - /// /// Starts the specified port number. /// @@ -69,8 +67,6 @@ namespace MediaBrowser.Server.Implementations.WebSocket }; WebSocketServer.Start(); - - _hasStarted = true; } catch (Exception ex) { @@ -141,14 +137,9 @@ namespace MediaBrowser.Server.Implementations.WebSocket { if (WebSocketServer != null) { - if (_hasStarted) - { - _logger.Debug("Stopping alchemy server"); - WebSocketServer.Stop(); - } - + // Calling dispose will also call stop _logger.Debug("Disposing alchemy server"); - WebSocketServer.Dispose(); + WebSocketServer.Stop(); WebSocketServer = null; } } diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index 577f5ea38d..e69d466613 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -26,8 +26,6 @@ namespace MediaBrowser.ServerApplication private static ILogger _logger; - private static bool _isRestarting = false; - private static bool _isRunningAsService = false; /// @@ -132,7 +130,7 @@ namespace MediaBrowser.ServerApplication if (duplicate != null) { _logger.Info("Found a duplicate process. Giving it time to exit."); - + if (!duplicate.WaitForExit(5000)) { _logger.Info("The duplicate process did not exit."); @@ -204,7 +202,7 @@ namespace MediaBrowser.ServerApplication SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT | ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX); } - + _app.Run(); } @@ -249,13 +247,6 @@ namespace MediaBrowser.ServerApplication SetErrorMode(ErrorModes.SYSTEM_DEFAULT); } - if (_isRestarting) - { - Process.Start("cmd", "/c net start " + BackgroundService.Name); - - _logger.Info("New service process started"); - } - _app.Dispatcher.Invoke(_app.Shutdown); } @@ -270,6 +261,11 @@ namespace MediaBrowser.ServerApplication { ManagedInstallerClass.InstallHelper(new[] { runningPath }); + using (var process = Process.Start("cmd.exe", "/c sc failure " + BackgroundService.Name + " reset= 0 actions= restart/1000/restart/1000/restart/60000")) + { + process.WaitForExit(); + } + logger.Info("Service installation succeeded"); } catch (Exception ex) @@ -445,15 +441,6 @@ namespace MediaBrowser.ServerApplication _logger.Info("Disposing app host"); _appHost.Dispose(); - _logger.Info("Starting new instance of server"); - RestartInternal(); - - _logger.Info("Shutting down existing instance of server."); - Shutdown(); - } - - private static void RestartInternal() - { if (!_isRunningAsService) { _logger.Info("Starting server application"); @@ -461,8 +448,8 @@ namespace MediaBrowser.ServerApplication } else { - _logger.Info("Starting windows service"); - RestartWindowsService(); + _logger.Info("Calling Enviornment.Exit to tell Windows to restart the server."); + Environment.Exit(1); } } @@ -471,11 +458,6 @@ namespace MediaBrowser.ServerApplication System.Windows.Forms.Application.Restart(); } - private static void RestartWindowsService() - { - _isRestarting = true; - } - private static void ShutdownWindowsApplication() { _app.Dispatcher.Invoke(_app.Shutdown); diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index 92c8f2c054..b7fd2a38f0 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.221 + 3.0.222 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index 3baf5d96fc..f6b3aeef85 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.221 + 3.0.222 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 147850f29e..b8227fa043 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.221 + 3.0.222 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +