Admin Mistakes: Apache Reload and Log Files
Background
So, you have a request to upload and configure a new website on some specific web server. The policy is to have a separate configuration file for each website (each new virtual host) under /etc/httpd/conf.d/ directory.
Problem
After finishing writing of the configuration file (which was about 200 lines due to numerous special requirements) you run the following command
# /etc/init.d/httpd configtest Syntax OK
in order to check that there is no syntax error. And then you reload the Apache’s configuration…
# /etc/init.d/httpd reload Reloading httpd: [ OK ]
However, when you check for the running Apache processes you see that it is not running.
# ps -C httpd PID TTY TIME CMD #
Now, let’s move to the next section to see what caused this problem.
Mistake
After having another look at the newly added configuration I noticed that the ‘ErrorLog’ directive was pointing to an invalid directory due to a typo. If Apache is not able to access the configured log files, it won’t start and this is what happened.
Resolution
Since each web server could host numerous websites and these were maintained by many different people, I wrote the following simple shell script that reports any missing log files.
#!/bin/sh HTTPD_CONFS="/etc/httpd/conf.d/*.conf" HTTPD_DIR="/etc/httpd" RET=3 cd $HTTPD_DIR function test_if_exists () { if [ -f $1 ]; then RET=0 else RET=1 fi } function gimmie_the_dirs () { LFILES=$(egrep '^ErrorLog|^CustomLog' $1 | awk {'print $2'} | tr '\n' ' ') } for i in `ls $HTTPD_CONFS`; do gimmie_the_dirs $i for j in $LFILES; do test_if_exists $j if [ $RET -eq 1 ]; then echo -en "ERROR: $j does not exist\n" fi done done
This was later integrated in some shell scripts used for adding new websites and we never had this problem again.
Leave a Reply