5 using System.ServiceProcess;
9 using WixToolset.Dtf.WindowsInstaller;
31 throw new ArgumentNullException(nameof(session));
35 session.Log(
"Begin DetachStopTgsServiceIfRunning");
36 ServiceController serviceController =
null;
38 session.Log($
"Searching for {CanonicalPackageName} service...");
41 foreach (var controller
in ServiceController.GetServices())
43 serviceController = controller;
47 if (serviceController ==
null || serviceController.Status != ServiceControllerStatus.Running)
49 session.Log($
"{CanonicalPackageName} service not found. Continuing.");
50 return ActionResult.Success;
57 session.Log($
"{CanonicalPackageName} service found. Sending command \"{PipeCommands.CommandDetachingShutdown}\" ({commandId})...");
59 serviceController.ExecuteCommand(commandId);
61 session.Log($
"Command sent. Waiting for {CanonicalPackageName} service to stop...");
63 serviceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMinutes(1));
65 var stopped = serviceController.Status == ServiceControllerStatus.Stopped;
66 session.Log($
"{CanonicalPackageName} stopped {(stopped ? String.Empty : "un
")}successfully.");
69 ? ActionResult.Success
70 : ActionResult.NotExecuted;
74 serviceController?.Dispose();
79 session.Log($
"Exception in DetachStopTgsServiceIfRunning:{Environment.NewLine}{ex}");
80 return ActionResult.Failure;
93 throw new ArgumentNullException(nameof(session));
97 session.Log(
"Begin ApplyProductionAppsettingsIfNonExistant");
98 var programDataDirectory = Path.Combine(
99 Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
101 var initialAppSettingsPath = Path.Combine(programDataDirectory,
"appsettings.Initial.yml");
102 var productionAppSettingsPath = Path.Combine(programDataDirectory,
"appsettings.Production.yml");
104 var initialAppSettingsExists = File.Exists(initialAppSettingsPath);
105 var productionAppSettingsExists = File.Exists(productionAppSettingsPath);
107 if (productionAppSettingsExists)
108 session.Log(
"appsettings.Production.yml present");
110 session.Log(
"appsettings.Production.yml NOT present");
112 if (!initialAppSettingsExists)
113 session.Log(
"appsettings.Initial.yml NOT present!");
116 session.Log(
"appsettings.Initial.yml present");
117 if (!productionAppSettingsExists)
119 session.Log(
"Copying initial settings to production settings...");
120 File.Copy(initialAppSettingsPath, productionAppSettingsPath);
121 return ActionResult.Success;
125 return ActionResult.NotExecuted;
129 session.Log($
"Exception in ApplyProductionAppsettingsIfNonExistant:{Environment.NewLine}{ex}");
130 return ActionResult.Failure;
Values able to be passed via the update file path.
static ? int GetServiceCommandId(string command)
Gets the int value of a given command .
const string CommandDetachingShutdown
Stops the server ASAP, detaching the watchdog for any running instances.
Extension methods for the .msi installer.
static ActionResult ApplyProductionAppsettingsIfNonExistant(Session session)
Attempts to copy the initial config to the production config if necessary.
static ActionResult DetachStopTgsServiceIfRunning(Session session)
Attempts to detach stop the existing tgstation-server service if it exists.
const string CanonicalPackageName
Package name