Automatically reboot minecraft on crashes

01May

Automatically reboot minecraft on crashes

by Craig Mayhew on Sun 1st May 2011 under Code
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.


  1. Install php on the minecraft server.

  2. 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 :)';
    }
    ?>



  3. 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"


  4. PHP   Minecraft  




© 2018 Craig Mayhew