Results 1 to 6 of 6
  1. #1

    Testing and Restarting Apache

    We have an issue with Apache and ColdFusion were about 3 times a day Apache will go to MaxClients (set at 250) and hang. We believe it is a ColdFusion related issue but for now the easiest way to keep things running is to have a cron job that tests if Apache is alive by retrieving a web page and if not, reboot Apache. By any chance would anyone have a script to reboot Apache that we could use as a starting point?
    Thanks,
    Don

  2. #2
    Join Date
    Jun 2002
    Location
    United Kingdom
    Posts
    1,238
    working on it as we speak

    you do have php installed on the system, yes?

  3. #3
    Join Date
    Jun 2002
    Location
    United Kingdom
    Posts
    1,238
    couldn't edit my above post, because i posted it over 15 minutes ago. anyway, here is PHP code i wrote to restart apache if its down.

    now, set a cron job to run it, in the following format

    /path/to/php/binary /path/to/php/file > /dev/null

    the script outputs error that it encounters with apache, and the time it happened. so if you want to know when apache died, use this command in cron instead:

    /path/to/php/binary /path/to/php/file > /path/to/log/file

    now, remember, your restarting apache, so you need to run the script as the user you normal run apache under, or restart apache under.

    anyway, here is the code i promised:

    PHP Code:
    <?php

    /*****************************************/
    /***     Apache Response Checking      ***/
    /*****************************************/

    /*
    ** First, i need to know a bit about the server.
    ** give me a domain, and a file to download.
    ** and the command used to restart apache.
    */

    // Domain to connect to:
    $test_domain "thedigitaldream.co.uk";

    // File to download:
    $test_file "index.php";

    // Command to restart apache
    $restart_cmd "apachectl restart";

    /*****************************************/
    /*** You wont need to modify anything  ***/
    /***        past this point.           ***/
    /*****************************************/

    /*
    ** Store current time in a var, used for logging
    */
    $current_time gmDate("H:i - d/m/y");

    /*
    ** Create a connection to the server. if this
    ** fails, we cant even connect to the host.
    ** so we will force the apache restart.
    */

    if(!$apache_handle = @fsockopen($test_domain80))
    {
      
    // Apache is down, restarting it.
      
    $result shell_exec($restart_cmd);
      echo(
    $current_time." - Cant connnect to apache, Restarting Apache\n");
    }
    else
    {
      
    // We are connected to apache, great.... lets
      // see if we can grab the test file from the
      // server though.
      
      // Generate a request with the above information
      
    $http_request "GET ".$test_file." HTTP/1.1\r\n";
      
    $http_request .= "Host: ".$test_domain."\r\n\r\n";
      
      
    // Send the request to the server:
      
    fputs($apache_handle$http_request);
      
      
    // Get back the response (if any).
      
    $http_response fgets($apache_handle);
      
      if(!
    $http_response)
      {
        
    // No response back, lets restart apache
        
    $result shell_exec($restart_cmd);
        echo(
    $current_time." - No http response, Restarting apache\n");
      }
      
      
    // End Of Test
    }

    /*
    ** Coded on 28th, Feb, 2004 by Matthew Jones.
    */ 

    ?>
    i can re - write this in perl, or c++ if needed.

    Matt.

  4. #4
    Matt,

    Yes, we have PHP, pearl and C++ all installed.

    I can not thank you enough for going to the trouble to do this!!!
    You are a life saver (well at least a job saver - mine).

    I'll get this coded up and installed.

    Again THANK YOU!!!
    Don

  5. #5
    Join Date
    Jun 2002
    Location
    United Kingdom
    Posts
    1,238
    ill keep an eye on this thread...

    if you get any problems, let me know and i will try sort it

    and dont worry, it was no problem to do, glad to help

    Matt.

  6. #6
    Matt, not sure you are still checking this, but if you are, your code works GREAT!!!! Thank you so much. We are still hitting MaxClients but now we don't hang long in that condition.

    Regards,
    Don
    Freedom Networking Solutions, Inc.
    www.freedomnetworking.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •