Restart that unrully Apache service
We are running about two dozen of Apache servers and from time to time they tend to croak. They are normally extremely stable and reliable, however about once a month, sometimes more often, they refuse to serve pages and hurl out status code 500. I did some tracing and tinkering around and found that this behavior is sometimes associated with a surge in traffic, other times it still remains a mystery to me. Apache is one hell of a beast...
Quick fix to this problem is a simple restart of the Apache web service. This somehow fixes Apache and the servers are good for another month or so. The problem is that when this problem happens, I am usually away from my desk and unable to issue a restart command. Sometimes I won't notice for hours that something went wrong, other times I get angry calls. Well, I am sure you get the picture... So using Mango Monitoring Service I created a simple automation tool that takes care of this and I have one less thing to worry about. Other people out there might be facing the same or similar problem, so this article might come in handy.
Mango Monitoring Service will remotely monitor various services on your servers and let you know if something goes wrong. It also gives you an access to useful web APIs you can use to create your own automation tools. I have used the XML export web service and a simple Perl script to create a simple tool that makes my life easier. Here is a short how-to:
Create a file on your server in your preferred script directory called mango.pl. I have put mine into /scripts/mango.pl. Paste the following code into it and run chmod 755 on it:
#!/usr/bin/perl
#PURPOSE: Restart apache on specific status code
# use modules
use XML::Simple;
use LWP::UserAgent;
use strict;
# create variables
my ($host_id, $key, $window, $status_code, $type_code, $url, $data, $xml, $ua, $req, $res, $event);
$host_id = 1111; # set to your host id
$key = "5555-abcdef"; # set to your API key
$window = 12; # how far into the past you want to go (in hours)
$url = "http://www.numango.com/web/manage_servers/".
"export/format/xml/host_id/$host_id/".
"window/$window/key/$key";
$status_code = 500; # your trigger code
$type_code = 3; # code 3 are HTTP codes
# create objects
$xml = new XML::Simple(forcearray => 1);
$ua = new LWP::UserAgent;
$req = new HTTP::Request GET => $url;
# check if we got data
print "Fetching XML data...\n";
$res = $ua->request($req);
if ($res->content eq "Invalid key!")
{
die("Invalid key!");
}
# read XML file
print "Reading in XML data...\n";
$data = $xml->XMLin($res->content);
# process XML data
print "Processing XML data...\n";
foreach $event (@{$data->{event}})
{
if (($event->{type_code}[0] == $type_code) && # we are only interested in HTTP codes
($event->{alert_note}[0] == $status_code) && # we want to trip on this status code
((time()-$event->{date_unix}[0]) <= (10*60)) # we only care about events <= 10 minutes old
)
{
print "Status code $status_code detected @ ".localtime($event->{date_unix}[0])."\n";
print "Restarting Apache server...\n";
system("/usr/sbin/apache2ctl restart");
# we only care about the most recent one, so quit the loop after first restart
last;
}
}
# exit
print "Done!\n";
exit(0);
You will need XML::Simple and LWP::UserAgent for this to work. You can get both easily if you are using apt-get (apt-get install libxml-simple-perl libwww-perl). Modify $host_id to match the ID of the server you want to monitor, $key is your webAPI key that can be found under My Account. $window defines how far into the past you want to look (in hours). I wouldn't worry about anything older than couple of hours, so I put 12. $status_code contains the code you want the server to restart on. This can be easily expanded to an array and you can restart on more than one status code (e.g. 501 and 502). And that's it. Now run it and you should get something like this:
[root@host: /scripts]# ./mango.pl
Fetching XML data...
Reading in XML data...
Processing XML data...
Done!
If error was detected then you will get this:
[root@host: /scripts]# ./mango.pl
Fetching XML data...
Reading in XML data...
Processing XML data...
Status code 500 detected @ Mon Nov 19 17:20:42 2007
Restarting Apache server...
Done!
The last piece of the puzzle is to have this script run periodically, I opted for it to run every five minutes. Thus I edited /etc/crontab and added the following line. You can select interval that fits your needs. Note: you should match the polling interval that you have selected for your server on the Mango website.
0-59/5 * * * * root /scripts/mango.pl
Voila! I hope this little how-to helps you. You can expand this to reboot any service like SMTP, DNS or anything that Mango lets you monitor.
Comments
Also search shared Images, Vidoes, MP3, Movies, Softwares and Photos on other sharing host ,
Good ! I like it ! Welcome to read following news
everybody, take your time and a little bit.
Now I introduce a website
http://www.oppell.com is specialized in online service on Prada Shoes,Christian Louboutin Shoes,Coach Shoes,Ed Hardy,Gucci Shoes,Jimmy Choo Shoes,Lacoste Shirts,Lacoste Shoes,LV Shoes,Paul Smith Shoes,Sebago Fashion Shoes and UGG boots.
_________________________$$$$$$$__________
______________- __________$$$$$$$$$$________
________________________$$$$$$- $$$$$_______
_________________________$$$$$$$$$$$______
__- ________________________$$$$$$$$$$$_____
__________________- ___________$$$$$$$$$____
___________________________$$$$$$$- $$$_____
http://www.oppell.com/ $$$$$$$$$$$$$____
________________$$$______$$$$$$$$$$$$$$__- _
______________$$$$$$$$_____$$$$$$__$$$$$__
_____________- $$$$$$$$$$_____$$$$____$$$$$_
___________$$$$$$_$$$$$$$$__$- $$$______$$$$
__________$$$$$_____$$$$$$$$_$$$$_______$$$
- ___ _____$$$$$_________$$$$$$$$$$$$_______$$$
_______ $$$_____________$$$$$$$$$$$________$$$
_____$$$__ ______________$$$$$$$$$$________$$$$$$
Air jordan(1-24)shoes Save: 32% off
UGG boota Save: 40% off
Tshirts (Polo ,ed hardy,lacoste) Save: 38% off
Bikini (Ed hardy) Save: 32% off
FREE SHIPPING
============ http://www.oppell.com/ =============
Founded in 1994 by Pamela Skaist-Levy and Gela Taylor, as a premium designer, marketer and wholesaler of sexy, sophisticated basics for women, Juicy Couture is recognized around the world as a leading contemporary brand of casual lifestyle clothing,go to pick items from Cheap Juicy Couture T Shirts now!
Moncler Nantes Hooded Down Coat - Gold
Moncler Nantes Hooded Down Coats - Gold
Moncler Quincy Women Down Jacket - Black
Moncler Quincy Women Down Jacket - Black,All products have good quality,fast and safe delivery without shipping fee. Our primary goal is to meet our clients’ requirement and establish mutually pleasant business relationships with you.If you are interested, please do not hesitate to contact us.
Christian Louboutin Mouskito Pump
Christian Louboutin Natural Python Alti Platform Pump
Christian Louboutin New Shoes 200904
Christian Louboutin Open Clic Leopard Pumps
,All products have good quality,fast and safe delivery without shipping fee. Our primary goal is to meet our clients’ requirement and establish mutually pleasant business relationships with you.If you are interested, please do not hesitate to contact us.
MAC 12 Eyeshadow 0009
MAC 12 Eyeshadow 0010
MAC 12 Eyeshadow 0011
MAC 12 Eyeshadow 0012,All products have good quality,fast and safe delivery without shipping fee. Our primary goal is to meet our clients’ requirement and establish mutually pleasant business relationships with you.If you are interested, please do not hesitate to contact us.
Christian Louboutin Escatin Sandals
Christian Louboutin Gold Libelle Sandals
Christian Louboutin Josefa - Black Gold
Christian Louboutin Josefa - Pewter,All products have good quality,fast and safe delivery without shipping fee. Our primary goal is to meet our clients’ requirement and establish mutually pleasant business relationships with you.If you are interested, please do not hesitate to contact us.
Louis Vuitton handbags
Chanel Handbags
Gucci Handbags
Hermes Handbags
Balenciaga Handbags
Bottega Veneta Handbags
Chloe Handbags
Coach Handbags
Dior Handbags
Fendi Handbags
Dolce & Gabbana Handbags
Hermes Handbags
Versace Handbags
Prada Handbags
Gucci Casual Leather Shoes--Dark Brown With Logo
Gucci Casual Leather Shoes--Orange And Yellow
Gucci Casual Leather Shoes--Red And Black
Gucci Casual Leather Shoes--White And Black ,All products have good quality,fast and safe delivery without shipping fee. Our primary goal is to meet our clients’ requirement and establish mutually pleasant business relationships with you.If you are interested, please do not hesitate to contact us.
I bought this The North Face Jackets for my husband. Usually, he is a
The North Facesize LG, but when this
north face jacket outletarrived it fit a bit big. It fit wider than normal, and the sleeves seemed longer. I exchanged it for a MD, and he loves it. It's thicker and much warmer than the regular North Face Denali. I liked it so much I got myself one in a small. I love this North Face Nuptse.Share it to you(http://www.northface-jackets.com/the-north-face-men-dena- li-hoodie-red-product-173.html). Definitely north face windwear jacket and keeps you warm at the same time.
at Rosetta Stone Outlet.
Founded in 1994 by Pamela Skaist-Levy and Gela Taylor, as a premium designer, marketer and wholesaler of sexy, sophisticated basics for women, Juicy Couture is recognized around the world as a leading contemporary brand of casual lifestyle clothing,go to pick items from Cheap Juicy Couture T Shirts now!
Christian Louboutin Fifre Suede Ankle Boot Grey
Christian Louboutin Fifre Suede Ankle Boot Red
Christian Louboutin Forever Tina
Christian Louboutin Forever Tina boots black
Christian Louboutin Fringe short Boots
Christian Louboutin Fringe short Boots
Christian Louboutin Ginevra Tall Suede Boots
Christian Louboutin Globe 100 suede boots
Christian Louboutin Globe 100 suede boots black
Christian Louboutin Fontanette Pink Suede Pumps
Christian Louboutin Fontanette Sand Suede Pumps
Christian Louboutin Gino T-strap Pumps Black
Christian Louboutin Gino T-strap Pumps Gold
Christian Louboutin Gino T-strap Pumps Pink
Christian Louboutin Gold Leather High Heel Sandals
Christian Louboutin helmut Black Pumps
Christian Louboutin Hidden-Platform Pump Leopard
Christian Louboutin Ivory Toe Platform Pumps
Juicy Couture Handbag in red
Juicy Couture Handbag in black
Juicy Couture Handbag in pink and black
Juicy Couture Handbag in blue
Juicy Couture Handbag in brown
Juicy Couture Handbag in yellow
Juicy Couture Handbag in yellow
Juicy Couture Handbag in rose
Juicy Couture Handbag in pink
Previous entries
VIVO kartička (views: 9157)
VIVO podľa tvojho gusta (views: 2239)
Nová verzia portálu VIVO.sk (views: 2287)
Restart that unrully Apache service (views: 30890)
Web API dostupné na serveri Kukaj.sk, časť druhá (views: 10433)
Web API dostupné na serveri Kukaj.sk, časť prvá (views: 3660)
Staraj sa o seba ty faking magor (views: 7096)
URL Rewriting, zjednodušene a rýchlo (views: 5392)
Dávid |

