hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Testing and Restarting Apache
Reply

Forum Jump

Testing and Restarting Apache

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 02-27-2004, 08:37 PM
FreedomNet FreedomNet is offline
Junior Guru Wannabe
 
Join Date: Jan 2002
Posts: 62

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



Sponsored Links
  #2  
Old 02-28-2004, 04:22 PM
matt2kjones matt2kjones is offline
Web Hosting Master
 
Join Date: Jun 2002
Location: United Kingdom
Posts: 1,236
working on it as we speak

you do have php installed on the system, yes?

  #3  
Old 02-28-2004, 04:58 PM
matt2kjones matt2kjones is offline
Web Hosting Master
 
Join Date: Jun 2002
Location: United Kingdom
Posts: 1,236
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.

Sponsored Links
  #4  
Old 02-28-2004, 06:20 PM
FreedomNet FreedomNet is offline
Junior Guru Wannabe
 
Join Date: Jan 2002
Posts: 62
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  
Old 02-28-2004, 06:32 PM
matt2kjones matt2kjones is offline
Web Hosting Master
 
Join Date: Jun 2002
Location: United Kingdom
Posts: 1,236
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  
Old 03-03-2004, 05:15 PM
FreedomNet FreedomNet is offline
Junior Guru Wannabe
 
Join Date: Jan 2002
Posts: 62
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

Reply

Related posts from TheWhir.com
Title Type Date Posted
Apache Market Share Falls in Netcraft October Web Server Survey Web Hosting News 2013-10-04 14:34:11
Apache Market Share Dips Slightly in June Netcraft Web Server Survey Web Hosting News 2013-06-06 13:40:21
Researchers Urge System Admins to Check for New Apache Web Server Backdoor Malware Web Hosting News 2013-05-01 11:35:53
CloudStack 4.0 Open Source Cloud Software Released as Apache Incubator Project Web Hosting News 2012-11-08 13:54:10
MochaHost Enhances Server Performance with Tomcat Native Library Accelerator Web Hosting News 2012-08-01 15:35:20


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?