Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need something that runs in the background as a service (Windows), watches defined process and when it crosses thresholds it restarts/stop/starts the process again? (similar functionality of rubygem called "god")

I have a network camera software that runs as a server, but it does not support running as a Windows service. It also stops responding once a day. When it does, I can see that memory drops below 10MB. Usually it is about 20-30MB in RAM.

share|improve this question

1 Answer 1

If you are familiar with C# you could try using a background worker to monitor the process and restart it when you get problems.

E.g. something similar I have (for a GUI app) looks like the below

private void startServer()
    {
        if (this.CancellationPending == true)
        {
            Console.WriteLine("Termination of {0} requested", thisServer.serverSettings.serverName);
            this.ReportProgress(100);
            this.Dispose(true);
        }
        else
        {
            try
            {
                thisServer.serverStatus = status.Starting;
                using (Process p = Process.Start(thisServer.serverStartInfo))
                {
                    thisServer.serverProc = p;
                    p.WaitForInputIdle(thisServer.serverSettings.startupDuration.Milliseconds);
                    thisServer.serverStatus = status.Running;

                    while (p.Responding)
                    {
                       // happy days
                    }

                    thisServer.serverStatus = status.Unknown;
                    try
                    {
                        p.Close();
                        thisServer.serverStatus = status.Offline;
                    }
                    catch 
                    {
                        try
                        {
                            p.Kill();
                            thisServer.serverStatus = status.Offline;
                        }
                        catch { }
                    }
                }

                reRun();
            }
            catch
            {
                thisServer.serverStatus = status.Offline;
                ReportProgress(100, "Error encountered when attempting to launch executable. Please review server settings.");
            }
        }
    }
share|improve this answer
    
I need something standalone. Not self developed. But it might work. I have my reasons. –  Ahmed Al Hafoudh Nov 4 '11 at 21:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.