From ed507456f61bffe1091820f419c0abe049dcecc5 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sat, 22 Jul 2023 19:41:54 -0400 Subject: [PATCH] Fix service install setting -p arg incorrectly --- src/Tgstation.Server.Host.Service/Program.cs | 115 +++++++++---------- 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/src/Tgstation.Server.Host.Service/Program.cs b/src/Tgstation.Server.Host.Service/Program.cs index 6073742252..79e589e7ff 100644 --- a/src/Tgstation.Server.Host.Service/Program.cs +++ b/src/Tgstation.Server.Host.Service/Program.cs @@ -86,64 +86,6 @@ namespace Tgstation.Server.Host.Service /// A resulting in the 's exit code. static Task Main(string[] args) => CommandLineApplication.ExecuteAsync(args); - /// - /// Runs sc.exe to either uninstall a given or install the running . - /// - /// The name of a service to uninstall. - static void InvokeSC(string serviceToUninstall) - { - using var installer = new ServiceInstaller(); - if (serviceToUninstall != null) - { - installer.Context = new InstallContext($"old-{serviceToUninstall}-uninstall.log", null); - installer.ServiceName = serviceToUninstall; - installer.Uninstall(null); - } - else - { - var fullPathToAssembly = Path.GetFullPath( - Assembly.GetExecutingAssembly().Location); - - var assemblyDirectory = Path.GetDirectoryName(fullPathToAssembly); - var assemblyNameWithoutExtension = Path.GetFileNameWithoutExtension(fullPathToAssembly); - var exePath = Path.Combine(assemblyDirectory, $"{assemblyNameWithoutExtension}.exe"); - - var programDataDirectory = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), - Server.Common.Constants.CanonicalPackageName); - - using var processInstaller = new ServiceProcessInstaller(); - processInstaller.Account = ServiceAccount.LocalSystem; - - // Mimicing Tgstation.Server.Host.Service.Wix here, which is the source of truth for this data - installer.Context = new InstallContext( - Path.Combine(programDataDirectory, $"tgs-install-{Guid.NewGuid()}.log"), - new[] - { - $"assemblypath=\"{exePath}\" -p=--appsettings-base-path={programDataDirectory}", - }); - installer.Description = $"{Server.Common.Constants.CanonicalPackageName} running as a Windows service."; - installer.DisplayName = Server.Common.Constants.CanonicalPackageName; - installer.StartType = ServiceStartMode.Automatic; - installer.ServicesDependedOn = new string[] { "Tcpip", "Dhcp", "Dnscache" }; - installer.ServiceName = ServerService.Name; - installer.Parent = processInstaller; - - var state = new ListDictionary(); - try - { - installer.Install(state); - - installer.Commit(state); - } - catch - { - installer.Rollback(state); - throw; - } - } - } - /// /// Command line handler, always runs. /// @@ -211,6 +153,63 @@ namespace Tgstation.Server.Host.Service } } + /// + /// Runs sc.exe to either uninstall a given or install the running . + /// + /// The name of a service to uninstall. + void InvokeSC(string serviceToUninstall) + { + using var installer = new ServiceInstaller(); + if (serviceToUninstall != null) + { + installer.Context = new InstallContext($"old-{serviceToUninstall}-uninstall.log", null); + installer.ServiceName = serviceToUninstall; + installer.Uninstall(null); + return; + } + + var fullPathToAssembly = Path.GetFullPath( + Assembly.GetExecutingAssembly().Location); + + var assemblyDirectory = Path.GetDirectoryName(fullPathToAssembly); + var assemblyNameWithoutExtension = Path.GetFileNameWithoutExtension(fullPathToAssembly); + var exePath = Path.Combine(assemblyDirectory, $"{assemblyNameWithoutExtension}.exe"); + + var programDataDirectory = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), + Server.Common.Constants.CanonicalPackageName); + + using var processInstaller = new ServiceProcessInstaller(); + processInstaller.Account = ServiceAccount.LocalSystem; + + // Mimicing Tgstation.Server.Host.Service.Wix here, which is the source of truth for this data + installer.Context = new InstallContext( + Path.Combine(programDataDirectory, $"tgs-install-{Guid.NewGuid()}.log"), + new[] + { + $"assemblypath=\"{exePath}\"{(String.IsNullOrWhiteSpace(PassthroughArgs) ? String.Empty : $" -p=\"{PassthroughArgs}\"")}", + }); + installer.Description = $"{Server.Common.Constants.CanonicalPackageName} running as a Windows service."; + installer.DisplayName = Server.Common.Constants.CanonicalPackageName; + installer.StartType = ServiceStartMode.Automatic; + installer.ServicesDependedOn = new string[] { "Tcpip", "Dhcp", "Dnscache" }; + installer.ServiceName = ServerService.Name; + installer.Parent = processInstaller; + + var state = new ListDictionary(); + try + { + installer.Install(state); + + installer.Commit(state); + } + catch + { + installer.Rollback(state); + throw; + } + } + /// /// Attempt to install the TGS Service. ///