2

Is there a way to control the order in which services are stopped on a system shut-down?

We are having issues with our domain-controller, which takes forever to shut down (if it goes down at all) because of a mistake in the order the services are shut down (First domain services, then Exchange).

I could write a script to stop Exchange first and then shut down the machine, but would really like to be able to just issue a shutdown /r /t 1 and not have to think about it.

So, is there a way to control the order in which services are stopped/started on system stops/starts?

Powertieke
  • 377
  • 2
  • 8

3 Answers3

3

Write the script. Assign it to the computer as a shutdown script. This script will be processed before any services are stopped.

Jason Berg
  • 19,084
  • 6
  • 40
  • 55
3

How to create a dependency between Windows services

  1. Run regedit to open your registry.
  2. Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services and locate the service that you need to set a dependency for.
  3. Open the DependOnService key on the right side. If the selected service does not have a DependOnService key, then create one by right-clicking and selecting New > Multi-String Value.
  4. In the value field, enter the names of all services that the current service will depend on. Each service name must be entered properly and on a separate line.
  5. Click OK, close your registry and restart your machine.

You could use this method to force dependencies between services, but it is undocumented.

The real question is why is Exchange Server delaying the shutdown. Exchange shouldn't be delaying the system shutdown like this. It sounds like this real issue needs to be addressed.

From msexchange.org:

If Exchange is on a domain controller then that will be the problem. It is caused by the simple fact that Exchange will only use itself for domain controller functions when installed on a DC, and when it is shutting down it needs to contact the domain controller. However during shutdown the domain controller functionality ends quicker than Exchange does. The delay is caused by the time Windows waits before it starts killing the services rather than letting them stop gracefully.

You can use a script to shutdown Exchange first and then restart the server. However the best option would be to get Exchange off that machine. Remember that you cannot remove the DC functionality while Exchange is installed. That is not supported and will often break Exchange. Exchange has to be removed first, or moved to another machine.

Ian Boyd
  • 5,293
  • 14
  • 60
  • 82
  • I like this one too, but I'm a mac/linux kinda guy, and the registry freaks me out a little bit. Maybe after a few beers :P. – Powertieke Sep 24 '10 at 20:33
  • 1
    @Powertieke - nope, this is the correct answer. It's the full version of what I posted, and was what I was fuzzily remembering. – mfinni Sep 24 '10 at 20:39
  • It appears to be a common issue with a domain controller which is also an exchange server. The 'hired' experts don't seem to be able to deal with it... – Powertieke Sep 24 '10 at 20:39
  • It's the way Windows defines dependencies between services. Technically the list of service dependences is passed to a `CreateService` API - that is the documented way to create dependencies between services (but since you didn't write the Exchange Server installer, you have no control over that). – Ian Boyd Sep 24 '10 at 20:41
  • @mfinni +1. Yes, i ran with your idea ;) – Ian Boyd Sep 24 '10 at 20:41
  • I'll go and try this on monday :) – Powertieke Sep 24 '10 at 20:50
1

Just guessing - can you make the Exchange service(s) dependent on the domain services? I should think Windows would then shut down Exchange first, before shutting down what they depend on.

mfinni
  • 36,144
  • 4
  • 53
  • 86