Script to restart apache when running out of memory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to restart apache when running out of memory
# 1  
Old 10-27-2012
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 server get out of memory and trying to use swap or after using swap more than 500MB, for example?


Thanks
# 2  
Old 10-27-2012
A cronjob can read the pid file, invoke ps, and then run the apache restart script if necessary. Alternatively, the cronjob can simply restart the webserver on a fixed interval.

More importantly, if your web server is consuming memory unboundedly, it is either misconfigured or buggy. If you don't know why it's happening, you should.

Regards,
Alister
# 3  
Old 10-28-2012
Thanks Alister,

Instead of using cronjob, which schedule a task/script to be running based on pre-determined time, I want to restart the apache based on memory consumption. So, for example, if memory consumption reach 4GB, then restart the apache. I need a bash script to do this job.

Yes, I have to find the root cause of the problem but I need a temporary solution for this issue in order to keep the web server up.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Red Hat

Service restart and check if running

Hello, I'l like to create a script that restart a service (/etc/init.d/httpd restart) and also check if after restart the service is actually running. Sometimes it happen that at the first try the service fails to restart. Thanks (2 Replies)
Discussion started by: bazzola
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. Shell Programming and Scripting

Error while running restart script -

Hi All I have written below basic restart script but it is giving me the following error - error - syntax error at line 40 : `else' is not matched . below is the script can someone assist me what i am doing wrong - #!/bin/ksh cd bin . ./set_sysm sleep 60 ./swstop -f 0 ... (1 Reply)
Discussion started by: honey26
1 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

Running a shell script in apache

I have a shell script, that works when ran in the shell. When placed in the cgi-bin directory, it doesn't work as expected. Looking at the logs, it seems that some environmental variables are not being passed. My apache user is www. For simplicity, here is a sample script I want to run ... (2 Replies)
Discussion started by: streetfighter2
2 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

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... (14 Replies)
Discussion started by: _joshua_
14 Replies
Login or Register to Ask a Question