public static void StopServer() { CPUInformation info = CPUHelper.GetAverage(); if (info != null) { Logger.LogInfo($"Average CPU Usage over {info.secondsPassed}s. %{info.averageOverTime}"); } if (Server == null) { return; } if (!Server.HasExited) { Server.Kill(); } Server = null; }
public static void StartServer() { IniFile file = new IniFile("restarter.ini"); ServerThread = new Thread(() => { Server = Process.GetProcessesByName("RustDedicated").FirstOrDefault(); if (Server == null) { Server = new Process(); Server.StartInfo.WorkingDirectory = file.Read("ServerPath", "ServerInformation"); Server.StartInfo.FileName = file.Read("BatchFile", "ServerInformation"); Server.Start(); CPUHelper.StartCounting(); SlackManager.SendSlackMessage("Started", $"The server has successfully started at {DateTime.Now.ToString("h: mm:ss tt")}.", "Information"); Logger.LogInfo("Server Started Successfully."); } Server.WaitForExit(); SlackManager.SendSlackMessage("Shutdown", $"The server has shutdown at {DateTime.Now.ToString("h: mm:ss tt")}. Restarting.", "Information"); Logger.LogWarning("Server Shut Down - Ending task and restarting."); RestartServer(); }); ServerThread.Start(); }