From 6680b0adb2de5f63a8c86396c51cb53b32281dc0 Mon Sep 17 00:00:00 2001 From: John Gross Date: Sat, 31 Aug 2019 23:25:05 -0700 Subject: [PATCH 1/6] Fix services? --- Torch.Server/Program.cs | 2 +- Torch.Server/TorchService.cs | 10 ++++++---- Torch/VRageGame.cs | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Torch.Server/Program.cs b/Torch.Server/Program.cs index 3e10b1e..2e36d46 100644 --- a/Torch.Server/Program.cs +++ b/Torch.Server/Program.cs @@ -63,7 +63,7 @@ namespace Torch.Server // Breaks on Windows Server 2019 if (!new ComputerInfo().OSFullName.Contains("Server 2019") && !Environment.UserInteractive) { - using (var service = new TorchService()) + using (var service = new TorchService(args)) ServiceBase.Run(service); return; } diff --git a/Torch.Server/TorchService.cs b/Torch.Server/TorchService.cs index e33fda3..b43064e 100644 --- a/Torch.Server/TorchService.cs +++ b/Torch.Server/TorchService.cs @@ -15,9 +15,11 @@ namespace Torch.Server public const string Name = "Torch (SEDS)"; private TorchServer _server; private Initializer _initializer; + private string[] _args; - public TorchService() + public TorchService(string[] args) { + _args = args; var workingDir = new FileInfo(typeof(TorchService).Assembly.Location).Directory.ToString(); Directory.SetCurrentDirectory(workingDir); _initializer = new Initializer(workingDir); @@ -29,11 +31,11 @@ namespace Torch.Server } /// - protected override void OnStart(string[] args) + protected override void OnStart(string[] _) { - base.OnStart(args); + base.OnStart(_args); - _initializer.Initialize(args); + _initializer.Initialize(_args); _initializer.Run(); } diff --git a/Torch/VRageGame.cs b/Torch/VRageGame.cs index 0f0530f..4f95c4d 100644 --- a/Torch/VRageGame.cs +++ b/Torch/VRageGame.cs @@ -199,7 +199,8 @@ namespace Torch } MyRenderProxy.Initialize(renderer); MyRenderProfiler.SetAutocommit(false); - MyRenderProfiler.InitMemoryHack("MainEntryPoint"); + //This broke services? + //MyRenderProfiler.InitMemoryHack("MainEntryPoint"); } // Loads object builder serializers. Intuitive, right? From 5630eb14c2d2a08e426c7c496fd24dbd40c6b865 Mon Sep 17 00:00:00 2001 From: John Gross Date: Sun, 1 Sep 2019 10:22:42 -0700 Subject: [PATCH 2/6] Stop service "properly" --- Torch.Server/TorchService.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Torch.Server/TorchService.cs b/Torch.Server/TorchService.cs index b43064e..1a659b8 100644 --- a/Torch.Server/TorchService.cs +++ b/Torch.Server/TorchService.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ServiceProcess; +using System.Threading; using NLog; using Torch.API; @@ -12,8 +14,8 @@ namespace Torch.Server { class TorchService : ServiceBase { + private static readonly Logger Log = LogManager.GetCurrentClassLogger(); public const string Name = "Torch (SEDS)"; - private TorchServer _server; private Initializer _initializer; private string[] _args; @@ -42,8 +44,10 @@ namespace Torch.Server /// protected override void OnStop() { - _server.Stop(); - base.OnStop(); + var mre = new ManualResetEvent(false); + Task.Run(() => _initializer.Server.Stop()); + if (!mre.WaitOne(TimeSpan.FromMinutes(1))) + Process.GetCurrentProcess().Kill(); } } } From ca99404b42db49ff7c698595d77ce41e5bae09bc Mon Sep 17 00:00:00 2001 From: N1Ran <38772205+N1Ran@users.noreply.github.com> Date: Tue, 10 Sep 2019 17:58:50 -0400 Subject: [PATCH 3/6] Stop command countdown (#343) Hopefully this works --- Torch/Commands/TorchCommands.cs | 85 ++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/Torch/Commands/TorchCommands.cs b/Torch/Commands/TorchCommands.cs index 05c6867..f91f928 100644 --- a/Torch/Commands/TorchCommands.cs +++ b/Torch/Commands/TorchCommands.cs @@ -29,6 +29,8 @@ namespace Torch.Commands { private static bool _restartPending = false; private static bool _cancelRestart = false; + private bool _stopPending = false; + private bool _cancelStop = false; private static readonly Logger Log = LogManager.GetCurrentClassLogger(); [Command("whatsmyip")] @@ -156,7 +158,23 @@ namespace Torch.Commands [Command("stop", "Stops the server.")] public void Stop(bool save = true) { - Context.Respond("Stopping server."); + if (_stopPending) + { + Context.Respond("A stop is already pending."); + return; + } + + _stopPending = true; + Task.Run(() => + { + var countdown = StopCountdown(countdownSeconds, save).GetEnumerator(); + while (countdown.MoveNext()) + { + Thread.Sleep(1000); + } + }); + + /*Context.Respond("Stopping server."); if (save) DoSave()?.ContinueWith((a, mod) => { @@ -165,7 +183,7 @@ namespace Torch.Commands torch.Stop(); }, this, TaskContinuationOptions.RunContinuationsAsynchronously); else - Context.Torch.Stop(); + Context.Torch.Stop();*/ } [Command("restart", "Restarts the server.")] @@ -204,6 +222,69 @@ namespace Torch.Commands else Context.Respond("A restart is not pending."); } + + [Command("stop cancel", "Cancel a pending stop.")] + public void CancelStop() + { + if (_restartPending) + _cancelStop = true; + else + Context.Respond("Server Stop is not pending."); + } + + private IEnumerable StopCountdown(int countdown, bool save) + { + for (var i = countdown; i >= 0; i--) + { + if (_cancelStop) + { + Context.Torch.CurrentSession.Managers.GetManager() + .SendMessageAsSelf($"Stop cancelled."); + + _stopPending = false; + _cancelStop = false; + yield break; + } + + if (i >= 60 && i % 60 == 0) + { + Context.Torch.CurrentSession.Managers.GetManager() + .SendMessageAsSelf($"Stopping server in {i / 60} minute{Pluralize(i / 60)}."); + yield return null; + } + else if (i > 0) + { + if (i < 11) + Context.Torch.CurrentSession.Managers.GetManager() + .SendMessageAsSelf($"Stopping server in {i} second{Pluralize(i)}."); + yield return null; + } + else + { + if (save) + { + Log.Info("Saving game before stop."); + Context.Torch.CurrentSession.Managers.GetManager() + .SendMessageAsSelf($"Saving game before stop."); + DoSave()?.ContinueWith((a, mod) => + { + ITorchBase torch = (mod as CommandModule)?.Context?.Torch; + Debug.Assert(torch != null); + torch.Stop(); + }, this, TaskContinuationOptions.RunContinuationsAsynchronously); + + } + else + { + Log.Info("Stopping server."); + Context.Torch.Invoke(() => Context.Torch.Stop()); + } + + + yield break; + } + } + } private IEnumerable RestartCountdown(int countdown, bool save) { From d661c893d5783a5aef4ebdf4811dc652e259df58 Mon Sep 17 00:00:00 2001 From: Brant Martin Date: Tue, 10 Sep 2019 18:17:45 -0400 Subject: [PATCH 4/6] Fix a dumb --- Torch/Commands/TorchCommands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Torch/Commands/TorchCommands.cs b/Torch/Commands/TorchCommands.cs index f91f928..6dd3959 100644 --- a/Torch/Commands/TorchCommands.cs +++ b/Torch/Commands/TorchCommands.cs @@ -156,7 +156,7 @@ namespace Torch.Commands } [Command("stop", "Stops the server.")] - public void Stop(bool save = true) + public void Stop(bool save = true, int countdownSeconds = 0) { if (_stopPending) { From 79368aa6ddd05071fab28f3aaccf3673188f33f7 Mon Sep 17 00:00:00 2001 From: John Gross Date: Fri, 13 Sep 2019 11:46:35 -0700 Subject: [PATCH 5/6] Fix MessageBox spam if Torch crashes with UI enabled and autorestart disabled --- Torch.Server/Initializer.cs | 1 + Torch.Server/TorchServer.cs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Torch.Server/Initializer.cs b/Torch.Server/Initializer.cs index e152373..7dfa5b9 100644 --- a/Torch.Server/Initializer.cs +++ b/Torch.Server/Initializer.cs @@ -245,6 +245,7 @@ quit"; private void HandleException(object sender, UnhandledExceptionEventArgs e) { + _server.FatalException = true; var ex = (Exception)e.ExceptionObject; LogException(ex); if (MyFakes.ENABLE_MINIDUMP_SENDING) diff --git a/Torch.Server/TorchServer.cs b/Torch.Server/TorchServer.cs index 503a277..389e2f8 100644 --- a/Torch.Server/TorchServer.cs +++ b/Torch.Server/TorchServer.cs @@ -49,6 +49,8 @@ namespace Torch.Server private Timer _watchdog; private int _players; private MultiplayerManagerDedicated _multiplayerManagerDedicated; + + internal bool FatalException { get; set; } /// public TorchServer(TorchConfig config = null) @@ -232,10 +234,16 @@ namespace Torch.Server private static void CheckServerResponding(object state) { + var server = (TorchServer)state; var mre = new ManualResetEvent(false); - ((TorchServer)state).Invoke(() => mre.Set()); + server.Invoke(() => mre.Set()); if (!mre.WaitOne(TimeSpan.FromSeconds(Instance.Config.TickTimeout))) { + if (server.FatalException) + { + server._watchdog.Dispose(); + return; + } #if DEBUG Log.Error( $"Server watchdog detected that the server was frozen for at least {((TorchServer) state).Config.TickTimeout} seconds."); From dbcd6969364577e8bf1bff314ca05b4745b1dadb Mon Sep 17 00:00:00 2001 From: Jimmacle Date: Thu, 19 Sep 2019 11:10:52 -0700 Subject: [PATCH 6/6] How did this get here --- Jenkins/jenkins-grab-se.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkins/jenkins-grab-se.ps1 b/Jenkins/jenkins-grab-se.ps1 index 5699e3d..f94193c 100644 --- a/Jenkins/jenkins-grab-se.ps1 +++ b/Jenkins/jenkins-grab-se.ps1 @@ -17,6 +17,6 @@ if (!(Test-Path $steamCMDPath)) { } cd "$steamData" -& "$steamCMDPath/steamcmd.exe" "+login anonymous" "+force_install_dir $steamData" "+app_update 298740 -beta publictest -betapassword nt8WuDw9kdvE validate" "+quit" +& "$steamCMDPath/steamcmd.exe" "+login anonymous" "+force_install_dir $steamData" "+app_update 298740 validate" "+quit" popd