Fix issue with appsettings installation on Windows

This commit is contained in:
Jordan Dominion
2023-07-24 23:27:40 -04:00
parent 9f0c2bccf4
commit 5fd5e83bd5
2 changed files with 60 additions and 4 deletions
@@ -1,6 +1,7 @@
namespace Tgstation.Server.Host.Service.Wix.Extensions
{
using System;
using System.IO;
using System.ServiceProcess;
using Tgstation.Server.Host.Common;
@@ -12,6 +13,12 @@
/// </summary>
public static class InstallationExtensions
{
/// <summary>
/// Package name
/// </summary>
/// <remarks>As much as I'd like to use Tgstation.Server.Common.Constants.CanonicalPackageName here, attempting to reference it makes Tgstation.Server.Migrator.Comms fail due to referencing the net2.0 version of that library. EVEN THOUGH IT'S A TRANSITIVE DEPENDENCY OF Tgstation.Server.Client!!!!! If that dead-ass tool has been removed, feel free to do this.</remarks>
const string CanonicalPackageName = "tgstation-server";
/// <summary>
/// Attempts to detach stop the existing tgstation-server service if it exists.
/// </summary>
@@ -28,9 +35,6 @@
session.Log("Begin DetachStopTgsServiceIfRunning");
ServiceController serviceController = null;
// As much as I'd like to use Tgstation.Server.Common.Constants.CanonicalPackageName here, attempting to reference it make Tgstation.Server.Migrator.Comms fail due to referencing the net2.0 version of that library. EVEN THOUGH IT'S A TRANSITIVE DEPENDENCY OF Tgstation.Server.Client!!!!!
// If that dead-ass tool has been removed, feel free to do this
const string CanonicalPackageName = "tgstation-server";
session.Log($"Searching for {CanonicalPackageName} service...");
try
{
@@ -76,5 +80,55 @@
return ActionResult.Failure;
}
}
/// <summary>
/// Attempts to copy the initial config to the production config if necessary.
/// </summary>
/// <param name="session">The installer <see cref="Session"/>.</param>
/// <returns>The <see cref="ActionResult"/> of the custom action.</returns>
[CustomAction]
public static ActionResult ApplyProductionAppsettingsIfNonExistant(Session session)
{
if (session == null)
throw new ArgumentNullException(nameof(session));
try
{
session.Log("Begin ApplyProductionAppsettingsIfNonExistant");
var programDataDirectory = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
CanonicalPackageName);
var initialAppSettingsPath = Path.Combine(programDataDirectory, "appsettings.Initial.yml");
var productionAppSettingsPath = Path.Combine(programDataDirectory, "appsettings.Production.yml");
var initialAppSettingsExists = File.Exists(initialAppSettingsPath);
var productionAppSettingsExists = File.Exists(productionAppSettingsPath);
if (productionAppSettingsExists)
session.Log("appsettings.Production.yml present");
else
session.Log("appsettings.Production.yml NOT present");
if (!initialAppSettingsExists)
session.Log("appsettings.Initial.yml NOT present!");
else
{
session.Log("appsettings.Initial.yml present");
if (!productionAppSettingsExists)
{
session.Log("Copying initial settings to production settings...");
File.Copy(initialAppSettingsPath, productionAppSettingsPath);
return ActionResult.Success;
}
}
return ActionResult.NotExecuted;
}
catch (Exception ex)
{
session.Log($"Exception in ApplyProductionAppsettingsIfNonExistant:{Environment.NewLine}{ex}");
return ActionResult.Failure;
}
}
}
}
@@ -7,6 +7,7 @@
<Binary Id="InstallerExtensionsBinary" SourceFile="$(var.Tgstation.Server.Host.Service.Wix.Extensions.TargetName).CA.dll" />
<CustomAction Id="DetachStopTgsServiceIfRunningAction" BinaryRef="InstallerExtensionsBinary" DllEntry="DetachStopTgsServiceIfRunning" Execute="deferred" />
<CustomAction Id="ApplyProductionAppsettingsIfNonExistantAction" BinaryRef="InstallerExtensionsBinary" DllEntry="ApplyProductionAppsettingsIfNonExistant" Execute="deferred" />
<CustomAction Id="RunTgsConfigure" Execute="deferred" FileRef="ServiceExecutableFile" ExeCommand="-c -p=--appsettings-base-path=[APPLICATIONDATADIRECTORY]" />
<CustomAction Id="RunTgsConfigureMariaDB" Execute="deferred" FileRef="ServiceExecutableFile" ExeCommand="-c -p=&quot;--appsettings-base-path=[APPLICATIONDATADIRECTORY] --Internal:MariaDBSetup=true --Internal:MariaDBDefaultRootPassword=\&quot;[MARIADB_PASSWORD]\&quot;&quot;" />
@@ -16,6 +17,7 @@
<InstallExecuteSequence>
<Custom Action="DetachStopTgsServiceIfRunningAction" Condition="UPGRADINGPRODUCTCODE OR REINSTALL" Before="StopServices" />
<Custom Action="ApplyProductionAppsettingsIfNonExistantAction" Condition="NOT ((NOT REMOVE~=&quot;ALL&quot;) AND (NOT PRODUCTIONAPPSETTINGSPRESENT) AND ((WIX_BOOTSTRAPPER_UILEVEL >= 4) OR (UILevel >= 4)))" Before="StartServices" />
<Custom Action="RunTgsConfigure" Before="StartServices" Condition="(NOT MARIADB_INSTALLED) AND (NOT REMOVE~=&quot;ALL&quot;) AND (NOT PRODUCTIONAPPSETTINGSPRESENT) AND ((WIX_BOOTSTRAPPER_UILEVEL >= 4) OR (UILevel >= 4))"/>
<Custom Action="RunTgsConfigureMariaDB" Before="StartServices" Condition="MARIADB_INSTALLED AND (NOT REMOVE~=&quot;ALL&quot;) AND (NOT PRODUCTIONAPPSETTINGSPRESENT) AND ((WIX_BOOTSTRAPPER_UILEVEL >= 4) OR (UILevel >= 4))"/>
<StartServices Condition="(NOT REMOVE~=&quot;ALL&quot;) AND ((WIX_BOOTSTRAPPER_UILEVEL >= 4) OR (UILevel >= 4) OR PRODUCTIONAPPSETTINGSPRESENT)"/>
@@ -79,7 +81,7 @@
<File Source="../../../../src/Tgstation.Server.Host/appsettings.yml" />
</Component>
<Component Id="ProductionAppSettingsComponent" Guid="" NeverOverwrite="yes">
<File Source="../../appsettings.Initial.yml" Name="appsettings.Production.yml">
<File Source="../../appsettings.Initial.yml">
<PermissionEx Sddl="D:PAI(A;;FA;;;SY)(A;;FA;;;BA)" />
</File>
</Component>