@ECHO OFF REM ******************************************************************** REM RestartNotesAfterCrash.bat REM REM Batch file to handle restarting the Notes service when the server REM crashes. Go to this registry key: REM REM HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug REM REM Set "Auto" to 1 (0 means you get a messagebox on a crash), and REM set "Debugger" to "D:\RunRestart.bat %ld" -- using the path to REM this batch file instead of "D:\" -- where RunRestart.bat is another REM batch file in the same directory with the line: REM REM start D:\RestartNotesAfterCrash.bat %1 REM REM You have to do this in order to run this batch file as a REM foreground process instead of a background process (cause it won't REM work right in the background). Make sure that the full path to this REM batch file is specified in the RunRestart.bat file. REM REM Interestingly enough, after a crash the batch file seems to run REM in the same directory as the crashing process. This is why you REM need the ThisDir variable to point explicitly to the programs and REM the crash log in this directory (or whatever directory they're in). REM REM Note: you will also need KILL.EXE, TLIST.EXE, SLEEP.EXE, and REM SHUTDOWN.EXE programs from the Windows NT Resource Kit in order to REM run this properly. There are some good freeware substitutes for REM these programs at http://www.sysinternals.com (look for psTools). REM REM ******************************************************************** REM version 1.0 REM by Julian Robichaux -- http://www.nsftools.com REM ******************************************************************** REM ADJUST THESE VARIABLES AS NEEDED!!! SET ThisDir=C:\CrashStuff SET NotesDir=D:\Notes5 SET NotesServiceName="Lotus Domino Server (LotusDominoData)" SET IsNotesService=TRUE SET RebootAfterKill=FALSE SET PidList=D:\pid.lst SET NotesTaskList=D:\ntasks.lst SET CrashLog="%ThisDir%\Crash.Log" SET sleep="%ThisDir%\sleep" SET tlist="%ThisDir%\tlist" SET kill="%ThisDir%\kill" SET shutdown="%ThisDir%\shutdown" REM Send basic information about the crash to a text file ECHO ====================================== >> %CrashLog% DATE /T >> %CrashLog% TIME /T >> %CrashLog% ECHO Crashed process reported as %1. >> %CrashLog% if not (%1) == () ECHO Information about the crashing process: >> %CrashLog% if not (%1) == () %tlist% %1 >> %CrashLog% ECHO. >> %CrashLog% REM If there was no PID passed to this batch file, just exit; REM otherwise, display some information about the crashing process if (%1) == () goto end ECHO Crashed process reported as %1 %tlist% %1 ECHO. REM See if the crashing process was a Notes process. If it was, REM restart the Notes server; if it wasn't, just exit ECHO. ECHO Finding all active Notes processes ECHO ------------------------------------ ECHO. dir "%NotesDir%\*.exe" /B > %NotesTaskList% dir "%NotesDir%\*.dll" /B >> %NotesTaskList% %tlist% | findstr /I /G:%NotesTaskList% > %PidList% ECHO Notes processes that are currently running are: ECHO -------------------------------------------------- TYPE %PidList% ECHO. REM if the crashing process was not in our PidList, exit with a message findstr /I "%1 " %PidList% if not (%ErrorLevel%) == (0) goto nonNotesCrash REM Try to kill the crashing process before we continue ECHO Attempting to kill process #%1 %kill% -f %1 ECHO. :stopNotes ECHO Attempting to Shutdown the Domino Server ECHO ------------------------------------------ REM Use the nserver -q syntax if the server is running as a stand-alone REM program. If it's running as a service, use the Net Stop syntax. REM Also, we're starting the shutdown process in a separate window, just REM in case it hangs. REM This line is for Notes servers started as a foreground application if not (%IsNotesService%) == (TRUE) start "Notes Server Shutdown" /b "%NotesDir%\nserver" -q REM This line is for Notes servers started as an NT service if (%IsNotesService%) == (TRUE) start net stop %NotesServiceName% ECHO Waiting 1 minute for Notes server shutdown to complete... %sleep% 60 REM Now forcibly kill any remaining Notes tasks REM You could also call your favorite "kill Notes" kind of utility REM here instead ECHO Notes Processes that must be killed >> %CrashLog% ECHO. TYPE %PidList% >> %CrashLog% ECHO. >> %CrashLog% ECHO Killing all hung Notes processes ECHO ----------------------------------- for /f "tokens=2" %%I in ( %PidList% ) do %kill% -f %%I ECHO. ECHO All Notes Processes Have Been Killed! ECHO. REM If we're supposed to reboot after all of that, then goto REM the reboot section; otherwise, we'll just try to restart REM the Notes server (I've never had much luck with restarts...) if (%RebootAfterKill%) == (TRUE) goto rebootServer :restartNotes ECHO Attempting to restart Notes server ECHO ----------------------------------------- if not (%IsNotesService%) == (TRUE) "%NotesDir%\nserver" if (%IsNotesService%) == (TRUE) net start %NotesServiceName% goto end :rebootServer ECHO Rebooting server in 5 seconds... REM set the reboot flag so we can be notified by the server DATE /T >> "%ThisDir%\RebootFlag" TIME /T >> "%ThisDir%\RebootFlag" %shutdown% /L /R /T:5 /Y /C goto end :nonNotesCrash ECHO. ECHO The crashing PID: %1 was not found in the list of running Notes processes. ECHO Notes will not be restarted. ECHO. ECHO The crashing PID: %1 was not found in the list of running Notes processes: >> %CrashLog% TYPE %PidList% >> %CrashLog% ECHO Notes will not be restarted. >> %CrashLog% ECHO. >> %CrashLog% REM You can also run another debugger here if you'd like to. For example: REM d:\notes5\qnc.exe -p %1 -e %1 -g :end PAUSE