Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index International Gentoo Users Deutsches Forum (German) Deutsche Dokumentation
  • Search

kleines apache-reload-script

Dokumentation, Tipps und Tricks.
Post Reply
  • Print view
Advanced search
5 posts • Page 1 of 1
Author
Message
equinox0r
l33t
l33t
User avatar
Posts: 614
Joined: Wed Feb 18, 2004 12:39 am
Contact:
Contact equinox0r
Website

kleines apache-reload-script

  • Quote

Post by equinox0r » Tue Feb 28, 2006 9:39 am

folgendes szenario:

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=4
in meinen cronjobs wird es alle 5 minuten via reload_apache_config.sh --check aufgerufen.

als 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 :)
AMD 2400+ XP | 1024 MB RAM | ATI Radeon 9600Pro
Gentoo Base System version 1.4.16 | Portage 2.0.51.19 | 2.6.11-gentoo-r9 Kernel
Top
xces
Guru
Guru
User avatar
Posts: 515
Joined: Fri Oct 11, 2002 7:23 pm

Re: kleines apache-reload-script

  • Quote

Post by xces » Tue Feb 28, 2006 5:36 pm

equinox0r wrote:die apache-vhosts sind in der mysql-datenbank abgebildet und ein php-script erstellt via cronjob alle vhost-dateien neu (bei bedarf).
net-www/mod_vdbh bzw. mod_vhost ;)
Funktioniert auch ohne Cronjob und Apache Reload bei jeder Änderung.
Top
equinox0r
l33t
l33t
User avatar
Posts: 614
Joined: Wed Feb 18, 2004 12:39 am
Contact:
Contact equinox0r
Website

  • Quote

Post by equinox0r » Tue Feb 28, 2006 10:08 pm

mod_vhost kenne ich schon und nutze es deshalb nicht, weil ich die vhosts viel spezieller konfigurieren möchte als es dieses modul kann :/ das ist dann auch der grund weshalb ich eine eigene lösung verwende ;)

deinen ersten vorschlag kenne ich nicht und leider ist deren seite down sodass man sich das gar nicht anschauen kann :( ich werds aber schnell testen, danke für den hinweis ;)
AMD 2400+ XP | 1024 MB RAM | ATI Radeon 9600Pro
Gentoo Base System version 1.4.16 | Portage 2.0.51.19 | 2.6.11-gentoo-r9 Kernel
Top
equinox0r
l33t
l33t
User avatar
Posts: 614
Joined: Wed Feb 18, 2004 12:39 am
Contact:
Contact equinox0r
Website

  • Quote

Post by equinox0r » Tue Feb 28, 2006 10:24 pm

also, ich habs mir angeschaut. pro domain/subdomain muss immernoch ein extra vhost eintrag erstellt werden (wenn ich das richtig verstanden habe):

Code: Select all

<IfModule mod_vdbh.c>

  #NameVirtualHost 206.9.161.29
  #<VirtualHost 206.9.161.29>
  #    vdbh On
  #    vdbh_CLIENT_COMPRESS On
  #    vdbh_MySQL_Database virtual_hosts
  #    vdbh_MySQL_Table virtual_hosts
  #    vdbh_MySQL_Host_Field server
  #    vdbh_MySQL_Path_Field path
  #    vdbh_MySQL_Environment_Field environment_variable
  #    vdbh_Default_Host julia.fractal.net
  #    vdbh_Declines .htpasswd *.txt
  #</VirtualHost>

</IfModule>
da die dokumentation auf der seite praktischerweise nicht existent ist hilft mir das leider auch nicht so recht weiter. interessant finde ich lediglich vdbh_MySQL_Environment_Field environment_variable, mit dem man wohl andere vhost-einstellungen angeben kann?
AMD 2400+ XP | 1024 MB RAM | ATI Radeon 9600Pro
Gentoo Base System version 1.4.16 | Portage 2.0.51.19 | 2.6.11-gentoo-r9 Kernel
Top
equinox0r
l33t
l33t
User avatar
Posts: 614
Joined: Wed Feb 18, 2004 12:39 am
Contact:
Contact equinox0r
Website

  • Quote

Post by equinox0r » Mon Mar 13, 2006 10:06 pm

ich pusche mal gaanz flauschig :)
AMD 2400+ XP | 1024 MB RAM | ATI Radeon 9600Pro
Gentoo Base System version 1.4.16 | Portage 2.0.51.19 | 2.6.11-gentoo-r9 Kernel
Top
Post Reply
  • Print view

5 posts • Page 1 of 1

Return to “Deutsche Dokumentation”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy