Compare commits

..

2 Commits

Author SHA1 Message Date
zznty
83dfc7152f properly handle sigterm and dont freeze forever on unload 2023-07-13 13:18:20 +07:00
d7e5f53e4f Fix SteamCMD args order + add quit arg 2023-07-10 01:46:28 -04:00
4 changed files with 19 additions and 6 deletions

View File

@@ -31,7 +31,7 @@ namespace Torch.Server
private const string TOOL_DIR = "tool"; private const string TOOL_DIR = "tool";
private const string TOOL_ZIP = "temp.zip"; private const string TOOL_ZIP = "temp.zip";
private static readonly string TOOL_EXE = "steamcmd.exe"; private static readonly string TOOL_EXE = "steamcmd.exe";
private const string TOOL_ARGS = "+login anonymous +app_update 298740 +force_install_dir \"{0}\""; private const string TOOL_ARGS = "+force_install_dir \"{0}\" +login anonymous +app_update 298740 +quit";
private TorchServer _server; private TorchServer _server;
internal Persistent<TorchConfig> ConfigPersistent { get; } internal Persistent<TorchConfig> ConfigPersistent { get; }
@@ -174,7 +174,7 @@ namespace Torch.Server
while (!cmd.HasExited) while (!cmd.HasExited)
{ {
if (await cmd.StandardOutput.ReadLineAsync() is { } line) if (await cmd.StandardOutput.ReadLineAsync() is { } line)
log.Info(line); //seems to hang sometimes, maybe switch back to Thread.Sleep? log.Info(line);
} }
} }
} }

View File

@@ -69,6 +69,14 @@ namespace Torch.Server
_simUpdateTimer.Elapsed += SimUpdateElapsed; _simUpdateTimer.Elapsed += SimUpdateElapsed;
_simUpdateTimer.Start(); _simUpdateTimer.Start();
Console.CancelKeyPress += (_, _) =>
{
if (State == ServerState.Running)
Stop();
Environment.Exit(0);
};
} }
private void SimUpdateElapsed(object sender, System.Timers.ElapsedEventArgs e) private void SimUpdateElapsed(object sender, System.Timers.ElapsedEventArgs e)
@@ -239,9 +247,14 @@ namespace Torch.Server
StopInternal(); StopInternal();
LogManager.Flush(); LogManager.Flush();
if (
#if DEBUG #if DEBUG
Environment.Exit(0); // ReSharper disable once ConditionIsAlwaysTrueOrFalse
true ||
#endif #endif
ApplicationContext.Current.IsService
)
Environment.Exit(0);
var exe = Path.Combine(AppContext.BaseDirectory, "Torch.Server.exe"); var exe = Path.Combine(AppContext.BaseDirectory, "Torch.Server.exe");

View File

@@ -116,7 +116,7 @@ namespace Torch.Server
if (_server?.State == ServerState.Running) if (_server?.State == ServerState.Running)
_server.Stop(); _server.Stop();
Process.GetCurrentProcess().Kill(); Environment.Exit(0);
} }
} }
} }

View File

@@ -372,10 +372,10 @@ namespace Torch
/// <inheritdoc /> /// <inheritdoc />
public virtual void Stop() public virtual void Stop()
{ {
LogManager.Flush();
Game.SignalStop(); Game.SignalStop();
if (!Game.WaitFor(VRageGame.GameState.Stopped)) if (!Game.WaitFor(VRageGame.GameState.Stopped, TimeSpan.FromSeconds(Config.TickTimeout)))
Log.Warn("Failed to wait for the game to be stopped"); Log.Warn("Failed to wait for the game to be stopped");
LogManager.Flush();
} }
/// <inheritdoc /> /// <inheritdoc />