3

We have about a dozen Windows Services, both in-house developed and third-party products, and have the following requirements for managing them:

  • Start/Stop/Bounce a given service at scheduled times of day, on certain days of the week.
  • Optionally monitor services: If a monitored service stops unexpectedly, send a notification email, and optionally start it.

These seems like fairly basic requirements, but I have not found any easy way to satisfy them with built-in Windows features, or simple and affordable third-party tools. Surely this must be a solved problem?! I expected to immediately find some open source tool to do just this.

An optional "fancy" requirement would be: - An awareness of manual intervention, such that the tool will not interfere with manual actions. e.g. Ability to stop and start services interactively via the same tool that does the monitoring, and/or ability to notify the tool that manual intervention is taking place.

Any ideas appreciated.

Daniel Fortunov
  • 201
  • 3
  • 5

5 Answers5

1

If you want to stop and start services on a schedule then why not use the windows built in job scheduler? It's perfectly capable of doing this kind of thing - it can run a command and you can simply use that with batch jobs designed to start and stop services.

As for monitoring services - again you can use the recovery option in the service itself - select 'run a program' and use that to run a batch job that sends an email notification (via something like blat if you want to make it easy) and then re-starts the service.

Service

Rob Moir
  • 31,884
  • 6
  • 58
  • 89
1

RobM's and HopelessN00b's suggestions are good if you want to stick with Windows tools (except for emailing with blat.exe which is actually a great command-line smtp emails).

Since you mentioned interest in a 3rd party utility, our (free) monitoring software EventSentry Light should be able to fulfill all of your requirements - with one piece of free software:

  1. Monitor Services: It will notify you when a service changes its status.
  2. Change Service Status: Our "Application Scheduler" allows you to schedule simple scripts, in this case you could just utilize sc.exe to stop & start a service at specified times.
  3. Control Services: You can specify a desired service status, in which case EventSentry will attempt to always keep the service in that state.

The advantage of the application scheduler is that it can capture the output from command-line processes in the event log, so if the service restart didn't work (for whatever reason), then you can instantly get a notification with the entire command line output.

Lucky Luke
  • 1,634
  • 1
  • 11
  • 12
0

This PowerShell script monitors when Windows services start and stop:

$services = @{};

while ($true)
{
    foreach ($service in @(Get-Service))
    {
        $oldStatus = $services[$service.Name];
        $newStatus = $service.Status;

        if (!$oldStatus)
        {
            echo "$newStatus $($service.Name) ($($service.DisplayName))"
        }
        elseif ($oldStatus -ne $newStatus)
        {
            echo "$oldStatus -> $newStatus $($service.Name) ($($service.DisplayName))"
        }

        $services[$service.Name] = $newStatus;
    }

    Start-Sleep 1
}

Sample output:

Stopped AarSvc_e22aba (Agent Activation Runtime_e22aba)
Stopped AJRouter (AllJoyn Router Service)
Stopped ALG (Application Layer Gateway Service)
Running AMD External Events Utility (AMD External Events Utility)
...
Stopped XblAuthManager (Xbox Live Auth Manager)
Stopped XblGameSave (Xbox Live Game Save)
Stopped XboxGipSvc (Xbox Accessory Management Service)
Stopped XboxNetApiSvc (Xbox Live Networking Service)
Running -> Stopped camsvc (Capability Access Manager Service)
Stopped -> Running camsvc (Capability Access Manager Service)
Stopped -> Running ClipSVC (Client License Service (ClipSVC))
Running -> Stopped camsvc (Capability Access Manager Service)
Running -> Stopped ClipSVC (Client License Service (ClipSVC))
Running -> Stopped AppXSvc (AppX Deployment Service (AppXSVC))
Stopped -> Running AppXSvc (AppX Deployment Service (AppXSVC))
Stopped -> Running ClipSVC (Client License Service (ClipSVC))
Stopped -> Running WerSvc (Windows Error Reporting Service)
Joey Adams
  • 277
  • 2
  • 4
  • 9
0

For monitoring: There is a built-in feature, look into the "Recovery" tab when you click the properties of the service in services.msc. You can "Run a Program" if the service fails, this program can be a script to send an email for example. There are also dozens of network monitoring solutions which can monitor windows services, Nagios, PRTG, OpenNMS to name a few.

duenni
  • 2,959
  • 1
  • 23
  • 38
0

As suggested by @RobM you can provide basic monitoring and recovery functionality through the service properties tab, though in my experience this tends to not scale well across a large number of servers or services and is more limited than I'd like. If your needs are beyond this basic tool, you can license any number of monitoring suites, or if cost is a factor, roll your own monitoring scripts fairly simply.

If you've got more of a *nix background, you might find it simpler to use SNMP to monitor and control services, though the native option is WMI (Windows Management Instrumentation), and the command-line WMIC (Windows Management Instrumentation Command), which is very powerful once you get the hang of using it.

For example... you can get a listing of the services on a target computer with: WMIC /node:[hostname] SERVICE LIST

output a list of running services with:

WMIC SERVICE where (state=”running”) GET caption, name, state > services.tsv

and start the telnet service with:

WMIC SERVICE where caption='TELNET' CALL STARTSERVICE.

A little bit of logic in your scripting language of choice and you can send out email alerts when a specific service isn't running, start, stop or restart services on a schedule, and meet all your other requirements. Best of all, it's native, and the only tool you need is a windows CLI (cmd and Powershell both work) and a very small amount of scripting skill.

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209