Windows Restart Script (Advanced)
This is the script that I use, just made it last night. Basically it is specifically designed to be used with ScheduledShutdown v1 and wanting the machine running the server to restart as well. There are a few different versions included.
The script writes to a log file "timelog.txt" in the running directory when the batch file starts, when it allows the minecraft server to stay closed, and when an unexpected server shutdown occurs at any other time. The log output looks like:
05/17/2012 0:15:23.68 - Batch file started, first loop 05/17/2012 4:30:17.32 - Allowing the server to stop 05/17/2012 4:36:48.40 - Batch file started, first loop
You will have to edit a few bits of the script for it to synchronize with scheduled shutdown and allow a machine restart without risking corruption and crashing the game process leaving an unusable world that requires a rollback.
You only need to touch 3 things. First edit the line that starts the server ("java -xmx5G -jar cb.jar") and make it what you currently use to start the server. Then you need to edit the top two lines and enter your own time fences. Put the time that ScheduledShutdown is configure to stop the server as the beforeFence. Then place the time that the computer is configured to restart as the afterFence, always allow ample time between these two configurations so that the server can properly close should it get locked up for a bit while saving, it happens. My exact script is shown below. I have the computer set to restart at 4:35 but I set it to 4:37 in the script because that is when it usually boots back into windows
For those of you more adventurous, you can go through and modify any of the lines that say echo and make your own customized console messages and log entries. Beware of messing with any other lines besides those unless you know what you are doing.
Script with logging, and allow for external machine restart
@echo off set beforeFence=0430 set afterFence=0437 set beforeHour=%beforeFence:~0,2% set beforeMinute=%beforeFence:~2,2% set afterMinute=%afterFence:~2,2% echo %date:~4,10% %time% - Batch file started, first loop>>timelog.txt :StartLoop echo (%time%) Bukkit Minecraft Server started. "c:\Program Files\Java\jre6\bin\java.exe" -Xincgc -Xmx5G -jar cb.jar echo Server proccess stopped if %time:~0,2%==%beforeHour% (goto CheckMinute) if %time:~1,1%==%beforeHour% (goto CheckMinute) :CheckMinute if %time:~3,2% GEQ %beforeMinute% (goto CheckAfter) echo %date:~4,10% %time% - Unexpected Crash >>timelog.txt goto StartLoop :CheckAfter if (%time:~3,2%) LEQ (%afterMinute%) goto Skip echo %date:~4,10% %time% - Unexpected Crash >>timelog.txt goto StartLoop :Skip echo Allowing the server to stop! echo %date:~4,10% %time% -
Script with logging and internal machine restart
@echo off set beforeFence=0430 set afterFence=0437 set beforeHour=%beforeFence:~0,2% set beforeMinute=%beforeFence:~2,2% set afterMinute=%afterFence:~2,2% echo %date:~4,10% %time% - Batch file started, first loop>>timelog.txt :StartLoop echo (%time%) Bukkit Minecraft Server started. "c:\Program Files\Java\jre6\bin\java.exe" -Xincgc -Xmx5G -jar cb.jar echo Server proccess stopped if %time:~0,2%==%beforeHour% (goto CheckMinute) if %time:~1,1%==%beforeHour% (goto CheckMinute) :CheckMinute if %time:~3,2% GEQ %beforeMinute% (goto CheckAfter) echo %date:~4,10% %time% - Unexpected Crash >>timelog.txt goto StartLoop :CheckAfter if (%time:~3,2%) LEQ (%afterMinute%) goto Skip echo %date:~4,10% %time% - Unexpected Crash >>timelog.txt goto StartLoop :Skip echo Allowing the server to stop! echo %date:~4,10% %time% - shutdown /r
Script with only logging
@echo off echo %date:~4,10% %time% - Batch file started, first loop>>timelog.txt :StartLoop echo (%time%) Bukkit Minecraft Server started. "c:\Program Files\Java\jre6\bin\java.exe" -Xincgc -Xmx5G -jar cb.jar echo Server proccess stopped! echo %date:~4,10% %time% - Unexpected Crash >>timelog.txt goto StartLoop
Comments