mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-25 22:17:51 +01:00
Allows changing remote port without full restart
This commit is contained in:
@@ -388,6 +388,9 @@ namespace TGS.CommandLine
|
||||
OutputProc(res);
|
||||
return ExitCode.ServerError;
|
||||
}
|
||||
|
||||
Interface.Dispose(); //close the channels to prevent holding the service open
|
||||
|
||||
OutputProc("Change will be applied after service restart");
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
|
||||
@@ -453,48 +453,12 @@ namespace TGS.Interface
|
||||
}
|
||||
}
|
||||
|
||||
#region IDisposable Support
|
||||
/// <summary>
|
||||
/// To detect redundant <see cref="Dispose(bool)"/> calls
|
||||
/// </summary>
|
||||
private bool disposedValue = false;
|
||||
|
||||
/// <summary>
|
||||
/// Implements the <see cref="IDisposable"/> pattern. Calls <see cref="CloseAllChannels"/>
|
||||
/// </summary>
|
||||
/// <param name="disposing"><see langword="true"/> if <see cref="Dispose()"/> was called manually, <see langword="false"/> if it was from the finalizer</param>
|
||||
void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
CloseAllChannels(true);
|
||||
}
|
||||
|
||||
// TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
|
||||
// TODO: set large fields to null.
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources.
|
||||
// ~Interface() {
|
||||
// // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
|
||||
// Dispose(false);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Implements the <see cref="IDisposable"/> pattern
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
|
||||
Dispose(true);
|
||||
// TODO: uncomment the following line if the finalizer is overridden above.
|
||||
// GC.SuppressFinalize(this);
|
||||
CloseAllChannels(true);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,5 +331,9 @@ namespace TGS.Server
|
||||
/// Warning: When a testmerge commit failed to be published
|
||||
/// </summary>
|
||||
ReferencePush = 7700,
|
||||
/// <summary>
|
||||
/// Error: When restarting the root service host and an unrecoverable error was encountered
|
||||
/// </summary>
|
||||
RootHostRestartFailure = 7800,
|
||||
}
|
||||
}
|
||||
|
||||
+22
-2
@@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security.Principal;
|
||||
using System.ServiceModel;
|
||||
using System.Threading.Tasks;
|
||||
using TGS.Interface;
|
||||
using TGS.Interface.Components;
|
||||
|
||||
@@ -104,6 +104,25 @@ namespace TGS.Server
|
||||
OnlineAllHosts();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to reload <see cref="serviceHost"/>
|
||||
/// </summary>
|
||||
void RestartHost()
|
||||
{
|
||||
lock (this)
|
||||
try
|
||||
{
|
||||
serviceHost.Close();
|
||||
Config.Save(DefaultConfigDirectory);
|
||||
SetupService();
|
||||
serviceHost.Open();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.WriteError(String.Format("An unrecoverable error occurred while attempting to restart the root ServiceHost! Error: {0}", e.ToString()), EventID.RootHostRestartFailure, LoggingID);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enumerates configured <see cref="IInstanceConfig"/>s. Detaches those that fail to load
|
||||
/// </summary>
|
||||
@@ -359,8 +378,8 @@ namespace TGS.Server
|
||||
Logger.WriteError(e.ToString(), EventID.ServiceShutdownFail, LoggingID);
|
||||
}
|
||||
serviceHost.Close();
|
||||
Config.Save(DefaultConfigDirectory);
|
||||
}
|
||||
Config.Save(DefaultConfigDirectory);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -385,6 +404,7 @@ namespace TGS.Server
|
||||
if (port == 0)
|
||||
return "Cannot bind to port 0";
|
||||
Config.RemoteAccessPort = port;
|
||||
Task.Factory.StartNew(() => RestartHost());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user