A common quick/temporary fix for server administrators is to check if software has crashed and restart it.
So Here's a simple console application that will do that for you. It accepts 2-3 paramaters
Usage:
ProcessRestarter <processName> <restartcommand/exe location> [interval-ms]
Example:
ProcessRestarter failware C:\servers\failware.exe 30000
The above example will check if the process 'failware' is running every 30 seconds, and if not, will start a new process at 'C:\servers\failware.exe' (so now. no need for human intervention to restart the failware app if it crashes, just check the restarters console window to see if a crash has occured)
the interval is optional and will default to 60,000ms (60 seconds)
Code:using System; using System.Diagnostics; namespace ProcessRestarter { class Program { public static void Main(string[] args) { Console.WriteLine("Process Restarter is booting..."); string processName = ""; string restartCommand = ""; int interval = 60000; if(args.Length >= 2) { processName = args[0]; restartCommand = args[1]; if(args.Length >= 3) int.TryParse(args[2],out interval); Console.WriteLine("Scanning for Process name: " + processName); Console.WriteLine("If not found, will send system command: " + restartCommand); Console.WriteLine("Scan will occur every " + interval.ToString() + "ms"); while(true) { if(Process.GetProcessesByName(processName).Length == 0) { Console.WriteLine("[" + DateTime.Now.ToString("dd/MM/yyyy") + " " + DateTime.Now.ToShortTimeString() + "] Process not found, sending restart command"); Process.Start(restartCommand); System.Threading.Thread.Sleep(2000); } System.Threading.Thread.Sleep(interval); } } else { Console.WriteLine("Not enough parameters specified.\nUsage .exe <processname> <restartcommand/exe location> [interval-ms]\nscan interval is optional and defaults to 60000 ms"); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); } } } }


Multi-Clipboard
Reply With Quote