Windows services restart automatically

  One of our Windows Services crashes a few times a month. When that happens, a tech has to log into the server and start the service again, which is a pain. Isn’t there a way to restart the service automatically after it crashes? Please help.

— Kirkland

Hi Kirkland.

A Windows Service is Microsoft’s technology of choice for mission-critical applications that must run 24/7/365. As such, it’s incredibly frustrating when a service crashes and fails to deliver on that primary task!

Not to worry though, we’ve got your back. Here are a couple of ways to ensure that your Windows Service rebounds quickly after a crash (or other failure).

Solution #1: Configure Service Recovery (Basic)

Good news! Windows Services come with a built-in recovery mechanism.

If you open your troublesome service in the Services application, you will notice the Recovery tab:

Services Recovery Tab

There, you can specify what happens the first, second and subsequent times that your service fails.

Windows can perform one of the following three actions in response to a failure:

  • Restart the service

  • Restart the computer

  • Run a program

Or you can select “Take no action” to do nothing at all. That is the default for new services.

If you choose to run a program, you must specify the full path to the program to run, along with any parameters required.

For your situation, we recommend that you set all failure actions to “Restart the Service”:

Recovery Tab: Restart the Service

Simple, right? Well, maybe not. While the actions are straightforward, exactly what defines a failure? Under what conditions will Windows invoke the actions you have specified (i.e. to restart the service)?

Let’s back up a bit and address that mystery.

Microsoft’s definition of service failure

From the technical documentation, a service fails if it:

  1. Terminates without reporting a status of SERVICE_STOPPED to the Service Control Manager, or

  2. Exits with a non-zero exit code.

Note that (b) applies only if the Enable actions for stops with errors box on the Recovery tab is checked. You should definitely enable that option because doing so will allow Windows to catch a wider range of failures of your misbehaving service.

To sum up, here is our final recommended recovery configuration:

Recovery Tab: Recommended settings

Next, let’s look at where Windows Service recovery does a great job and where it’s not quite up to the task.

What service interruptions are covered by the Recovery tab?

The recovery settings above will cover a wide array of interruptions of your service.

For example, Windows will restart your service if:

  • The service ends unexpectedly

  • The service’s process is terminated (e.g. someone kills it from Task Manager)

  • The service exits with a non-zero error code

What service interruptions are NOT covered by the Recovery tab?

Sadly, the following disruptions are not handled by the basic recovery settings:

  • The service fails to start at boot

  • Someone accidentally stops the service from Services (or using the NET or SC commands)

  • The service stops unexpectedly but exits with code 0 (e.g. due to a bug in the software)

  • An internal component of the service crashes but the service shuts down normally

  • The service has a memory leak and stops working after it runs for a while

Other ways that Service Recovery falls short

Besides the above:

  • Service failures will be silent. That’s because the recovery options do not include notification. As a result, you may not find out when your service fails to start.

  • There is no protection in “zombie” situations — where your service is running but isn’t working as expected. Unfortunately, the recovery options are not sophisticated enough to look beyond the service’s status.

Solution #2: Deploy Service Protector (Advanced)

For comprehensive protection against a wide range of problems — including the ones listed above — you should use our Service Protector software.

Service Protector keeps any Windows Service running 24/7/365. Whenever a service stops — no matter the reason — Service Protector will immediately restart it.

Here’s a look at Service Protector babysitting the Windows print spooler service on our Server 2022 machine:

The Print Spooler service is protected

But Service Protector is much more than automatic restarts. Here are some of its key features:

Stuck service detection

Service Protector will handle non-responsive services that become stuck in the “Stopping” or “Starting” states for too long.

CPU hog detection

You can tell Service Protector to restart your service if it “runs hot” for a long period.

Memory leak/hog detection

A Windows Service that constantly eats up RAM can lead to disaster. Service Protector will terminate and recycle leaky services, to free up accumulated memory and restore normal operation.

Email alerts when things go wrong

To ensure that you are kept in the loop, Service Protector can send you an email whenever your service fails.

Extensibility

Extend Service Protector with your own, customized failure detection plugins. Use them to detect and restart “zombie” Windows Services.

Workflow

Need to perform some housekeeping tasks before your service starts? Service Protector can run a batch file (or program) before restarting your Windows Service.

Scheduled restarts

Sometimes software that has been running for too long doesn’t work. Service Protector can restart your service (or reboot the PC) at specific times, to minimize the effects of memory leaks and keep your service “fresh”.

Daily/Weekly reports

Service Protector will email you summaries of restarts, crashes, etc.

Error control

Service Protector will automatically dismiss those annoying “I have crashed!” message boxes that can halt the action.

Restores disabled services

If some clever person disables your service from the Services application, Service Protector will automatically re-enable it.

Try Service Protector for Free

Best of all, you can setup your service with Service Protector and see how it works completely free for 30 days. No need to make a purchase, register your email or provide a credit card. Just download and install.

Finally, while the Recovery tab is free, a perpetual license of Service Protector costs $99.99.

Nevertheless, if you are operating in a commercial environment where downtime is costly, we recommend making that modest investment to bulletproof your servers.

Best of luck with your service!

You may also like…

Setting a service to restart automatically on failure using the Windows Service Manager (WSM) is essential for ensuring continuous operation and minimal downtime of critical services within the Windows operating system. This detailed article provides step-by-step instructions on how to configure automatic service restart settings using WSM, empowering administrators and users to enhance service reliability and maintain system performance.

Introduction to Automatic Service Restart in Windows Service Manager

The Windows Service Manager serves as a centralised tool for manageing background services that are essential for system functionality. Configuring automatic restart options ensures that services are automatically restarted in the event of failure, reducing the need for manual intervention and maintaining seamless operation.

Steps to Set a Service to Restart Automatically on Failure

1. Accessing Windows Service Manager

  1. Open Run Dialog Box:
    • Press Windows Key + R on your keyboard to open the Run dialog box.
  2. Enter services.msc:
    • Type services.msc into the Run dialog box and press Enter. This action launches the Windows Service Manager interface.

2. Configuring Automatic Restart Settings

  1. Navigate to Services Console:
    • In the Windows Service Manager window, locate the service you wish to configure for automatic restart from the list of displayed services.
  2. Access Service Properties:
    • Right-click on the service name and select Properties from the context menu.
  3. Navigate to Recovery Tab:
    • In the Properties window of the selected service, click on the Recovery tab.

3. Setting Automatic Restart Options

  1. Configure First Failure Action:
    • Under the First failure section, use the dropdown menu to select Restart the service. This option instructs Windows to automatically attempt to restart the service upon the first failure.
  2. Define Subsequent Failure Actions:
    • Optionally, configure actions for subsequent failures by choosing from options such as Restart the service, Run a program, Restart the computer, or Take no action under the Second failure and Subsequent failures sections.
  3. Specify Reset Options:
    • Set Reset fail count after to define the time interval after which Windows resets the failure count for the service, allowing subsequent restart attempts as needed.
  4. Adjust Restart Delay (if required):
    • Optionally, adjust Restart service after to specify the time delay (in minutes) before Windows attempts to restart the service after a failure. This parameter helps stagger restart attempts and manage system resources effectively.

4. Applying and Saving Configuration

  1. Save Configuration Changes:
    • Once automatic restart settings are configured, click Apply and then OK to save the settings for the service.
    • Windows Service Manager will apply the specified automatic restart options, ensuring that the service is configured to restart automatically on failure as defined.

5. Testing and Monitoring Automatic Restart

  1. Verify Configuration:
    • Test the configured automatic restart settings by intentionally stopping the service or simulating a failure scenario.
    • Monitor the Services console and Event Viewer (eventvwr.msc) for logs and notifications related to service restart attempts and verify that the configured settings function correctly.

Benefits of Setting Automatic Restart in Windows Service Manager

  • Continuous Operation: Ensure continuous service availability and minimise downtime by automating restart procedures in response to service failures.
  • Operational Efficiency: Reduce manual intervention and streamline service management tasks, enhancing overall system efficiency and resource optimisation.
  • Enhanced Reliability: Maintain service integrity and reliability by promptly addressing service failures and facilitating quick recovery without impacting system operations.

Conclusion

Setting a service to restart automatically on failure using the Windows Service Manager is integral to maintaining service reliability and operational continuity within Windows environments. By following the outlined steps and best practices in this guide, administrators and users can effectively configure automatic restart options, mitigate service disruptions, and ensure seamless operation of critical services across their IT infrastructure.

By leverageing the capabilities of Windows Service Manager to automate service restart procedures, organisations can enhance system resilience, optimise service management practices, and uphold performance standards aligned with business objectives and operational requirements. This approach supports proactive maintenance and responsive action to service failures, contributing to a robust and efficient computing environment.

What happens when you run a program via service and it stops responding? You can configure the service to automatically restart if it stops responding. You can even set an option that if service was automatically restarted to restart again. But sometimes this functionality doesn’t work as expected.

I mean service could stop every hour and then, eventually, you have to start the service automatically.

If you are dependant on a program whose service is failing regularly you have two options.

  1. Fix the problem
  2. Find a way to bypass the problem

Number one is the best solution, you dig in to the problem, find a cause and you fix it. This one is also the most rewarding, you get one of those feelings, wow, I did something well and that makes me feel good.

Number two is more like a bypass, you find a quick solution to fix the problem but you do not fix the cause. You will always know that you didn’t do your best. But you did fix the problem. You see, sometimes there is no other way, there is no time, perhaps software vendor is out of business and you can’t get proper support.

So how do you automatically restart a windows service?

There is a this fine program called NetWrix Services Monitor.

User interface simple, it has only has the features that are needed. Once installed you are able to restart windows services, but not only on the server program is installed on, that would be to easy, you can restart windows services on the server program is installed plus you can restart a service remotely, on remote servers. All the services that you add are being monitored from this fine program.

First you need to Enable Services Monitor, then you set which servers and services you will monitor.

You can set alerting via email (this can be really helpful, either to troubleshoot or to give vendor more data when services stop)

After the service is stopped, the program can notify you via email, start the service, reboot the server and even start a user program. And best of all, it’s very simple to use. It’s doesn’t have unnecessary functions.

Wonderful tool that can save you some time. Did I mention it’s free? You can get it here

How to restart a windows service from a command line?

If you are looking for a way to restart a windows service from a command line, either for use in installation program or for writing up a script, you can use a command called net stop.

To stop the service you would use:

net stop {name of the service}

To start the service you would use:

net start {name of the service}

So to restart a service you would use both at the same time:

net stop {name of the service} && net start {name of the service}

You can include it in a command prompt or even scheduled tasks:

cmd /c “net stop{name of the service} & sc start {name of the service}”

To find a service name, you can type: net start and it will list all the services

You can also use Powershell to restart a service:

Restart-Service

Windows Service is a program or application that runs on the Windows operating system and operates as a background process, without requiring user interaction.

A service is, in fact, any Windows program that uses the Service API to perform low-level activities that require little or no user input.

Windows Service controls various operations, such as network connection, speaker sound, data backup, and user authentication. Services are typically used for continuous system tasks, such as monitoring, synchronization, or other maintenance tasks.

Windows Service can be set to auto-start when the computer boots and runs all the time even if no user is logged on to the system.

You may need to open and adjust your Windows Service from time to time. Start or stop a Service, disable it, delay its startup, or restart or suspend a Windows Service.

How to open Windows Services Manager

There are several ways to open Windows Services Manager:

  1. Use the keyboard keys (WIN + R) and type “services.msc” in the Run dialog box. Press Enter.
  2. Click Start Menu, then find and click Control Panel. Click System and Security, then click Administrative Tools. Double-click on Services.
  3. Click the Start Menu, then find and click Command Prompt (Admin). Type “services.msc” in the Command Prompt and press Enter.

All the above methods will open the Windows Services Manager, which will allow you to set up and manage the services running on the Windows operating system.

How to restart Windows Services

To restart Windows Service, you can use Windows Services Manager. Here are the steps to restart a specific Service:

  1. Open Windows Services Manager.
  2. Find the service you want to restart, for example, “Print Spooler”.
  3. Right-click on the service and select ” Restart ” from the drop-down menu.
  4. A confirmation pop-up will appear, click ” Yes ” to continue.
  5. The service will restart and will run as normal.

Some services may require a computer restart to restart the service. If the service cannot be restarted via Windows Services Manager, restart your computer.

How to configure Windows Service to restart automatically if it crashes

To configure Windows Service to automatically restart if it crashes, here are the steps you can take:

  1. Open ” Services ” via Control Panel or by entering the command “services.msc” in Run.
  2. Find the service you want to configure and right-click on it.
  3. Select the “Recovery” tab.
  4. In the ” First failure ” section, select the “Restart the Service” option.
  5. In the “Subsequent failures” section, select the ” Restart the Service ” option as well.
  6. Click OK to save changes.

Service will automatically restart after the crash. You can change recovery settings for each different type of service failure.

Other Interesting Articles

How to configure Windows Service to restart automatically via the Task Scheduler

To configure Windows Service to restart automatically via Task Scheduler, follow these steps:

  1. Open Task Scheduler: Click Start, find Task Scheduler, and click on Task Scheduler.
  2. Create a new task: Click on the ” Create Task...” button in the ” Actions ” section.
  3. Name the task: Enter a name for the task in the ” Name ” box.
  4. Trigger configuration: Click on the “ Triggers ” tab and click on the “ New ” button. Select ” At log on ” or ” At startup ” or other desired time.
  5. Then set ” Repeat task every “, for example, every hour, if you want to check the service every hour.
  1. Action configuration: Click on the “Actions ” tab and click on the ” New ” button. Select ” Start a program ” and enter the command “net start [service_name]” in the “Program/script” box.
  1. Save task: Click the “OK” button to save the task and start the task automatically each time the computer is turned on.
  2. Check task: Open Task Scheduler and check if the new task is running correctly.

Note that service_name must be replaced with the name of the service you want to configure.

Windows Service is a program or application that runs on the Windows operating system and operates as a background process, without requiring user interaction.

A service is, in fact, any Windows program that uses the Service API to perform low-level activities that require little or no user input.

Windows Service controls various operations, such as network connection, speaker sound, data backup, and user authentication. Services are typically used for continuous system tasks, such as monitoring, synchronization, or other maintenance tasks.

Windows Service can be set to auto-start when the computer boots and runs all the time even if no user is logged on to the system.

You may need to open and adjust your Windows Service from time to time. Start or stop a Service, disable it, delay its startup, or restart or suspend a Windows Service.

How to open Windows Services Manager

There are several ways to open Windows Services Manager:

Use the keyboard keys (WIN + R) and type “services.msc” in the Run dialog box. Press Enter.

Click Start Menu, then find and click Control Panel. Click System and Security, then click Administrative Tools. Double-click on Services.

Click the Start Menu, then find and click Command Prompt (Admin). Type “services.msc” in the Command Prompt and press Enter.

All the above methods will open the Windows Services Manager, which will allow you to set up and manage the services running on the Windows operating system.

How to re…
https://bardimin.com/en/windows-en/how-to-configure-windows-service-to-restart-automatically/?feed_id=757&_unique_id=66a558ed8a521

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Что делать если часто вылетает синий экран на windows 11
  • Команда управление компьютером из командной строки windows 10
  • Linux file system for windows by paragon software key
  • Change windows lock screen windows 10
  • C programdata microsoft windows defender scans history service