Apache – restarting the server when max clients is reached.

Apache top data

Sharing is caring!

Apache is the most popular web server with over 50% of servers using it to serve their web sites. We currently use it to serve a web site we manage for a client. This website was having issues where an http get request was being generated every 6 seconds and causing the server to spawn child process like crazy until it eventually become unusable. The issue was causing some problems for the end users and was becoming a problem that needed fixed.

 

Apache

 

We were unable to find a quick solution to the problem so we had to create a short term fix that would allow us to diagnose the problem while trying to keep as much uptime as possible. As the server was spawning child threads until it would stop responding, so we created a script that would measure the amount of processes owned by Apache and then restart the server if a certain limit was reached. This would allow the server to keep working with minimal downtime while we looked into what was causing all the requests.

 

The first thing we wanted to do with this script was to monitor the Apache processes. We did this by using a crontab entry to run a script once every 5 minutes. Then in the script we get a list of all processes that are created by the server and get a count. If the count is larger than the set limit we would stop the server, kill all server processes and then start the server again.

 

We also wanted to add an email to notify us of the event and pass along some data from the logs. The script below is what we created to monitor the server and email the logs when the clients reached max limit.

 

 

Sharing is caring!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.