Sat, Nov 17 2007 23:30
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: News