From 75139e51cc0fc19de8ff17bcdc6227742479bed8 Mon Sep 17 00:00:00 2001 From: andryyy Date: Thu, 5 Jan 2017 20:35:46 +0100 Subject: [PATCH] Use a single view for all domains - easier but will cause more load with large setups, use procs here instead --- data/Dockerfiles/sogo/reconf-domains.sh | 61 +++++++++++++------------ 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/data/Dockerfiles/sogo/reconf-domains.sh b/data/Dockerfiles/sogo/reconf-domains.sh index 78482859..8cc24052 100755 --- a/data/Dockerfiles/sogo/reconf-domains.sh +++ b/data/Dockerfiles/sogo/reconf-domains.sh @@ -1,17 +1,27 @@ #!/bin/bash -# Go in a 5 minute loop -while true; do +# Recreate view - # Wait for MySQL to warm-up - while ! mysqladmin ping --host mysql --silent; do - sleep 1 - done +mysql --host mysql -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "DROP VIEW IF EXISTS sogo_view" - mkdir -p /var/lib/sogo/GNUstep/Defaults/ +mysql --host mysql -u ${DBUSER} -p${DBPASS} ${DBNAME} << EOF +CREATE VIEW sogo_view (c_uid, domain, c_name, c_password, c_cn, mail, aliases, ad_aliases, senderacl, home) AS +SELECT mailbox.username, mailbox.domain, mailbox.username, mailbox.password, mailbox.name, mailbox.username, IFNULL(ga.aliases, ''), IFNULL(gda.ad_alias, ''), IFNULL(gs.send_as, ''), CONCAT('/var/vmail/', maildir) FROM mailbox +LEFT OUTER JOIN grouped_mail_aliases ga ON ga.username = mailbox.username +LEFT OUTER JOIN grouped_sender_acl gs ON gs.username = mailbox.username +LEFT OUTER JOIN grouped_domain_alias_address gda ON gda.username = mailbox.username +WHERE mailbox.active = '1'; +EOF - # Generate plist header with timezone data - cat < /var/lib/sogo/GNUstep/Defaults/sogod.plist +# Wait for MySQL to warm-up +while ! mysqladmin ping --host mysql --silent; do + sleep 1 +done + +mkdir -p /var/lib/sogo/GNUstep/Defaults/ + +# Generate plist header with timezone data +cat < /var/lib/sogo/GNUstep/Defaults/sogod.plist @@ -22,6 +32,8 @@ while true; do mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_cache_folder OCSEMailAlarmsFolderURL mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_alarms_folder + DomainFieldName + domain OCSFolderInfoURL mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_folder_info OCSSessionsFolderURL @@ -36,14 +48,14 @@ while true; do EOF - # Generate multi-domain setup - while read line +# Generate multi-domain setup +while read line do DOMAIN_SANE=$(echo ${line} | tr '-' 'b' | tr '.' 'p' | tr -cd '[[:alnum:]]') echo " ${line} SOGoMailDomain - $(echo ${line} | tr '-' 'b' | tr '.' 'p') + ${DOMAIN_SANE} SOGoUserSources @@ -72,30 +84,19 @@ EOF userPasswordAlgorithm ssha256 viewURL - mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_view_${DOMAIN_SANE} + mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_view " >> /var/lib/sogo/GNUstep/Defaults/sogod.plist - mysql --host mysql -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "DROP VIEW IF EXISTS sogo_view_${DOMAIN_SANE}" - mysql --host mysql -u ${DBUSER} -p${DBPASS} ${DBNAME} << EOF -CREATE VIEW sogo_view_${DOMAIN_SANE} (c_uid, c_name, c_password, c_cn, mail, aliases, ad_aliases, senderacl, home) AS -SELECT mailbox.username, mailbox.username, mailbox.password, mailbox.name, mailbox.username, IFNULL(ga.aliases, ''), IFNULL(gda.ad_alias, ''), IFNULL(gs.send_as, ''), CONCAT('/var/vmail/', maildir) FROM mailbox -LEFT OUTER JOIN grouped_mail_aliases ga ON ga.username = mailbox.username -LEFT OUTER JOIN grouped_sender_acl gs ON gs.username = mailbox.username -LEFT OUTER JOIN grouped_domain_alias_address gda ON gda.username = mailbox.username -WHERE mailbox.active = '1' AND domain = '${line}'; -EOF done < <(mysql --host mysql -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "SELECT domain FROM domain;" -B -N) - # Generate footer - echo ' +# Generate footer +echo ' ' >> /var/lib/sogo/GNUstep/Defaults/sogod.plist - # Fix permissions - chown sogo:sogo -R /var/lib/sogo/ - chmod 600 /var/lib/sogo/GNUstep/Defaults/sogod.plist +# Fix permissions +chown sogo:sogo -R /var/lib/sogo/ +chmod 600 /var/lib/sogo/GNUstep/Defaults/sogod.plist - sleep 300 - -done +sleep infinite