/// <summary> /// Restart server if freeze/slowness detected /// </summary> private void RestartServer(ServerTimer timer) { if (this.IsStopping) { return; } this.IsStopping = true; if (timer == null || timer.Server == null) { return; } Log.WriteInfo("Stopping frozen server {0}...", timer.Server.Name); var id = timer.With(x => x.Server).With(x => x.Process).Return(x => x.Id, 0); if (id == 0) { Log.WriteInfo("Unable to restart server {0}. Unknown process id.", timer.Server.Name); return; } Util.Try(() => { var process = Process.GetProcessById(id); if (process == null) { Log.WriteInfo("Unable to restart server {0}. Process not found.", timer.Server.Name); return; } if (string.IsNullOrWhiteSpace(this.Server.Process.CommandLine)) { Log.WriteInfo("Unable to restart a server {0}. Empty command line!", timer.Server.Name); return; } process.Kill(); }, false); Util.Try(() => { Thread.Sleep(1000); Log.WriteInfo("Starting server {0}...", timer.Server.Name); var exeFile = Re.GetSubString(this.Server.Process.CommandLine, @"^(.*exe).*$"); var arguments = Re.GetSubString(this.Server.Process.CommandLine, @"^.*?\s(.*)$"); var directory = this.Server.Process.Path; this.StartProcess(exeFile, arguments, directory); }); }