Automatically reboot minecraft on crashes
The latest version of minecraft has been extremely unstable for me, so I've written this quick script to automatically check if minecraft is running - and reboot it within 30 seconds if it isn't. You will need php installed for this script to work.
- Install php on the minecraft server.
- Save this code to a file named "rebootCheck.php"
<?php
//options
$url = 'localhost';//localhost or an ip address
$port = 25565;//25565 is minecrafts default port
$pauseLength = 20;//time between killing minecraft and booting it again
//end options
$fp = @pfsockopen($url, $port);
if (!$fp) {
echo 'SERVER DOWN! Rebooting it.',"\r\n";
//kill anything with javaw.exe in the name
`Taskkill /IM javaw.exe`;
//take a nap, while minecraft shutsdown
sleep($pauseLength);
//boot minecraft
`C:\Users\user\Desktop\minecraft alpha\Minecraft_Server.exe`;
} else {
echo 'SERVER UP :)';
}
?>
Add a scheduled task to run every 5 minutes and run the following command. Notice here that I have put php within the minecraft directory, you may not have php there and may need to adjust the directory accordingly.
"C:\servers\minecraft alpha\php\php.exe" "C:\servers\minecraft alpha\php\scripts\check.php"