[There's a reason that Yoda is the unofficial mascot of SBS.  Size indeed matters not.] Charlie Russel on shutdown.. - THE OFFICIAL BLOG OF THE SBS "DIVA"
Saturday, November 17, 2007 11:30 PM bradley

Charlie Russel on shutdown..

In addition to writing really good books on Windows Server, SBS and lots of other technical titles for MS Press, Charlie Russel knows he way around scripts and Powershell.  

So we started chatting about tricks we use to ensure that our servers reboot.. and Charlie Russel shared his reboot scripts... Make sure you download the sleep.exe file and put it in the same subdirectory as all the rest.

They are also in this download section: http://msmvps.com/files/folders/bradley/entry1328651.aspx

The first one is called shutdown_reboot.cmd and includes this:

SHUTDOWN_REBOOT.CMD

----------------------

@REM ****************************************************************
@REM Batch file to shut down and reboot the SBS server. For when it's
@REM mis-behaving. Calls stopexch.cmd, then uses shutdown -r -t 5
@REM
@REM   Requires a separate stopexch.cmd and sleep.exe from the
@REM     Server 2k3 RK.
@REM
@REM  Possible enhancements:
@REM     Use command line parameters to control wait times and
@REM     shutdown warning commands.
@REM ****************************************************************


@REM Ignore any sleep errors if you don't have a copy of sleep on this
@REM   machine. It's not critical, just for neatness.
@REM

SET LOGFILE=C:\Shutdown.log
SET WARNING=5
SET SLEEP=2

echo ===================================================================== >> %LOGFILE%
echo. >>%LOGFILE%
echo Automatic reboot of SRV1 initiated at: >> %LOGFILE%
date /t >> %LOGFILE%
time /t >> %LOGFILE%
echo. >>%LOGFILE%
echo Calling exchange shutdown script to speed things up >> %LOGFILE%

sleep %SLEEP%
call %windir%\system32\stopexch.cmd 1>&2 >> %LOGFILE%

echo. >>%LOGFILE%
echo Exchange should be stopped now... >> %LOGFILE%
echo. >>%LOGFILE%
echo. >>%LOGFILE%
echo Now, shutting down the server using the command: >> %LOGFILE%
echo 'shutdown /r /t %WARNING% /c "Automatic Reboot for out of resources problem" /d e:4:5' >> %LOGFILE%
@echo Shutting down in %WARNING% seconds...
shutdown /r /t %WARNING% /c "Automatic Reboot for out of resources problem" >> %LOGFILE%

----------------------

The second is called shutdown_server_60.cmd and looks like this:

SHUTDOWN_SERVER_60.CMD

---------------------

@echo off
REM Script to automatically reboot the server
REM this is a temporary workaround until we figure out what's happening
REM
REM ModHist: 8/5/2006 - Initial, cpr
REM        :
REM
SET LOGFILE=C:\Shutdown.log
echo Automatic reboot of SRV1 initiated at: >> %LOGFILE%
date /t >> %LOGFILE%
time /t >> %LOGFILE%
echo. >>%LOGFILE%
echo Calling exchange shutdown script to speed things up >> %LOGFILE%
call stopexch.cmd 1>&2 >> %LOGFILE%
echo. >>%LOGFILE%
echo Exchange should be stopped now... >> %LOGFILE%
echo. >>%LOGFILE%
echo. >>%LOGFILE%
echo Now, shutting down the server using the command: >> %LOGFILE%
echo 'shutdown /r /t 60 /c "Automatic Reboot for out of resources problem" /d e:4:5' >> %LOGFILE%
shutdown /r /t 60 /c "Automatic Reboot for out of resources problem" >> %LOGFILE%

-------------

>>Next grab a copy of sleep.exe from the Win2k res kit... there's some links here to grab that

>>http://hp.vector.co.jp/authors/VA007219/sleep/sleep.html

-------------

Next Charlie has a script called startexch.cmd

STARTEXCH.CMD

-------------

REM batch file to start MS Exchange services on SRV1
REM Created: 18/03/05 by charlie
REM ModHist:
REM
rem first we have ones that are interdependent

net start "Microsoft Exchange System Attendant"
net start "Microsoft Exchange Information Store"

sleep 5
REM now, the ones that are essentially standalone
net start "Microsoft Exchange Management"
net start "Microsoft Exchange Routing Engine"
net start "Network News Transfer Protocol (NNTP)"
net start "Simple Mail Transfer Protocol (SMTP)"
sleep 5

-------

lastly the script stopexch.cmd that stops the Exchange services

STOPEXCH.CMD

---------

@REM ****************************************************************
@REM batch file to stop MS Exchange services
@REM Created: 18/03/05 by charlie
@REM ModHist: 27/10/06 - cleaned up REMs and changed sleeps
@REM
@REM ****************************************************************
@REM these first ones aren't really dependent on anything else
@REM nor are any of the other MS exchange pieces dependent on them

@REM we expect this to be called from the shutdown_reboot batch file
@REM  which will pass in a value for SLEEP. But if called alone, use
@REM  a default value.

IF  "%SLEEP%" == "" SET SLEEP=5

@echo First, stop the non-dependent services
net stop "Microsoft Exchange Management"
net stop "Microsoft Exchange Routing Engine"
net stop "Network News Transfer Protocol (NNTP)"
net stop "Simple Mail Transfer Protocol (SMTP)"


@REM if sleep.exe is not on this machine, you'll get an error on
@REM the following. Ignore it, or download and install the reskit
@REM Now we have ones that are interdependent

sleep %SLEEP%

@echo Stopping the dependent services in order....
net stop "Microsoft Exchange Information Store"
net stop "Microsoft Exchange System Attendant"

sleep %SLEEP%

Filed under:

# re: Charlie Russel on shutdown..

Sunday, November 18, 2007 11:28 AM by Harry Carter

In using the stop exchnage script, it hangs with a user prompt:

C:\scripts>net stop "Microsoft Exchange System Attendant"

The following services are dependent on the Microsoft Exchange System Attendant service.

Stopping the Microsoft Exchange System Attendant service will also stop these services.

  Microsoft Exchange MTA Stacks

Do you want to continue this operation? (Y/N) No:

# re: Charlie Russel on shutdown..

Sunday, November 18, 2007 12:03 PM by Charlie Russel

Most SBS boxes don't use MTA stacks, so won't see that issue. But if your environment does, then simply add a line just before the system attendent line:

NET Stop "Microsoft Exchange MTA Stacks"

and you're in business. You can also include a "/y" at the end of a net stop line and it should act as a "yes" response to that query. But I prefer inserting the missing line and getting the order right in the first place.

HTH.

Charlie.

# re: Charlie Russel on shutdown..

Wednesday, November 21, 2007 4:34 AM by Andy

nice script - a couple of changes. You may want to change the location for the stopexch.cmd file, or at least hard code it into the path. One of the batch files has it in the system32 directory, the other doesn't.

I'd also change references to srv1 to %hostname% so the log file has the correct server name in it.

Also you may want to add the /f to the end of the shutdown commands, otherwise you may get "The machine is locked and can not be shut down without the force option" if someone is logged onto the console of the machine.

# re: Charlie Russel on shutdown..

Wednesday, December 05, 2007 11:52 AM by Terry Cole

At the risk of looking somewhat naive, what is the value of this script versus "shutdown /r"?

# re: Charlie Russel on shutdown..

Tuesday, January 08, 2008 12:28 AM by Charlie Russel

To answer Terry Cole - it's faster, and it works. The straight shutdown /r has been known to hang. But shutting down Exchange first, and adding a /t command seems to solve the problem, even on stubborn systems.

Charlie.

# Kicking and Screaming I am Bloggin » Blog Archive » Restart File discussed at Triad SBS Group Meeting

Pingback from  Kicking and Screaming I am Bloggin  » Blog Archive   » Restart File discussed at Triad SBS Group Meeting