commit b44a0c621910dcd00b6d74a4d321dba0acaa61aa
parent 6c2065335b6cd723bc5df7117b62b4c184f6b46e
Author: dankert <devnull@localhost>
Date: Wed, 24 Feb 2016 22:02:54 +0100
Document-Root anlegen, sofern notwendig.
Diffstat:
update_httpd | | | 63 | ++++++++++++++++++++++++++++++++++++++++++++------------------- |
1 file changed, 44 insertions(+), 19 deletions(-)
diff --git a/update_httpd b/update_httpd
@@ -16,11 +16,12 @@ fi
source $CONFIG
-if [ ! -f $HTTP_VHOST_DIR ]; then
- echo "File $HTTP_VHOST_DIR not found"
+if [ ! -d $HTTPD_VHOST_DIR ]; then
+ echo "Directory $HTTPD_VHOST_DIR not found"
exit 4;
fi
+# Ggf. Mercurial-Repository anlegen.
if [ ! -d $HTTPD_VHOST_DIR/.hg ]; then
hg -R $HTTPD_VHOST_DIR init
fi
@@ -46,16 +47,30 @@ sql "SELECT UNIX_TIMESTAMP(modified),domain FROM domain WHERE active=1"|while re
echo "Aktualisiere $domain"
- # Versuchen, den Benutzer zur Domain zu finden.
- dir=`find /home -mindepth 4 -maxdepth 4 -path "/home/*/var/www/*" -type d -name "$domain"`
- user=`echo $dir|cut -f 3 -d "/"`
- #echo "User: $user ==> Domain: $domain"
+ # Den Benutzer zur Domain zu finden. Es ist der (hoffentlich einzige) <Benutzername>@webmaster..., der für die Domain berechtigt ist.
+ user=`sql "SELECT substring_index(username,'@',1) as user FROM domain_admins where domain='$domain' and username like '%@webmaster%'"`
+ echo "User: $user ==> Domain: $domain"
+
+
if [ ! "$user" ]; then
- cat > $CONFFILE <<EOF
+ if [ -f $HTTPD_EXTRA_CONFIG_DIR/$domain.conf ]; then
+ cat > $CONFFILE <<EOF
-# AUTO-GENERATED by $0 - DO NOT CHANGE!
+# AUTO-GENERATED - DO NOT CHANGE!
+# Domain: $domain
+<VirtualHost *>
+ ServerName $domain
+ Include $HTTPD_EXTRA_CONFIG_DIR/$domain.conf"
+</VirtualHost>
+EOF
+ else
+
+ cat > $CONFFILE <<EOF
+
+# AUTO-GENERATED - DO NOT CHANGE!
+# Domain $domain disabled
<VirtualHost *>
ServerName $domain
@@ -63,20 +78,29 @@ sql "SELECT UNIX_TIMESTAMP(modified),domain FROM domain WHERE active=1"|while re
RewriteRule (.*) - [L,R=410]
</VirtualHost>
EOF
+ fi
else
- #echo "Pruefe $HTTPD_EXTRA_CONFIG_DIR/$domain.conf"
+ docroot=/home/$user/var/www/$domain
+
+ if [ ! -d $docroot ]; then
+ # Document-Root existiert noch nicht, also anlegen.
+ mkdir -v $docroot
+ chown -v $user $docroot
+ fi
+
if [ -f $HTTPD_EXTRA_CONFIG_DIR/$domain.conf ]; then
extra_config=" Include $HTTPD_EXTRA_CONFIG_DIR/$domain.conf"
else
extra_config=
fi
+
log_dir=/home/$user/var/log/apache2/$domain
if [ ! -d $log_dir ]; then
- echo "Lege an: $log_dir"
- mkdir $log_dir
+ mkdir -v $log_dir
fi
+
#echo "Logdir: $log_dir"
@@ -86,11 +110,12 @@ EOF
cat > $CONFFILE <<EOF
# AUTO-GENERATED by $0 - DO NOT CHANGE!
+# Domain $domain User: $user
<VirtualHost *>
ServerName $domain
ServerAdmin webmaster@$domain
- DocumentRoot /home/$user/var/www/$domain
+ DocumentRoot $docroot
php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -r webmaster@$domain"
php_admin_value open_basedir /home/$user/var/www/$domain:/home/$user/tmp
@@ -103,9 +128,9 @@ EOF
</VirtualHost>
EOF
- hg -R $HTTPD_VHOST_DIR add $CONFFILE
fi
+
fi
@@ -114,20 +139,20 @@ done
# Apache-Webserver muss Konfiguration neu laden
-if [ `hg -R $HTTPD_VHOST_DIR status|wc -l` -gt 0 ]; then
+if [ `hg -R $HTTPD_VHOST_DIR status -m -a|wc -l` -gt 0 ]; then
- echo "Änderungen durchgeführt"
+ echo "Änderungen durchgeführt:"
hg -R $HTTPD_VHOST_DIR diff
- hg -R $HTTPD_VHOST_DIR commit -u `whoami` -m "Updating HTTPD configuration"
+ hg -R $HTTPD_VHOST_DIR commit -addremove -u `whoami` -m "Updating HTTPD configuration"
if [ ! `apache2ctl -t|grep "Syntax OK"|wc -l` -eq "0" ]; then
- echo "Apache-Konfiguraton ist fehlerhaft! Kein Restart."
- #apache2ctl -t
+ echo "Apache-Konfiguraton ist fehlerhaft! Kein Restart!"
+ apache2ctl -t
else
echo "Apache-Konfiguration ist OK."
echo "Reloading Apache Webserver."
- #apache2ctl restart
+ apache2ctl restart
fi
fi