Automating a Quicker Exchange 2000 or 2003 / DC reboot
Microsoft’s official advice is that you are not supposed to install Exchange on a Domain Controller. The fact remains, however, that there are a lot of Exchange DCs in use out there. Ultimately, whether you install Exchange on a DC, or not, depends on many factors (like what else the server is expected to do); but one thing you will have noticed if you do have an Exchange DC is that it takes a very long time to shut down or reboot. I mean a very long time; somewhere between 15 and 30 minutes, usually. I used to think that it was just my own servers that took a long time to reboot (due to something that I’d configured incorrectly, no doubt), but when I came across a Microsoft knowledgebase article KB555025 discussing this issue, I was relieved to discover that it happens to them all, and more importantly, that there is something you can do about it.
It turns out that the problem is caused by the fact that the server shuts down Active Directory before it shuts down the Exchange services. Exchange relies rather heavily on Active Directory, and therefore it takes it a long time to shut down cleanly while it is still trying to communicate with it. Of course, this wouldn’t be a problem if you never needed to reboot your server, but most automatic updates seem to insist on it nowadays.
The previously mentioned KB article suggests that the problem of the slow shutdown can be resolved by either shutting down the Exchange services using a batch file, or by manipulating the registry entry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\WaitToKillServiceTimeout . It transpires that changing this registry value can cause other problems because it kills the Exchange Services before they are really ready. This certainly improves the shutdown time, but may leave your Exchange data in inconsistent state. Besides, the KB document also states that MS do not officially support the use of the registry key in this way.
In fact, the best way to shut down your Exchange services prior to shutdown is by using a batch file. The only problem is remembering to run it first. If you forget, your server will shut down as slowly as ever. What we need is a way to run the script every time the server shuts down. The method described will ensure that the Exchange services will be stopped first, even if the server is shut down remotely, or by a UPS as a result of a power failure.
You can make the server execute a script at shutdown time by using the Group Policy Editor, which is an MMC (Microsoft Management Console) snap-in. I will explain how to use the Group Policy Editor shortly, but first, we need to create the batch file that will shut down the Exchange services.
The batch file is very short, and you can create it in Notepad (figure 1):
Figure 1: The Batch File in Notepad
Here is the text that I have used, in case you want to copy/paste it, rather than type it yourself:
net stop MSExchangeES /y
net stop MSExchangeIS /y
net stop MSExchangeMTA /y
net stop MSExchangeSA /y
net stop WinHttpAutoProxySvc /y
Or, you can download the completed file from here http://www.leederbyshire.com/DL/ExchShutdown.zip
For this example, I am going to save the file in the root of my server’s C: drive, but remember that you can also save it in a shared folder, in case you want it to be accessed by several servers.
Now, we are going to use the Group Policy Editor to configure the server to execute this batch file every time it is shut down. Click on Run on your server’s Start Menu, and type gpedit.msc , then click OK (figure 2) to start the Group Policy Editor.
Figure 2: Starting the Group Policy Editor
Once the Group Policy Editor has started, expand the tree in the left-hand window through Computer Configuration, Windows Settings, and then select Scripts (Startup/Shutdown), so that you can see the Startup and Shutdown objects in the right-hand pane. Right-click Shutdown and select the Properties open from the context menu as shown in figure 3.
Figure 3: The Group Policy Editor main window
You probably do not have any shutdown scripts configured yet, so the list will probably be empty (figure 4):
Figure 4: The list of Shutdown Scripts for the Local Computer
Click the Add button, and then click on Browse… to navigate to the location of the batch file that you created. Remember that I saved the file on my C: drive, but your location may be different. Once you have located the file in the browser dialog, select it, and click Open to indicate the file location. Of course, you could also just type the full path into the Script Name field.
Figure 5: Adding a Shutdown Script to the list
Once you have the script name field populated with the batch file path, click OK to add it to the list of Shutdown Scripts, as shown in figure 6:
Figure 6: The Shutdown Script added to the list
Click OK to save the changes, close the Group Policy Editor, and the procedure is finished.
This probably isn’t something you can test immediately (unless you’re working very late), but the next time you need to shutdown or reboot the server, you should find that it shuts down a lot quicker. In my case, it now takes about three minutes instead of twenty minutes. Of course, it would all be a lot simpler if the Exchange setup program somehow automatically arranged for the Exchange Services to shutdown first wouldn’t it? Perhaps that isn’t as simple as it sounds.
(This article is based on a similar one, which I wrote some time earlier. Thanks to the feedback I received, most notably from Andras Gaal, I am able to describe this improved method, which offers automation of the script, rather than manual execution).