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
Thank you all so much for the help. With your help I think I can write my first shell script, which I hope will avoid the issue.
The real issue is 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 have no clue why the number of processes keep growing and can't be killed automatically by the system.
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?
Thanks sb008, do you any suggestion?
The problem is that when the number of processes grows abnormally, finally not only apache but also the whole server can be brought down.
By now I haven't found out the cause, but just thought that at lease I can save the server from being down by using kill or killall. I really have no better idea at the moment.
I know that kill command is not the best bet to stop a process...but,I have observed in many such kind of cases that kill 'is a better choice' as stopping the process using the 'decent way' might end up in many 'zombie' processes...
Thanks ZB, you are absolutely right.
I tried to change MaxClients, but because the number of processes grows almost infinitely, I know something must be wrong which is causing the issue.
Sadly I only know it should has something to do with mysql, but no idea how to get closer.
This is most likely to obtain for orocess which are started, to put it simple, with the nohup option. When the initional "httpd" daemon dies, parenthood for all child "httpd" daemons is passed over to the "init" process.
This is bug sensitive.
Therefore a kill, as shown, will more likely cause zombie processes since the order in which the "httpd" daemons are killed is random meaning the parent "httpd" is almost for sure killed before at least some of the "httpd" child processes.
Furthermore a "kill -9" might result in a not proper cleaning of the resources which are used by the process. When killing enough processes like that, at some stage the system will end up with an internal chaos which can cause all kind of unexpected/unwanted behavior like zombie processes starting to occur.
The "kill -9" is meant for when all other options fail, and surely not as first option.
I used 'killall httpd' to kill all 'httpd' processes and start apache again. So far it's working well. I know little about killall command except for it killing all the processes.