From d0c9273d679cfec73c10e6f863c5cf9012a3aa2f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 23 May 2015 16:44:15 -0400 Subject: install service with Emby name --- MediaBrowser.ServerApplication/App.config | 2 +- .../BackgroundService.cs | 24 +++++++++++++++++++--- .../BackgroundServiceInstaller.cs | 2 +- MediaBrowser.ServerApplication/MainStartup.cs | 7 ++++--- MediaBrowser.ServerApplication/Native/Autorun.cs | 19 +++++++++++++++-- 5 files changed, 44 insertions(+), 10 deletions(-) (limited to 'MediaBrowser.ServerApplication') diff --git a/MediaBrowser.ServerApplication/App.config b/MediaBrowser.ServerApplication/App.config index 94dd9ee73..14ce35a96 100644 --- a/MediaBrowser.ServerApplication/App.config +++ b/MediaBrowser.ServerApplication/App.config @@ -13,7 +13,7 @@ - + diff --git a/MediaBrowser.ServerApplication/BackgroundService.cs b/MediaBrowser.ServerApplication/BackgroundService.cs index 019a11e1c..da7537cd7 100644 --- a/MediaBrowser.ServerApplication/BackgroundService.cs +++ b/MediaBrowser.ServerApplication/BackgroundService.cs @@ -1,4 +1,5 @@ using MediaBrowser.Model.Logging; +using System.Linq; using System.ServiceProcess; namespace MediaBrowser.ServerApplication @@ -8,8 +9,25 @@ namespace MediaBrowser.ServerApplication /// public class BackgroundService : ServiceBase { - public static string Name = "MediaBrowser"; - public static string DisplayName = "Media Browser"; + public static string Name = "Emby"; + public static string DisplayName = "Emby Server"; + + public static string GetExistingServiceName() + { + try + { + if (ServiceController.GetServices().Any(s => s.ServiceName == "MediaBrowser")) + { + return "MediaBrowser"; + } + } + catch + { + return "MediaBrowser"; + } + + return Name; + } private readonly ILogger _logger; @@ -24,7 +42,7 @@ namespace MediaBrowser.ServerApplication CanStop = true; - ServiceName = Name; + ServiceName = GetExistingServiceName(); } /// diff --git a/MediaBrowser.ServerApplication/BackgroundServiceInstaller.cs b/MediaBrowser.ServerApplication/BackgroundServiceInstaller.cs index 15cab6c19..08c8a25b9 100644 --- a/MediaBrowser.ServerApplication/BackgroundServiceInstaller.cs +++ b/MediaBrowser.ServerApplication/BackgroundServiceInstaller.cs @@ -22,7 +22,7 @@ namespace MediaBrowser.ServerApplication DelayedAutoStart = true, - Description = "The windows background service for Media Browser Server.", + Description = "The windows background service for Emby Server.", // Will ensure the network is available ServicesDependedOn = new[] { "LanmanServer", "Tcpip" } diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index 6e8774eea..f918fc37c 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -370,7 +370,8 @@ namespace MediaBrowser.ServerApplication private static void RunServiceInstallationIfNeeded(string applicationPath) { - var ctl = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == BackgroundService.Name); + var serviceName = BackgroundService.GetExistingServiceName(); + var ctl = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == serviceName); if (ctl == null) { @@ -476,7 +477,7 @@ namespace MediaBrowser.ServerApplication // Update is there - execute update try { - var serviceName = _isRunningAsService ? BackgroundService.Name : string.Empty; + var serviceName = _isRunningAsService ? BackgroundService.GetExistingServiceName() : string.Empty; new ApplicationUpdater().UpdateApplication(appPaths, updateArchive, logger, serviceName); // And just let the app exit so it can update @@ -539,7 +540,7 @@ namespace MediaBrowser.ServerApplication private static void ShutdownWindowsService() { _logger.Info("Stopping background service"); - var service = new ServiceController(BackgroundService.Name); + var service = new ServiceController(BackgroundService.GetExistingServiceName()); service.Refresh(); diff --git a/MediaBrowser.ServerApplication/Native/Autorun.cs b/MediaBrowser.ServerApplication/Native/Autorun.cs index 593bb7955..dd2a77565 100644 --- a/MediaBrowser.ServerApplication/Native/Autorun.cs +++ b/MediaBrowser.ServerApplication/Native/Autorun.cs @@ -18,17 +18,32 @@ namespace MediaBrowser.ServerApplication.Native { var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3", "Media Browser Server.lnk"); + if (!Directory.Exists(Path.GetDirectoryName(shortcutPath))) + { + shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk"); + } + var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); + // Remove lnk from old name + try + { + fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Media Browser Server.lnk")); + } + catch + { + + } + if (autorun) { //Copy our shortut into the startup folder for this user - File.Copy(shortcutPath, Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "MBstartup.lnk"), true); + File.Copy(shortcutPath, Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"), true); } else { //Remove our shortcut from the startup folder for this user - fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "MBstartup.lnk")); + fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk")); } } } -- cgit v1.2.3 From fb48dd34870d5ef8d1d636d83af5132e26b99449 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 23 May 2015 18:01:13 -0400 Subject: support mono restarts --- MediaBrowser.Server.Mac/Main.cs | 20 ++++++++++++++++ MediaBrowser.Server.Mac/Native/BaseMonoApp.cs | 6 ++--- MediaBrowser.Server.Mac/Native/NativeApp.cs | 22 ++++++++++++++++- MediaBrowser.Server.Mono/Native/BaseMonoApp.cs | 6 ++--- MediaBrowser.Server.Mono/Native/NativeApp.cs | 20 ++++++++++++++++ MediaBrowser.Server.Mono/Program.cs | 33 +++++++++++++++++++++++++- MediaBrowser.ServerApplication/MainStartup.cs | 4 ++-- SharedVersion.cs | 2 +- 8 files changed, 102 insertions(+), 11 deletions(-) (limited to 'MediaBrowser.ServerApplication') diff --git a/MediaBrowser.Server.Mac/Main.cs b/MediaBrowser.Server.Mac/Main.cs index b4184f3b1..cffa62fae 100644 --- a/MediaBrowser.Server.Mac/Main.cs +++ b/MediaBrowser.Server.Mac/Main.cs @@ -146,6 +146,26 @@ namespace MediaBrowser.Server.Mac MenuBarIcon.Instance.Terminate (); } + public static void Restart() + { + _logger.Info("Disposing app host"); + AppHost.Dispose(); + + _logger.Info("Starting new instance"); + + var currentProcess = Process.GetCurrentProcess(); + + var args = Environment.GetCommandLineArgs() + .Select(NormalizeCommandLineArgument); + + var commandLineArgsString = string.Join(" ", args.ToArray()); + + Process.Start(currentProcess.MainModule.FileName, commandLineArgsString); + + _logger.Info("AppController.Terminate"); + MenuBarIcon.Instance.Terminate(); + } + /// /// Handles the UnhandledException event of the CurrentDomain control. /// diff --git a/MediaBrowser.Server.Mac/Native/BaseMonoApp.cs b/MediaBrowser.Server.Mac/Native/BaseMonoApp.cs index 9821f49dd..57610dfc2 100644 --- a/MediaBrowser.Server.Mac/Native/BaseMonoApp.cs +++ b/MediaBrowser.Server.Mac/Native/BaseMonoApp.cs @@ -19,16 +19,16 @@ namespace MediaBrowser.Server.Mac /// /// Restarts this instance. /// - public void Restart() + public virtual void Restart() { - + throw new NotImplementedException(); } /// /// Determines whether this instance [can self restart]. /// /// true if this instance [can self restart]; otherwise, false. - public bool CanSelfRestart + public virtual bool CanSelfRestart { get { diff --git a/MediaBrowser.Server.Mac/Native/NativeApp.cs b/MediaBrowser.Server.Mac/Native/NativeApp.cs index f7c2dd4c9..4515be051 100644 --- a/MediaBrowser.Server.Mac/Native/NativeApp.cs +++ b/MediaBrowser.Server.Mac/Native/NativeApp.cs @@ -13,7 +13,27 @@ namespace MediaBrowser.Server.Mac public override void Shutdown() { MainClass.Shutdown(); - } + } + + /// + /// Determines whether this instance [can self restart]. + /// + /// true if this instance can self restart; otherwise, false. + public override bool CanSelfRestart + { + get + { + return true; + } + } + + /// + /// Restarts this instance. + /// + public override void Restart() + { + MainClass.Restart(); + } } } diff --git a/MediaBrowser.Server.Mono/Native/BaseMonoApp.cs b/MediaBrowser.Server.Mono/Native/BaseMonoApp.cs index aea6d7367..ba96ca737 100644 --- a/MediaBrowser.Server.Mono/Native/BaseMonoApp.cs +++ b/MediaBrowser.Server.Mono/Native/BaseMonoApp.cs @@ -21,16 +21,16 @@ namespace MediaBrowser.Server.Mono.Native /// /// Restarts this instance. /// - public void Restart() + public virtual void Restart() { - + throw new NotImplementedException(); } /// /// Determines whether this instance [can self restart]. /// /// true if this instance [can self restart]; otherwise, false. - public bool CanSelfRestart + public virtual bool CanSelfRestart { get { diff --git a/MediaBrowser.Server.Mono/Native/NativeApp.cs b/MediaBrowser.Server.Mono/Native/NativeApp.cs index d92b86157..8c954ffcc 100644 --- a/MediaBrowser.Server.Mono/Native/NativeApp.cs +++ b/MediaBrowser.Server.Mono/Native/NativeApp.cs @@ -13,5 +13,25 @@ namespace MediaBrowser.Server.Mono.Native { MainClass.Shutdown(); } + + /// + /// Determines whether this instance [can self restart]. + /// + /// true if this instance can self restart; otherwise, false. + public override bool CanSelfRestart + { + get + { + return true; + } + } + + /// + /// Restarts this instance. + /// + public override void Restart() + { + MainClass.Restart(); + } } } diff --git a/MediaBrowser.Server.Mono/Program.cs b/MediaBrowser.Server.Mono/Program.cs index 10a6c6fb9..7cd80f5c9 100644 --- a/MediaBrowser.Server.Mono/Program.cs +++ b/MediaBrowser.Server.Mono/Program.cs @@ -1,4 +1,3 @@ -using System.IO; using MediaBrowser.Common.Implementations.IO; using MediaBrowser.Common.Implementations.Logging; using MediaBrowser.Model.Logging; @@ -8,6 +7,8 @@ using MediaBrowser.Server.Startup.Common; using Microsoft.Win32; using System; using System.Diagnostics; +using System.IO; +using System.Linq; using System.Net; using System.Net.Security; using System.Reflection; @@ -136,6 +137,36 @@ namespace MediaBrowser.Server.Mono { ApplicationTaskCompletionSource.SetResult (true); } + + public static void Restart() + { + _logger.Info("Disposing app host"); + _appHost.Dispose(); + + _logger.Info("Starting new instance"); + + var currentProcess = Process.GetCurrentProcess(); + + var args = Environment.GetCommandLineArgs() + .Select(NormalizeCommandLineArgument); + + var commandLineArgsString = string.Join(" ", args.ToArray()); + + Process.Start(currentProcess.MainModule.FileName, commandLineArgsString); + + _logger.Info("Calling Environment.Exit"); + Environment.Exit(0); + } + + private static string NormalizeCommandLineArgument(string arg) + { + if (arg.IndexOf(" ", StringComparison.OrdinalIgnoreCase) == -1) + { + return arg; + } + + return "\"" + arg + "\""; + } } class NoCheckCertificatePolicy : ICertificatePolicy diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index f918fc37c..968172bc3 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -516,11 +516,11 @@ namespace MediaBrowser.ServerApplication _logger.Info("Hiding server notify icon"); _serverNotifyIcon.Visible = false; - _logger.Info("Executing windows forms restart"); + _logger.Info("Starting new instance"); //Application.Restart(); Process.Start(_appHost.ServerConfigurationManager.ApplicationPaths.ApplicationPath); - _logger.Info("Calling Application.Exit"); + _logger.Info("Calling Environment.Exit"); Environment.Exit(0); } } diff --git a/SharedVersion.cs b/SharedVersion.cs index 5da02ac70..653297d70 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,4 +1,4 @@ using System.Reflection; //[assembly: AssemblyVersion("3.0.*")] -[assembly: AssemblyVersion("3.0.5621.0")] +[assembly: AssemblyVersion("3.0.5621.1")] -- cgit v1.2.3