Re-add shutdown/restart methods

This commit is contained in:
Patrick Barron 2023-10-02 15:55:26 -04:00
parent 59ec06c35c
commit f746db9a54
3 changed files with 36 additions and 24 deletions

View File

@ -101,6 +101,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Prometheus.DotNetRuntime; using Prometheus.DotNetRuntime;
using static MediaBrowser.Controller.Extensions.ConfigurationExtensions; using static MediaBrowser.Controller.Extensions.ConfigurationExtensions;
@ -850,6 +851,24 @@ namespace Emby.Server.Implementations
} }
} }
/// <inheritdoc />
public void Restart()
{
ShouldRestart = true;
Shutdown();
}
/// <inheritdoc />
public void Shutdown()
{
Task.Run(async () =>
{
await Task.Delay(100).ConfigureAwait(false);
IsShuttingDown = true;
Resolve<IHostApplicationLifetime>().StopApplication();
});
}
/// <summary> /// <summary>
/// Gets the composable part assemblies. /// Gets the composable part assemblies.
/// </summary> /// </summary>

View File

@ -4,7 +4,6 @@ using System.ComponentModel.DataAnnotations;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Mime; using System.Net.Mime;
using System.Threading.Tasks;
using Jellyfin.Api.Attributes; using Jellyfin.Api.Attributes;
using Jellyfin.Api.Constants; using Jellyfin.Api.Constants;
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
@ -18,7 +17,6 @@ using MediaBrowser.Model.System;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Jellyfin.Api.Controllers; namespace Jellyfin.Api.Controllers;
@ -33,7 +31,6 @@ public class SystemController : BaseJellyfinApiController
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly INetworkManager _network; private readonly INetworkManager _network;
private readonly ILogger<SystemController> _logger; private readonly ILogger<SystemController> _logger;
private readonly IHostApplicationLifetime _hostApplicationLifetime;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="SystemController"/> class. /// Initializes a new instance of the <see cref="SystemController"/> class.
@ -43,21 +40,18 @@ public class SystemController : BaseJellyfinApiController
/// <param name="fileSystem">Instance of <see cref="IFileSystem"/> interface.</param> /// <param name="fileSystem">Instance of <see cref="IFileSystem"/> interface.</param>
/// <param name="network">Instance of <see cref="INetworkManager"/> interface.</param> /// <param name="network">Instance of <see cref="INetworkManager"/> interface.</param>
/// <param name="logger">Instance of <see cref="ILogger{SystemController}"/> interface.</param> /// <param name="logger">Instance of <see cref="ILogger{SystemController}"/> interface.</param>
/// <param name="hostApplicationLifetime">Instance of <see cref="IHostApplicationLifetime"/> interface.</param>
public SystemController( public SystemController(
IServerConfigurationManager serverConfigurationManager, IServerConfigurationManager serverConfigurationManager,
IServerApplicationHost appHost, IServerApplicationHost appHost,
IFileSystem fileSystem, IFileSystem fileSystem,
INetworkManager network, INetworkManager network,
ILogger<SystemController> logger, ILogger<SystemController> logger)
IHostApplicationLifetime hostApplicationLifetime)
{ {
_appPaths = serverConfigurationManager.ApplicationPaths; _appPaths = serverConfigurationManager.ApplicationPaths;
_appHost = appHost; _appHost = appHost;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_network = network; _network = network;
_logger = logger; _logger = logger;
_hostApplicationLifetime = hostApplicationLifetime;
} }
/// <summary> /// <summary>
@ -112,13 +106,7 @@ public class SystemController : BaseJellyfinApiController
[ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status403Forbidden)]
public ActionResult RestartApplication() public ActionResult RestartApplication()
{ {
Task.Run(async () => _appHost.Restart();
{
await Task.Delay(100).ConfigureAwait(false);
_appHost.ShouldRestart = true;
_appHost.IsShuttingDown = true;
_hostApplicationLifetime.StopApplication();
});
return NoContent(); return NoContent();
} }
@ -134,12 +122,7 @@ public class SystemController : BaseJellyfinApiController
[ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status403Forbidden)]
public ActionResult ShutdownApplication() public ActionResult ShutdownApplication()
{ {
Task.Run(async () => _appHost.Shutdown();
{
await Task.Delay(100).ConfigureAwait(false);
_appHost.IsShuttingDown = true;
_hostApplicationLifetime.StopApplication();
});
return NoContent(); return NoContent();
} }

View File

@ -41,15 +41,15 @@ namespace MediaBrowser.Common
bool HasPendingRestart { get; } bool HasPendingRestart { get; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether this instance is currently shutting down. /// Gets a value indicating whether this instance is currently shutting down.
/// </summary> /// </summary>
/// <value><c>true</c> if this instance is shutting down; otherwise, <c>false</c>.</value> /// <value><c>true</c> if this instance is shutting down; otherwise, <c>false</c>.</value>
bool IsShuttingDown { get; set; } bool IsShuttingDown { get; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether the application should restart. /// Gets a value indicating whether the application should restart.
/// </summary> /// </summary>
bool ShouldRestart { get; set; } bool ShouldRestart { get; }
/// <summary> /// <summary>
/// Gets the application version. /// Gets the application version.
@ -91,6 +91,11 @@ namespace MediaBrowser.Common
/// </summary> /// </summary>
void NotifyPendingRestart(); void NotifyPendingRestart();
/// <summary>
/// Restarts this instance.
/// </summary>
void Restart();
/// <summary> /// <summary>
/// Gets the exports. /// Gets the exports.
/// </summary> /// </summary>
@ -122,6 +127,11 @@ namespace MediaBrowser.Common
/// <returns>``0.</returns> /// <returns>``0.</returns>
T Resolve<T>(); T Resolve<T>();
/// <summary>
/// Shuts down.
/// </summary>
void Shutdown();
/// <summary> /// <summary>
/// Initializes this instance. /// Initializes this instance.
/// </summary> /// </summary>