views:

5937

answers:

6

I'm looking for a way to monitor certain Windows services (on Windows Server 2003) and restart if necessary. The services are on different servers and include mainly SQL Server services (e.g. SQL Server Agent), but also some proprietary services.

Email alerts sent out if a service has stopped would be very useful as well.

+3  A: 

They may be some dedicated tools out there, but I just want to point out the wmic tool.

wmic /node:[hostname] service list

is able to list the services of any computer

WMIC SERVICE where caption='TELNET' CALL STARTSERVICE

would restart the telnet service.

If you encapsulate wmic in a script language (able to send email), you can have the monitoring tool you are looking for.

VonC
+6  A: 

A "might be enough" version of this is built into Windows. Look into the "Recovery" tab of the service properties, as available via services.msc.

You can act on a service fail with:

  • "Restart the Service"
  • "Run a Progam"
  • "Restart the Computer"

"Run a program" could be a small script that sends a mail, for example.

If you want a bigger solution with an overview dashboard and all, there are plenty of system monitoring solutions available. For example SolarWinds IPMonitor comes to mind, or Nagios, or Cacti.

Tomalak
A: 

Well will you be interested in a Blade Logic product called Blade Logic Configuration Manager? Its not free but it can do a lot more than monitor windows services. Look it over. It will do everything you asked in your question and more

Colwin
+2  A: 

If you are interested in some .NET programming, The System.ServiceProcess namespace provides classes that allow you to implement, install, and control Windows service applications.

Simple example, checking and starting a service in C#:

var srv = new ServiceController("MyService");
Console.WriteLine("MyService Status {0}", srv.Status);
if (srv.Status != ServiceControllerStatus.Running)
    srv.Start();
gimel
A: 

This depends on exactly what you want to monitor:

  • A service has actually stopped as far as the Service Control Manager (SCM) is concerned.
  • A service has crashed without the SCM being aware - this is very common due to threading.
  • A service has hung without the SCM being aware - also very common.

For the first item, you can configure the service to kick-off a script that sends an email alert. Note this can be really annoying if the service keeps rebooting due to circumstances outside its control (dependence on a flaky network connection, or whatever).

For the other two items, you will need some type of heartbeat service, which you can either build or buy. Be careful to have the heartbeat monitor running local to the services it's monitoring because as I wrote a while ago, the network is not reliable.

RoadWarrior
A: 

+1 for making sure that services are monitored on the local machine.

Something like Service Hawk can monitor your services and restart them if they should stop and sends you an email alert. You could also consider scheduling periodic restarts since, as mentioned by another poster, the service doesn't always show up as "stopped" as far as the SCM is concerned. In those cases the service is hung, frozen, or otherwise messed up and restarting the service every once in a while on a schedule keeps it running cleanly. It just clears out the memory, etc and gives it a fresh start.

ExtraLean