diff --git a/TGS.CommandLine/ServiceCommands.cs b/TGS.CommandLine/ServiceCommands.cs
index 833469d0c8..8ec2cd221b 100644
--- a/TGS.CommandLine/ServiceCommands.cs
+++ b/TGS.CommandLine/ServiceCommands.cs
@@ -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;
}
diff --git a/TGS.Interface/ServerInterface.cs b/TGS.Interface/ServerInterface.cs
index e92e630e19..d1bfec48ff 100644
--- a/TGS.Interface/ServerInterface.cs
+++ b/TGS.Interface/ServerInterface.cs
@@ -453,48 +453,12 @@ namespace TGS.Interface
}
}
- #region IDisposable Support
- ///
- /// To detect redundant calls
- ///
- private bool disposedValue = false;
-
- ///
- /// Implements the pattern. Calls
- ///
- /// if was called manually, if it was from the finalizer
- 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);
- // }
-
///
/// Implements the pattern
///
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
}
}
diff --git a/TGS.Server/EventID.cs b/TGS.Server/EventID.cs
index 5fd0a44696..e021b1112c 100644
--- a/TGS.Server/EventID.cs
+++ b/TGS.Server/EventID.cs
@@ -331,5 +331,9 @@ namespace TGS.Server
/// Warning: When a testmerge commit failed to be published
///
ReferencePush = 7700,
+ ///
+ /// Error: When restarting the root service host and an unrecoverable error was encountered
+ ///
+ RootHostRestartFailure = 7800,
}
}
diff --git a/TGS.Server/Server.cs b/TGS.Server/Server.cs
index b500bf3fa0..3e7e0d8138 100644
--- a/TGS.Server/Server.cs
+++ b/TGS.Server/Server.cs
@@ -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();
}
+ ///
+ /// Attempts to reload
+ ///
+ 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);
+ }
+ }
+
///
/// Enumerates configured s. Detaches those that fail to load
///
@@ -359,8 +378,8 @@ namespace TGS.Server
Logger.WriteError(e.ToString(), EventID.ServiceShutdownFail, LoggingID);
}
serviceHost.Close();
+ Config.Save(DefaultConfigDirectory);
}
- Config.Save(DefaultConfigDirectory);
}
///
@@ -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;
}