| Cfare ju duhet te dini? |
|
#1
| ||||
| ||||
| How to check if Apache is running & restart via cron job? First, I've had to create a shell script named apachetest on my system: #!/bin/sh run=`ps ax | grep /usr/sbin/httpd | grep -v grep | cut -c1-5 | paste -s -` if [ "$run" ]; then echo "Apache is running" else /etc/init.d/httpd start fi The sections in bold above are where I had to make modifications of the initial script to get it to work properly on my RHEL5 system. In the first section, the initial ps command was running simply this: ps ax | grep httpd | grep -v grep | cut -c1-5 | paste -s - However, after checking why it wasn't restarting properly, I ran the command while the Apache web server was up, and got a list of about a dozen process ids, so that seems fine, but when I manually stopped the web server, and ran the same command, I was still getting 2 processes listed. After investigating, I had a couple of other processes that had the term "httpd" in the path, so the command above was pulling those, and considering that they were web server processes as well. So I pulled up the full process list, and determined that if I used the full path that was present in each of the true web server processes, I was able to run the check properly, so my final command looked like this: ps ax | grep /usr/sbin/httpd | grep -v grep | cut -c1-5 | paste -s- I also changed the last bold section to execute the proper httpd startup command on the system. It was unable to use the "service httpd start" command that I normally use on the command line and what is standard with Ensim systems, so I had to use the full path to the actual startup script which was /etc/init.d/httpd start. Now, to set up the cron that we will use to run this script automagically, you can edit the crontab from the command line by executing the command "crontab -e". I'm choosing to run this script once every single minute without fail. I'd like my web server to never be down for more than 60 seconds. This may not be the most processor friendly way to do this, however, the example I found was doing it every 10 minutes, but if my server is down for 10 minutes, I have lost money. And I don't cherish the idea of losing money... do you? To run the cron every minute, you would add the following line to your crontab: * * * * * /path/to/your/apachetest You can find more information on setting up a cron job at wikipedia. Here's a few easy samples I'll go ahead include for common requests: ---- will run every 5 minutes */5 * * * * /path/to/your/apachetest ---- will run every 10 minutes */10 * * * * /path/to/your/apachetest Thanks to Jake Strawn's blog for this usefull tips.
__________________ The heaven's sound is composed inside your heart, listen to its beat to syncronize your life onto the angel's steps. |
![]() |
| Bookmarks |
| Alternativa Teme | |
| Vleresojeni kete Teme | |
|
|