private static bool IncludeDemoProcess(Process process) { var demoMode = bool.Parse(System.Configuration.ConfigurationSettings.AppSettings["DemoMode"] ?? "false"); // If process has Mode=Demo attribute and is set to true then only that process is to be run if (process.Mode == null) { return(true); } else if (process.Mode == "Demo" && demoMode) { return(true); } return(false); }
/// <summary> /// Checks health of processes that don't have heartbeat setup. Also if processes with heartbeat are hung then checks to see if those processes are dead /// </summary> /// <param name="process"></param> private void CheckForDeadProcess(Process process) { // If process doesnot have heartbeat setup if (!process.HasHeartBeat) { // Check if process is running i.e this in short means if process is showing in taskmanager if (!processManager.IsProcessRunning(process)) { Console.WriteLine(process.Name + ": Process state is Dead"); process.CurrentState = State.IsDead; } else { Console.WriteLine(process.Name + ": Process state is Happy"); process.CurrentState = State.IsHappy; } } else { // Process has heartbeat setup // Heartbeat was missed but now checking if process is running if (process.CurrentState == State.IsHung) { // Check if process is running i.e this in short means if process is showing in taskmanager if (!processManager.IsProcessRunning(process)) { Console.WriteLine(process.Name + ": Process state is Dead"); // Heartbeat missed and process is not there hence dead process.CurrentState = State.IsDead; } } } }
/// <summary> /// Steps to restart each process /// </summary> /// <param name="process"></param> private void RestartProcess(Process process) { // Wait time is configured in xml for each process. Each process can have different time to restart successfully. Default time is 30 seconds var restartTimeout = process.RestartTimeout != 0 ? process.RestartTimeout : defaultRestartTimeout; Console.WriteLine(string.Format("Stopping the process:{0}", process.Name)); var stopFailed = true; // Stop the process var returnStopCode = processManager.StopProcess(process); // Wait until process is stopped successfully var lastStopDateTime = DateTime.Now; while (DateTime.Now.Subtract(lastStopDateTime).TotalSeconds < restartTimeout) { if (processManager.IsProcessStopped(process)) { Console.WriteLine(string.Format("{0} {1}:Stopped.", process.Name, "STATE")); stopFailed = false; break; } Thread.Sleep(2000); } if (stopFailed) { Console.WriteLine(string.Format("Failed to stopped the process:{0}", process.Name)); // Fix for CR 29838: when ConnexCS became unkillable have to make upto 3 restart attempts and then reboot if needed. if (process.Type == "Application") { if (numberOfRestartAttempts < defaultNumberOfRestartAttempts) { numberOfRestartAttempts++; RestartProcess(process); } else { var nonWorkingProcesses = new List <Process> { process }; ExecuteRebootPlan(nonWorkingProcesses); } } // Abort the thread if restartFailed TerminateThread(); } Console.WriteLine(string.Format("Starting the process:{0}", process.Name)); var startFailed = true; // If process was Stopped successfully then Start the process var returnStartCode = processManager.StartProcess(process); // Wait until process is started successfully var lastStartDateTime = DateTime.Now; while (DateTime.Now.Subtract(lastStartDateTime).TotalSeconds < restartTimeout) { if (processManager.IsProcessRunning(process)) { Console.WriteLine(string.Format("{0} {1}:Running.", process.Name, "STATE")); startFailed = false; break; } Thread.Sleep(2000); } if (startFailed) { Console.WriteLine(string.Format("Failed to start the process:{0}", process.Name)); // Abort the thread if restartFailed TerminateThread(); } }