Information and Links
Join the fray by commenting, tracking what others have to say, or linking to it from your blog.
Safe auto restart for httpd after updating httpd.conf for apache
If you modify your apache /etc/httpd/conf/httpd.conf configs as often as I do, you will know it is a bit tedious to constantly test for valid syntax in the httpd.config and then restart apache if all is good. With the help of a couple of friends I came up with this bash function:
-
httpdreload () {
-
configtestresults=`/etc/init.d/httpd configtest 2>&1`
-
if [ "$configtestresults" == "Syntax OK" ]; then
-
echo 'HTTPD config valid... reloading now.'
-
/etc/init.d/httpd reload
-
echo 'HTTPD reloaded'
-
else
-
echo $configtestresults
-
fi
-
}
Place this in your own users .bashrc file, then either log out of your shell and back in, or run source .bashrc.
In a nutshell, you simply type httpdreload at the command prompt in your bash shell. The function will get called and will first test if the Syntax is okay or not. If it is not okay, the script will exit with the error. If the Syntax of your httpd.conf file is okay, it will then proceed to restart apache.


The title should have read “Safe auto reload” and not restart.