auf meinem rootserver läuft ein apache, mysql und ein paar php und bash-voodoo-scripte.
die apache-vhosts sind in der mysql-datenbank abgebildet und ein php-script erstellt via cronjob alle vhost-dateien neu (bei bedarf).
anschliessend muss noch der apache neu geladen werden, damit die config auch übernommen wird.
dafür habe ich mir folgendes kleines script geschrieben:
Code: Select all
#!/bin/bash
# reload_apache_config.sh version 0.4
version=0.4
# this script checks if apache vhost-files have changed
# from md5 hashes stored in a md5sum-output file
#
# mailto: Tristan Cebulla <equinox@lichtspiele.org>
# path to md5file which should be used
md5_file=/data/www/system/md5/apache_vhost_files.md5
# remove # to enable debug messages in cronjobs
# or call export DDEBUG="yes" && reload_apache_config.sh --option
#DDEBUG="yes"
# do not change code from here...
function debug {
# TERM environment is set to dumb in cronjobs
if [ "$TERM" != "dumb" ]; then
echo "$@"
else
if [ ${DDEBUG} ]; then
echo "$@"
fi
fi
}
function gen_new_md5 {
for file in $@; do
if [ -f $file ]; then
md5sum $file >> $md5_file
debug " * indexing: adding $file"
else
debug " * indexing: not adding $file"
fi
done
}
function print_md5 {
awk '{ print $2 " -> " $1; }' $md5_file
}
function check_update {
md5sum -c $md5_file >/dev/null 2>&1
if [ $? != "0" ]; then
files=`awk {'print $2'} $md5_file`
rm $md5_file 2>&1 /dev/null && debug " * deleting original md5 file"
gen_new_md5 $files
reload_apache
else
debug " * apache needs not to be reloaded"
fi
}
function reload_apache {
/etc/init.d/apache2 configtest >/dev/null 2>&1
if [ $? == "0" ]; then
debug " * syntax ok"
/etc/init.d/apache2 reload >/dev/null 2>&1
debug " * apache has been reloaded"
debug " * new config is active"
else
debug "error while reloading new vhost-config"
debug "new config NOT active!"
debug "see /var/log/apache2/startuperror.log for details"
if [ "$TERM" == "dumb" ]; then
echo " * error loading apache vhosts on $HOSTNAME !"
fi
fi
}
debug "apache config reloader $version (cronjob edition)"
case "$1" in
--index)
if [ "$2" == "" ]; then
debug "no file(s) given for indexing"
exit 1
fi
if [ -f $md5_file ]; then
debug " * existing md5 file found, backuping to ${md5_file}.old"
mv $md5_file ${md5_file}.old
fi
gen_new_md5 $@
;;
--print)
print_md5
;;
--reload)
reload_apache
;;
--force-reload)
/etc/init.d/apache2 reload >/dev/null 2>&1
debug " * apache forcereloaded"
;;
--check)
if [ ! -f $md5_file ]; then
debug "md5 list $md5_file does not exist!"
debug "please run $0 --index file [file] as root"
exit 1
fi
check_update
;;
--help|*)
echo "usage: $0 [option] [file] [..]"
echo ""
echo " --check : reload apache only if necessary"
echo " --index file : create new checksum of the given files"
echo " --print : print out md5/file list"
echo " --reload : reload apache with configtest"
echo " --force-reload : simply reload apache"
;;
esac
## die gracefully
exit 0
#:set tabstop=4als erstes sollte man jedoch den index erstellen, das macht man mit reload_apache_config.sh --index datei1 datei2 datei3 ...
der rest ist oder sollte zumindest selbsterklärend sein, bei fragen fragen

