aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Server.Startup.Common/ApplicationHost.cs')
-rw-r--r--MediaBrowser.Server.Startup.Common/ApplicationHost.cs102
1 files changed, 72 insertions, 30 deletions
diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
index 005b38a7d..59b553ecf 100644
--- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
+++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
@@ -315,6 +315,8 @@ namespace MediaBrowser.Server.Startup.Common
/// </summary>
public override async Task RunStartupTasks()
{
+ await PerformPreInitMigrations().ConfigureAwait(false);
+
if (ServerConfigurationManager.Configuration.MigrationVersion < CleanDatabaseScheduledTask.MigrationVersion &&
ServerConfigurationManager.Configuration.IsStartupWizardCompleted)
{
@@ -325,6 +327,15 @@ namespace MediaBrowser.Server.Startup.Common
await MediaEncoder.Init().ConfigureAwait(false);
+ if (string.IsNullOrWhiteSpace(MediaEncoder.EncoderPath))
+ {
+ if (ServerConfigurationManager.Configuration.IsStartupWizardCompleted)
+ {
+ ServerConfigurationManager.Configuration.IsStartupWizardCompleted = false;
+ ServerConfigurationManager.SaveConfiguration();
+ }
+ }
+
Logger.Info("ServerId: {0}", SystemId);
Logger.Info("Core startup complete");
HttpServer.GlobalResponse = null;
@@ -336,6 +347,7 @@ namespace MediaBrowser.Server.Startup.Common
{
var name = entryPoint.GetType().FullName;
Logger.Info("Starting entry point {0}", name);
+ var now = DateTime.UtcNow;
try
{
entryPoint.Run();
@@ -344,7 +356,7 @@ namespace MediaBrowser.Server.Startup.Common
{
Logger.ErrorException("Error in {0}", ex, name);
}
- Logger.Info("Entry point completed: {0}", name);
+ Logger.Info("Entry point completed: {0}. Duration: {1} seconds", name, (DateTime.UtcNow - now).TotalSeconds.ToString(CultureInfo.InvariantCulture));
}
Logger.Info("All entry points have started");
@@ -356,20 +368,21 @@ namespace MediaBrowser.Server.Startup.Common
HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber;
HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber;
- PerformPreInitMigrations();
-
return base.Init(progress);
}
- private void PerformPreInitMigrations()
+ private async Task PerformPreInitMigrations()
{
- var migrations = new List<IVersionMigration>();
+ var migrations = new List<IVersionMigration>
+ {
+ new UpdateLevelMigration(ServerConfigurationManager, this, HttpClient, JsonSerializer, _releaseAssetFilename, Logger)
+ };
foreach (var task in migrations)
{
try
{
- task.Run();
+ await task.Run().ConfigureAwait(false);
}
catch (Exception ex)
{
@@ -383,8 +396,7 @@ namespace MediaBrowser.Server.Startup.Common
var migrations = new List<IVersionMigration>
{
new MovieDbEpisodeProviderMigration(ServerConfigurationManager),
- new DbMigration(ServerConfigurationManager, TaskManager),
- new UpdateLevelMigration(ServerConfigurationManager, this, HttpClient, JsonSerializer, _releaseAssetFilename)
+ new DbMigration(ServerConfigurationManager, TaskManager)
};
foreach (var task in migrations)
@@ -519,7 +531,7 @@ namespace MediaBrowser.Server.Startup.Common
PlaylistManager = new PlaylistManager(LibraryManager, FileSystemManager, LibraryMonitor, LogManager.GetLogger("PlaylistManager"), UserManager, ProviderManager);
RegisterSingleInstance<IPlaylistManager>(PlaylistManager);
- LiveTvManager = new LiveTvManager(this, ServerConfigurationManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, TaskManager, LocalizationManager, JsonSerializer, ProviderManager, FileSystemManager);
+ LiveTvManager = new LiveTvManager(this, ServerConfigurationManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, TaskManager, LocalizationManager, JsonSerializer, ProviderManager, FileSystemManager, SecurityManager);
RegisterSingleInstance(LiveTvManager);
UserViewManager = new UserViewManager(LibraryManager, LocalizationManager, UserManager, ChannelManager, LiveTvManager, ServerConfigurationManager);
@@ -537,7 +549,7 @@ namespace MediaBrowser.Server.Startup.Common
SubtitleManager = new SubtitleManager(LogManager.GetLogger("SubtitleManager"), FileSystemManager, LibraryMonitor, LibraryManager, MediaSourceManager);
RegisterSingleInstance(SubtitleManager);
- RegisterSingleInstance<IDeviceDiscovery>(new DeviceDiscovery(LogManager.GetLogger("IDeviceDiscovery"), ServerConfigurationManager, this, NetworkManager));
+ RegisterSingleInstance<IDeviceDiscovery>(new DeviceDiscovery(LogManager.GetLogger("IDeviceDiscovery"), ServerConfigurationManager));
ChapterManager = new ChapterManager(LibraryManager, LogManager.GetLogger("ChapterManager"), ServerConfigurationManager, ItemRepository);
RegisterSingleInstance(ChapterManager);
@@ -548,14 +560,10 @@ namespace MediaBrowser.Server.Startup.Common
EncodingManager = new EncodingManager(FileSystemManager, Logger, MediaEncoder, ChapterManager, LibraryManager);
RegisterSingleInstance(EncodingManager);
- RegisterSingleInstance(NativeApp.GetPowerManagement());
-
var sharingRepo = new SharingRepository(LogManager, ApplicationPaths, NativeApp.GetDbConnector());
await sharingRepo.Initialize().ConfigureAwait(false);
RegisterSingleInstance<ISharingManager>(new SharingManager(sharingRepo, ServerConfigurationManager, LibraryManager, this));
- RegisterSingleInstance<ISsdpHandler>(new SsdpHandler(LogManager.GetLogger("SsdpHandler"), ServerConfigurationManager, this));
-
var activityLogRepo = await GetActivityLogRepository().ConfigureAwait(false);
RegisterSingleInstance(activityLogRepo);
RegisterSingleInstance<IActivityManager>(new ActivityManager(LogManager.GetLogger("ActivityManager"), activityLogRepo, UserManager));
@@ -772,7 +780,19 @@ namespace MediaBrowser.Server.Startup.Common
/// </summary>
protected override void FindParts()
{
- if (!ServerConfigurationManager.Configuration.IsPortAuthorized)
+ var isAuthorized = ServerConfigurationManager.Configuration.IsPortAuthorized;
+ if (isAuthorized)
+ {
+ try
+ {
+ isAuthorized = !NativeApp.PortsRequireAuthorization(ConfigurationManager.CommonApplicationPaths.ApplicationPath);
+ }
+ catch
+ {
+
+ }
+ }
+ if (!isAuthorized)
{
RegisterServerWithAdministratorAccess();
ServerConfigurationManager.Configuration.IsPortAuthorized = true;
@@ -830,12 +850,12 @@ namespace MediaBrowser.Server.Startup.Common
{
var prefixes = new List<string>
{
- "http://"+i+":" + ServerConfigurationManager.Configuration.HttpServerPortNumber + "/"
+ "http://"+i+":" + HttpPort + "/"
};
if (!string.IsNullOrWhiteSpace(CertificatePath))
{
- prefixes.Add("https://" + i + ":" + ServerConfigurationManager.Configuration.HttpsPortNumber + "/");
+ prefixes.Add("https://" + i + ":" + HttpsPort + "/");
}
return prefixes;
@@ -852,6 +872,23 @@ namespace MediaBrowser.Server.Startup.Common
try
{
ServerManager.Start(GetUrlPrefixes(), CertificatePath);
+ return;
+ }
+ catch (Exception ex)
+ {
+ Logger.ErrorException("Error starting http server", ex);
+
+ if (HttpPort == 8096)
+ {
+ throw;
+ }
+ }
+
+ HttpPort = 8096;
+
+ try
+ {
+ ServerManager.Start(GetUrlPrefixes(), CertificatePath);
}
catch (Exception ex)
{
@@ -1095,7 +1132,8 @@ namespace MediaBrowser.Server.Startup.Common
LocalAddress = localAddress,
SupportsLibraryMonitor = SupportsLibraryMonitor,
EncoderLocationType = MediaEncoder.EncoderLocationType,
- SystemArchitecture = NativeApp.Environment.SystemArchitecture
+ SystemArchitecture = NativeApp.Environment.SystemArchitecture,
+ SystemUpdateLevel = ConfigurationManager.CommonConfiguration.SystemUpdateLevel
};
}
@@ -1153,20 +1191,24 @@ namespace MediaBrowser.Server.Startup.Common
public async Task<List<IPAddress>> GetLocalIpAddresses()
{
- var localAddresses = NetworkManager.GetLocalIpAddresses()
- .Where(IsIpAddressValid)
- .ToList();
+ var addresses = NetworkManager.GetLocalIpAddresses().ToList();
+ var list = new List<IPAddress>();
+
+ foreach (var address in addresses)
+ {
+ var valid = await IsIpAddressValidAsync(address).ConfigureAwait(false);
+ if (valid)
+ {
+ list.Add(address);
+ }
+ }
- return localAddresses;
+ return list;
}
private readonly ConcurrentDictionary<string, bool> _validAddressResults = new ConcurrentDictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
private DateTime _lastAddressCacheClear;
- private bool IsIpAddressValid(IPAddress address)
- {
- return IsIpAddressValidInternal(address).Result;
- }
- private async Task<bool> IsIpAddressValidInternal(IPAddress address)
+ private async Task<bool> IsIpAddressValidAsync(IPAddress address)
{
if (IPAddress.IsLoopback(address))
{
@@ -1176,7 +1218,7 @@ namespace MediaBrowser.Server.Startup.Common
var apiUrl = GetLocalApiUrl(address);
apiUrl += "/system/ping";
- if ((DateTime.UtcNow - _lastAddressCacheClear).TotalMinutes >= 5)
+ if ((DateTime.UtcNow - _lastAddressCacheClear).TotalMinutes >= 10)
{
_lastAddressCacheClear = DateTime.UtcNow;
_validAddressResults.Clear();
@@ -1329,8 +1371,8 @@ namespace MediaBrowser.Server.Startup.Common
cacheLength = TimeSpan.FromMinutes(5);
}
- var result = await new GithubUpdater(HttpClient, JsonSerializer, cacheLength).CheckForUpdateResult("MediaBrowser", "Emby", ApplicationVersion, updateLevel, _releaseAssetFilename,
- "MBServer", "Mbserver.zip", cancellationToken).ConfigureAwait(false);
+ var result = await new GithubUpdater(HttpClient, JsonSerializer).CheckForUpdateResult("MediaBrowser", "Emby", ApplicationVersion, updateLevel, _releaseAssetFilename,
+ "MBServer", "Mbserver.zip", cacheLength, cancellationToken).ConfigureAwait(false);
HasUpdateAvailable = result.IsUpdateAvailable;