Welcome to WebmasterWorld Guest from 54.226.241.8

Forum Moderators: bakedjake

Message Too Old, No Replies

shell script to restart apache when no. of processes keeps growing

Can I have your help?

     

Jo555

5:36 am on Mar 6, 2007 (gmt 0)

5+ Year Member



I need a shell script to kill apache and restart it, in case the number of processes keeps growing. The logic is like the below, but I don't know how to get the number and neither the syntax. Could somebody kindly help?

if no_of_processes (ps ax ¦ grep httpd) > 200
then
killall httpd
apachectl start

bcc1234

6:02 am on Mar 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PROC_COUNT=`ps aux ¦ grep <apache process name> ¦ wc -l`
if [ "${RPOC_COUNT}" -gt "200" ]
then
whatever here
fi

But you really have bigger issues if the number of processes keeps growing. A script like that is a bad solution.

Jo555

11:38 am on Mar 6, 2007 (gmt 0)

5+ Year Member



Thank you so much for the script, bcc1234. It's going to be my first shell script.

Yes the real issue is bigger, but I have no clue why the number of processes keep growing and can't be killed automatically by the system.
When that happens, there are accordingly growing number of records like those below in the httpd log file.

[Mon Mar 05 16:08:15 2007] [warn] child process 24829 still did not exit, sending a SIGTERM
and
[Mon Mar 05 16:08:21 2007] [error] child process 24829 still did not exit, sending a SIGKILL

I think it has something to do with mysql, because at the early stage before the server is brought down, dynamic pages using mysql slow down while static pages of plain text still respond normally.

At the moment I simply don't know what I can do to get closer to finding out what is the origin of the issue. Can anybody give me some advices or suggestions or any comments?

nalin

3:41 pm on Mar 13, 2007 (gmt 0)

10+ Year Member



In lieu of the shell script you could try something like "monit".

As far as having a large number of open threads - you might want to check your http.conf and make sure keepalive is disabled or has a very low timeout.

Keepalive makes a thread that serves up a page stay open (to respond to other requests for more pages or css or js or images). Generally you will get MUCH improved performance out of apache if you use it for dynamic content only (which makes keepalive useless because apache will be generating only a single request per page) and serve up js, css, images, and other static stuff via something more lightweight (I use squid in reverse proxy mode).

 

Featured Threads

Hot Threads This Week

Hot Threads This Month