Merge pull request #1828 from tgstation/1826-TopicPortConfig [APIDeploy][NugetDeploy]

Adds OpenDream topic port as a DreamDaemon option
This commit is contained in:
Jordan Dominion
2024-07-21 05:35:02 -04:00
committed by GitHub
26 changed files with 4617 additions and 23 deletions
+4 -4
View File
@@ -3,12 +3,12 @@
<!-- Integration tests will ensure they match across the board -->
<Import Project="WebpanelVersion.props" />
<PropertyGroup>
<TgsCoreVersion>6.6.1</TgsCoreVersion>
<TgsCoreVersion>6.7.0</TgsCoreVersion>
<TgsConfigVersion>5.1.0</TgsConfigVersion>
<TgsApiVersion>10.4.0</TgsApiVersion>
<TgsApiVersion>10.5.0</TgsApiVersion>
<TgsCommonLibraryVersion>7.0.0</TgsCommonLibraryVersion>
<TgsApiLibraryVersion>13.4.0</TgsApiLibraryVersion>
<TgsClientVersion>15.4.0</TgsClientVersion>
<TgsApiLibraryVersion>13.5.0</TgsApiLibraryVersion>
<TgsClientVersion>15.5.0</TgsClientVersion>
<TgsDmapiVersion>7.1.2</TgsDmapiVersion>
<TgsInteropVersion>5.9.0</TgsInteropVersion>
<TgsHostWatchdogVersion>1.4.1</TgsHostWatchdogVersion>
@@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"wix": {
"version": "4.0.4",
"version": "5.0.1",
"commands": [
"wix"
]
@@ -1,4 +1,4 @@
<Project Sdk="WixToolset.Sdk/4.0.4" xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Project Sdk="WixToolset.Sdk/5.0.1" xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Import Project="../../../Common.props" />
<PropertyGroup>
<DefineConstants>ProductVersion=$(TgsCoreVersion);NetMajorVersion=$(TgsNetMajorVersion);DotnetRedistUrl=$(TgsDotnetRedistUrl);MariaDBRedistUrl=https://github.com/tgstation/tgstation-server/releases/download/tgstation-server-v$(TgsCoreVersion)/mariadb-$(TgsMariaDBRedistVersion)-winx64.msi</DefineConstants>
@@ -24,8 +24,8 @@
<Content Include="Theme.xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="WixToolset.Bal.wixext" Version="4.0.4" />
<PackageReference Include="WixToolset.Netfx.wixext" Version="4.0.4" />
<PackageReference Include="WixToolset.Bal.wixext" Version="5.0.1" />
<PackageReference Include="WixToolset.Netfx.wixext" Version="5.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tgstation.Server.Host.Service.Wix\Tgstation.Server.Host.Service.Wix.wixproj" />
@@ -1,4 +1,4 @@
<Project Sdk="WixToolset.Sdk/4.0.4">
<Project Sdk="WixToolset.Sdk/5.0.1">
<Import Project="../../../Common.props" />
<PropertyGroup>
<DefineConstants>ProductVersion=$(TgsCoreVersion)</DefineConstants>
@@ -25,8 +25,8 @@
</HarvestDirectory>
</ItemGroup>
<ItemGroup>
<PackageReference Include="WixToolset.Heat" Version="4.0.4" />
<PackageReference Include="WixToolset.Util.wixext" Version="4.0.4" />
<PackageReference Include="WixToolset.Heat" Version="5.0.1" />
<PackageReference Include="WixToolset.Util.wixext" Version="5.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tgstation.Server.Host.Service.Wix.Extensions\Tgstation.Server.Host.Service.Wix.Extensions.csproj" />
@@ -46,6 +46,13 @@ namespace Tgstation.Server.Api.Models.Internal
[Range(1, UInt16.MaxValue)]
public ushort? Port { get; set; }
/// <summary>
/// The port used by <see cref="EngineType.OpenDream"/> for its topic port.
/// </summary>
[Required]
[ResponseOptions]
public ushort? OpenDreamTopicPort { get; set; }
/// <summary>
/// The DreamDaemon startup timeout in seconds.
/// </summary>
@@ -109,8 +116,9 @@ namespace Tgstation.Server.Api.Models.Internal
/// Check if we match a given set of <paramref name="otherParameters"/>. <see cref="StartupTimeout"/> is excluded.
/// </summary>
/// <param name="otherParameters">The <see cref="DreamDaemonLaunchParameters"/> to compare against.</param>
/// <param name="engineType">The <see cref="EngineType"/> currently running.</param>
/// <returns><see langword="true"/> if they match, <see langword="false"/> otherwise.</returns>
public bool CanApplyWithoutReboot(DreamDaemonLaunchParameters otherParameters)
public bool CanApplyWithoutReboot(DreamDaemonLaunchParameters otherParameters, EngineType engineType)
{
if (otherParameters == null)
throw new ArgumentNullException(nameof(otherParameters));
@@ -119,6 +127,7 @@ namespace Tgstation.Server.Api.Models.Internal
&& SecurityLevel == otherParameters.SecurityLevel
&& Visibility == otherParameters.Visibility
&& Port == otherParameters.Port
&& (OpenDreamTopicPort == otherParameters.OpenDreamTopicPort || engineType != EngineType.OpenDream)
&& TopicRequestTimeout == otherParameters.TopicRequestTimeout
&& AdditionalParameters == otherParameters.AdditionalParameters
&& StartProfiler == otherParameters.StartProfiler
@@ -48,6 +48,12 @@ namespace Tgstation.Server.Api.Models.Response
[ResponseOptions]
public ushort? CurrentPort { get; set; }
/// <summary>
/// The <see cref="EngineType.OpenDream"/> topic port the running <see cref="DreamDaemonResponse"/> instance is set to.
/// </summary>
[ResponseOptions]
public ushort? CurrentTopicPort { get; set; }
/// <summary>
/// The webclient status the running <see cref="DreamDaemonResponse"/> instance is set to.
/// </summary>
@@ -785,6 +785,7 @@ namespace Tgstation.Server.Host.Components.Deployment
{
AllowWebClient = false,
Port = portToUse,
OpenDreamTopicPort = 0,
SecurityLevel = securityLevel,
Visibility = DreamDaemonVisibility.Invisible,
StartupTimeout = timeout,
@@ -107,7 +107,7 @@ namespace Tgstation.Server.Host.Components.Engine
var parametersString = EncodeParameters(parameters, launchParameters);
var arguments = $"--cvar {(logFilePath != null ? $"log.path=\"{InstallationIOManager.GetDirectoryName(logFilePath)}\" --cvar log.format=\"{InstallationIOManager.GetFileName(logFilePath)}\"" : "log.enabled=false")} --cvar watchdog.token={accessIdentifier} --cvar log.runtimelog=false --cvar net.port={launchParameters.Port!.Value} --cvar opendream.topic_port=0 --cvar opendream.world_params=\"{parametersString}\" --cvar opendream.json_path=\"./{dmbProvider.DmbName}\"";
var arguments = $"--cvar {(logFilePath != null ? $"log.path=\"{InstallationIOManager.GetDirectoryName(logFilePath)}\" --cvar log.format=\"{InstallationIOManager.GetFileName(logFilePath)}\"" : "log.enabled=false")} --cvar watchdog.token={accessIdentifier} --cvar log.runtimelog=false --cvar net.port={launchParameters.Port!.Value} --cvar opendream.topic_port={launchParameters.OpenDreamTopicPort!.Value} --cvar opendream.world_params=\"{parametersString}\" --cvar opendream.json_path=\"./{dmbProvider.DmbName}\"";
return arguments;
}
@@ -272,8 +272,13 @@ namespace Tgstation.Server.Host.Components.Watchdog
{
using (await SemaphoreSlimContext.Lock(synchronizationSemaphore, cancellationToken))
{
bool match = launchParameters.CanApplyWithoutReboot(ActiveLaunchParameters);
var currentLaunchParameters = ActiveLaunchParameters;
ActiveLaunchParameters = launchParameters;
var currentEngine = GetActiveController()?.EngineVersion.Engine;
if (!currentEngine.HasValue)
return false;
bool match = launchParameters.CanApplyWithoutReboot(currentLaunchParameters, currentEngine.Value);
if (match || Status == WatchdogStatus.Offline || Status == WatchdogStatus.DelayedRestart)
return false;
@@ -211,6 +211,7 @@ namespace Tgstation.Server.Host.Controllers
if (CheckModified(x => x.AllowWebClient, DreamDaemonRights.SetWebClient)
|| CheckModified(x => x.AutoStart, DreamDaemonRights.SetAutoStart)
|| CheckModified(x => x.Port, DreamDaemonRights.SetPort)
|| CheckModified(x => x.OpenDreamTopicPort, DreamDaemonRights.SetPort)
|| CheckModified(x => x.SecurityLevel, DreamDaemonRights.SetSecurity)
|| CheckModified(x => x.Visibility, DreamDaemonRights.SetVisibility)
|| (model.SoftRestart.HasValue && !ddRights.HasFlag(DreamDaemonRights.SoftRestart))
@@ -344,10 +345,12 @@ namespace Tgstation.Server.Host.Controllers
var rstate = dd.RebootState;
result.AutoStart = settings.AutoStart!.Value;
result.CurrentPort = llp?.Port!.Value;
result.CurrentTopicPort = llp?.OpenDreamTopicPort;
result.CurrentSecurity = llp?.SecurityLevel!.Value;
result.CurrentVisibility = llp?.Visibility!.Value;
result.CurrentAllowWebclient = llp?.AllowWebClient!.Value;
result.Port = settings.Port!.Value;
result.OpenDreamTopicPort = settings.OpenDreamTopicPort;
result.AllowWebClient = settings.AllowWebClient!.Value;
var firstIteration = true;
@@ -742,6 +742,7 @@ namespace Tgstation.Server.Host.Controllers
AllowWebClient = false,
AutoStart = false,
Port = ddPort,
OpenDreamTopicPort = 0,
SecurityLevel = DreamDaemonSecurity.Safe,
Visibility = DreamDaemonVisibility.Public,
StartupTimeout = 60,
@@ -375,22 +375,22 @@ namespace Tgstation.Server.Host.Database
/// <summary>
/// Used by unit tests to remind us to setup the correct MSSQL migration downgrades.
/// </summary>
internal static readonly Type MSLatestMigration = typeof(MSAddCronAutoUpdates);
internal static readonly Type MSLatestMigration = typeof(MSAddOpenDreamTopicPort);
/// <summary>
/// Used by unit tests to remind us to setup the correct MYSQL migration downgrades.
/// </summary>
internal static readonly Type MYLatestMigration = typeof(MYAddCronAutoUpdates);
internal static readonly Type MYLatestMigration = typeof(MYAddOpenDreamTopicPort);
/// <summary>
/// Used by unit tests to remind us to setup the correct PostgresSQL migration downgrades.
/// </summary>
internal static readonly Type PGLatestMigration = typeof(PGAddCronAutoUpdates);
internal static readonly Type PGLatestMigration = typeof(PGAddOpenDreamTopicPort);
/// <summary>
/// Used by unit tests to remind us to setup the correct SQLite migration downgrades.
/// </summary>
internal static readonly Type SLLatestMigration = typeof(SLAddCronAutoUpdates);
internal static readonly Type SLLatestMigration = typeof(SLAddOpenDreamTopicPort);
/// <inheritdoc />
#pragma warning disable CA1502 // Cyclomatic complexity
@@ -419,6 +419,16 @@ namespace Tgstation.Server.Host.Database
string BadDatabaseType() => throw new ArgumentException($"Invalid DatabaseType: {currentDatabaseType}", nameof(currentDatabaseType));
if (targetVersion < new Version(6, 7, 0))
targetMigration = currentDatabaseType switch
{
DatabaseType.MySql => nameof(MSAddCronAutoUpdates),
DatabaseType.PostgresSql => nameof(PGAddCronAutoUpdates),
DatabaseType.SqlServer => nameof(MSAddCronAutoUpdates),
DatabaseType.Sqlite => nameof(SLAddCronAutoUpdates),
_ => BadDatabaseType(),
};
if (targetVersion < new Version(6, 6, 0))
targetMigration = currentDatabaseType switch
{
@@ -0,0 +1,33 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Tgstation.Server.Host.Database.Migrations
{
/// <inheritdoc />
public partial class MSAddOpenDreamTopicPort : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
ArgumentNullException.ThrowIfNull(migrationBuilder);
migrationBuilder.AddColumn<int>(
name: "OpenDreamTopicPort",
table: "DreamDaemonSettings",
type: "int",
nullable: false,
defaultValue: 0);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
ArgumentNullException.ThrowIfNull(migrationBuilder);
migrationBuilder.DropColumn(
name: "OpenDreamTopicPort",
table: "DreamDaemonSettings");
}
}
}
@@ -0,0 +1,33 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Tgstation.Server.Host.Database.Migrations
{
/// <inheritdoc />
public partial class MYAddOpenDreamTopicPort : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
ArgumentNullException.ThrowIfNull(migrationBuilder);
migrationBuilder.AddColumn<ushort>(
name: "OpenDreamTopicPort",
table: "DreamDaemonSettings",
type: "smallint unsigned",
nullable: false,
defaultValue: (ushort)0);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
ArgumentNullException.ThrowIfNull(migrationBuilder);
migrationBuilder.DropColumn(
name: "OpenDreamTopicPort",
table: "DreamDaemonSettings");
}
}
}
@@ -0,0 +1,33 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Tgstation.Server.Host.Database.Migrations
{
/// <inheritdoc />
public partial class PGAddOpenDreamTopicPort : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
ArgumentNullException.ThrowIfNull(migrationBuilder);
migrationBuilder.AddColumn<int>(
name: "OpenDreamTopicPort",
table: "DreamDaemonSettings",
type: "integer",
nullable: false,
defaultValue: 0);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
ArgumentNullException.ThrowIfNull(migrationBuilder);
migrationBuilder.DropColumn(
name: "OpenDreamTopicPort",
table: "DreamDaemonSettings");
}
}
}
@@ -0,0 +1,33 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Tgstation.Server.Host.Database.Migrations
{
/// <inheritdoc />
public partial class SLAddOpenDreamTopicPort : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
ArgumentNullException.ThrowIfNull(migrationBuilder);
migrationBuilder.AddColumn<ushort>(
name: "OpenDreamTopicPort",
table: "DreamDaemonSettings",
type: "INTEGER",
nullable: false,
defaultValue: (ushort)0);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
ArgumentNullException.ThrowIfNull(migrationBuilder);
migrationBuilder.DropColumn(
name: "OpenDreamTopicPort",
table: "DreamDaemonSettings");
}
}
}
@@ -13,7 +13,7 @@ namespace Tgstation.Server.Host.Database.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("ProductVersion", "8.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
@@ -233,6 +233,10 @@ namespace Tgstation.Server.Host.Database.Migrations
.IsRequired()
.HasColumnType("tinyint(1)");
b.Property<ushort?>("OpenDreamTopicPort")
.IsRequired()
.HasColumnType("smallint unsigned");
b.Property<ushort?>("Port")
.IsRequired()
.HasColumnType("smallint unsigned");
@@ -13,7 +13,7 @@ namespace Tgstation.Server.Host.Database.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("ProductVersion", "8.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@@ -213,6 +213,9 @@ namespace Tgstation.Server.Host.Database.Migrations
.IsRequired()
.HasColumnType("boolean");
b.Property<int>("OpenDreamTopicPort")
.HasColumnType("integer");
b.Property<int>("Port")
.HasColumnType("integer");
@@ -13,7 +13,7 @@ namespace Tgstation.Server.Host.Database.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("ProductVersion", "8.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
@@ -215,6 +215,9 @@ namespace Tgstation.Server.Host.Database.Migrations
.IsRequired()
.HasColumnType("bit");
b.Property<int>("OpenDreamTopicPort")
.HasColumnType("int");
b.Property<int>("Port")
.HasColumnType("int");
@@ -12,7 +12,7 @@ namespace Tgstation.Server.Host.Database.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
modelBuilder.HasAnnotation("ProductVersion", "8.0.7");
modelBuilder.Entity("Tgstation.Server.Host.Models.ChatBot", b =>
{
@@ -205,6 +205,10 @@ namespace Tgstation.Server.Host.Database.Migrations
.IsRequired()
.HasColumnType("INTEGER");
b.Property<ushort?>("OpenDreamTopicPort")
.IsRequired()
.HasColumnType("INTEGER");
b.Property<ushort?>("Port")
.IsRequired()
.HasColumnType("INTEGER");
@@ -40,6 +40,8 @@ using Tgstation.Server.Host.IO;
using Tgstation.Server.Host.System;
using Tgstation.Server.Host.Utils;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace Tgstation.Server.Tests.Live.Instance
{
sealed class WatchdogTest : JobsRequiredTest
@@ -136,15 +138,18 @@ namespace Tgstation.Server.Tests.Live.Instance
{
// Increase startup timeout, disable heartbeats, enable map threads because we've tested without for years
global::System.Console.WriteLine($"PORT REUSE BUG 4: Setting I-{instanceClient.Metadata.Id} DD to {ddPort}");
await instanceClient.DreamDaemon.Update(new DreamDaemonRequest
var updated = await instanceClient.DreamDaemon.Update(new DreamDaemonRequest
{
StartupTimeout = 60,
HealthCheckSeconds = 0,
Port = ddPort,
MapThreads = 2,
OpenDreamTopicPort = 47,
LogOutput = false,
AdditionalParameters = BaseAdditionalParameters
}, cancellationToken);
Assert.AreEqual<ushort?>(47, updated.OpenDreamTopicPort);
}
catch (ConflictException ex) when (ex.ErrorCode == ErrorCode.PortNotAvailable)
{
@@ -154,6 +159,13 @@ namespace Tgstation.Server.Tests.Live.Instance
// I have no idea why this happens sometimes
await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken);
}
var updated2 = await instanceClient.DreamDaemon.Update(new DreamDaemonRequest
{
OpenDreamTopicPort = 0,
}, cancellationToken);
Assert.AreEqual<ushort?>(0, updated2.OpenDreamTopicPort);
}
global::System.Console.WriteLine($"PORT REUSE BUG 4: Expect error. Setting I-{instanceClient.Metadata.Id} DD to 0");
@@ -115,6 +115,7 @@ namespace Tgstation.Server.Tests
HealthCheckSeconds = 0,
DumpOnHealthCheckRestart = false,
Port = 1447,
OpenDreamTopicPort = 0,
SecurityLevel = DreamDaemonSecurity.Safe,
Visibility = DreamDaemonVisibility.Public,
StartupTimeout = 1000,