diff --git a/target/check_for_changes.sh b/target/check_for_changes.sh index d96b2f75..79f0b505 100755 --- a/target/check_for_changes.sh +++ b/target/check_for_changes.sh @@ -1,13 +1,28 @@ #! /bin/bash - - -while ! [ $ENABLE_LDAP = 1 ]; do +while true; do cd /tmp/docker-mailserver chksum=$(sha512sum -c chksum) resu_acc=${chksum:21:2} resu_vir=${chksum:44:2} +# Check postfix-virtual.cf exist else break +if [ ! -f postfix-virtual.cf ]; then + echo 'postfix-virtual.cf is missing! exit!' + break; +fi + +# Check postfix-accounts.cf exist else break +if [ ! -f postfix-accounts.cf ]; then + echo 'postfix-accounts.cf is missing! exit!' + break; +fi + +# Check chksum exist else create +if [ ! -f chksum ]; then + sha512sum --tag postfix-accounts.cf --tag postfix-virtual.cf > chksum +fi + if ! [ $resu_acc = "OK" ] || ! [ $resu_vir = "OK" ]; then echo "CHANGE DETECT" echo -n > /etc/postfix/vmailbox @@ -50,16 +65,21 @@ if ! [ $resu_acc = "OK" ] || ! [ $resu_vir = "OK" ]; then echo ${domain} >> /tmp/vhost.tmp done fi + + # Set vhost if [ -f /tmp/vhost.tmp ]; then cat /tmp/vhost.tmp | sort | uniq > /etc/postfix/vhost && rm /tmp/vhost.tmp fi + + # Set right new if needed if [ `find /var/mail -maxdepth 3 -a \( \! -user 5000 -o \! -group 5000 \) | grep -c .` != 0 ]; then chown -R 5000:5000 /var/mail fi - postfix reload - dovecot reload + supervisorctl restart postfix + supervisorctl restart dovecot sha512sum --tag postfix-accounts.cf --tag postfix-virtual.cf > chksum fi + sleep 1 -done \ No newline at end of file +done diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index b86a4861..a0679ae6 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -183,7 +183,10 @@ function register_functions() { if [ "$ENABLE_CLAMAV" = 1 ]; then _register_start_daemon "_start_daemons_clamav" fi - + # Change detector + if [ "$ENABLE_LDAP" = 0 ]; then + _register_start_daemon "_start_changedetector" + fi _register_start_daemon "_start_daemons_amavis" ################### << daemon funcs @@ -1247,7 +1250,10 @@ function _start_daemons_amavis() { # Start check for update postfix-accounts and postfix-virtual ########################################################################## -nohup /usr/local/bin/check_for_changes.sh >/dev/null 2>&1 & +function _start_changedetector() { + notify 'task' 'Starting changedetector' 'n' + supervisorctl start changedetector +} # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/target/supervisor/conf.d/supervisor-app.conf b/target/supervisor/conf.d/supervisor-app.conf index 92441afc..c768ba4b 100644 --- a/target/supervisor/conf.d/supervisor-app.conf +++ b/target/supervisor/conf.d/supervisor-app.conf @@ -114,3 +114,10 @@ stdout_logfile=/var/log/supervisor/%(program_name)s.log stderr_logfile=/var/log/supervisor/%(program_name)s.log command=/usr/local/bin/postfix-wrapper.sh +[program:changedetector] +startsecs=0 +autostart=false +autorestart=true +stdout_logfile=/var/log/supervisor/%(program_name)s.log +stderr_logfile=/var/log/supervisor/%(program_name)s.log +command=/usr/local/bin/check_for_changes.sh