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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help: shell script to restart apache when no. of processes keeps growing
# 1  
Old 03-06-2007
need help: shell script to restart apache when no. of processes keeps growing

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

I'm using Fedora Core3
# 2  
Old 03-06-2007
Code:
if [ `ps -fu $USERNAME  | awk '/processname/ { x++ } END{print x}'` > 200 ]
then
 echo "exceeded"
 #do killall and restarting
fi

# 3  
Old 03-06-2007
[[ $(ps -ax | grep httpd| wc -l) -gt 200 ]]&& { kill -9 $(ps -ax | grep httpd | awk '{ print $1; }'); apachectl start; }
# 4  
Old 03-06-2007
# 5  
Old 03-06-2007
Quote:
Originally Posted by jacoden
[[ $(ps -ax | grep httpd| wc -l) -gt 200 ]]&& { kill -9 $(ps -ax | grep httpd | awk '{ print $1; }'); apachectl start; }

kill -9???????????????????????????
# 6  
Old 03-06-2007
killall httpd -------------> I assumed killing all the httpd processes...
# 7  
Old 03-06-2007
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to restart shell script when cpu is 0.0%?

Hello, My operating system is ubuntu 16.04. I need to kill or restart a shell script when cpu usage of related process is equal to 0.0% for X seconds. Appearing name on top page is vlc While surfing on forums, I found below script but not sure how to edit: Also don't know the function of -gt... (7 Replies)
Discussion started by: baris35
7 Replies

2. Red Hat

Apache service not coming up after restart

When I update the server with new SSL certificates, and restart httpd, I get errors : # service httpd restart Stopping httpd: rm: cannot remove `/usr/local/apache2/bin/httpd/logs/httpd.pid': Not a directory Starting httpd: ... (0 Replies)
Discussion started by: anaigini45
0 Replies

3. Red Hat

Error Restart apache

Hi Im apache service restart Error $ service httpd reload Reloading httpd: service httpd reload Reloading httpd: service httpd start Starting httpd: (98)Address already in use: make_sock: could not bind to address :80 (98)Address already in... (1 Reply)
Discussion started by: mnnn
1 Replies

4. Shell Programming and Scripting

Script to restart apache when running out of memory

Hi, I have a problem with running out of memory in my Ubuntu web server (4GB RAM) because many people try to access my server. I used to restart manually my apache server to clear out the memory & swap. Can anyone tell me how to write bash script that can automatically restart apache when... (2 Replies)
Discussion started by: nica
2 Replies

5. Shell Programming and Scripting

Help scripting to start, check, and restart processes

Here it goes from my unexperienced point of view. I am using CentOS 5.6. I have a Java based server that needs to be running 24/7/365. To begin from the machine the server is on rebooting; I SSH in to a shell, cd to the server dir, screen -S server1, and execute ./exec (listed below) in the screen.... (12 Replies)
Discussion started by: MacG32
12 Replies

6. Shell Programming and Scripting

How to keep process running after apache restart.

I have posted this on the Web subforum but it seems that nobody knows to do this, maybe someone has a solution here. Thank you I have a PHP application that starts a couple of processes on the server...the problem is that if I restart apache those running apps will die. How can I start them... (1 Reply)
Discussion started by: valiadi
1 Replies

7. Web Development

How to keep process running after apache restart.

Hi, I have a PHP application that starts a couple of processes on the server...the problem is that if I restart apache those running apps will die. How can I start them in a way that they are not killed when I restart/stop apache ? $cmdstr = "nohup ".$config."/".$config."... (6 Replies)
Discussion started by: valiadi
6 Replies

8. Shell Programming and Scripting

Restart Logic for a Korn Shell Master Script

Hello All, I was wondering if someone can help me to develop restart logic for a Korn Shell program (a master script) that I am developing. The program is design to invoke a series of child processes (Korn Shell Scripts) whose function is to create a series of load files on a specified mount... (0 Replies)
Discussion started by: jonesdk5
0 Replies

9. Web Development

Can't restart apache. PHP is broken.

I need to restart my apache, but apachectl configtest tells me that Syntax error on line 208 of /etc/httpd/conf/httpd.conf: Cannot load /usr/local/apache/libexec/libphp4.so into server: /usr/local/apache/libexec/libphp4.so: undefined symbol: ap_signal I've tried rebuilding php, I'm not... (2 Replies)
Discussion started by: tatebn
2 Replies

10. Shell Programming and Scripting

suspend/restart a process in shell script

Hi, I have a task that Im stuck on. I have an elementary script named 'myscript' that prints "the script is running" once a second. It runs for 27 seconds. I need to write a 2nd script that starts 'myscript' and takes a parameter '$1' for a number. my 2nd script then needs to pause myscript... (1 Reply)
Discussion started by: daneensign
1 Replies
Login or Register to Ask a Question