Пример #1
0
        /// <summary>
        /// Check if specified server timer is already started
        /// </summary>
        /// <param name="server">Server object</param>
        /// <returns>true if timer is already registered and running</returns>
        private bool IsTimerStarted(Server server)
        {
            ServerTimer serverTimer = null;

            lock (lockServers)
                return(serverTimers.TryGetValue(server.Process.Id, out serverTimer));
        }
Пример #2
0
        /// <summary>
        /// Reset timer to default timeout
        /// </summary>
        /// <param name="server">Server object</param>
        private void ResetTimer(Server server)
        {
            ServerTimer serverTimer = null;

            lock (lockServers)
                if (serverTimers.TryGetValue(server.Process.Id, out serverTimer))
                {
                    serverTimer.ResetTimer();
                }
        }
Пример #3
0
        /// <summary>
        /// Restart server if freeze/slowness detected
        /// </summary>
        private void RestartServer(ServerTimer timer)
        {
            if (IsStopping)
            {
                return;
            }

            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(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(Server.Process.CommandLine, @"^(.*exe).*$");
                var arguments = Re.GetSubString(Server.Process.CommandLine, @"^.*?\s(.*)$");
                var directory = Server.Process.Path;
                StartProcess(exeFile, arguments, directory);
            });
        }