From f7b95ae5a0c25f1fc3c31f8eee224a338e8e2942 Mon Sep 17 00:00:00 2001 From: andryyy Date: Sun, 25 Dec 2016 10:03:37 +0100 Subject: [PATCH] Restart SOGo from within panel --- data/Dockerfiles/php-fpm/Dockerfile | 4 +- data/Dockerfiles/sogo/Dockerfile | 4 +- ...docker-entrypoint.sh => reconf-domains.sh} | 45 ++++++++-------- data/Dockerfiles/sogo/supervisord.conf | 20 ++++++-- data/web/call_sogo_ctrl.php | 40 +++++++++++++++ data/web/inc/footer.inc.php | 51 +++++++++++++++++++ data/web/inc/header.inc.php | 7 +++ data/web/js/mailbox.js | 2 +- data/web/mailbox.php | 8 +-- 9 files changed, 149 insertions(+), 32 deletions(-) rename data/Dockerfiles/sogo/{docker-entrypoint.sh => reconf-domains.sh} (81%) create mode 100644 data/web/call_sogo_ctrl.php diff --git a/data/Dockerfiles/php-fpm/Dockerfile b/data/Dockerfiles/php-fpm/Dockerfile index aa489dbc9..0dc1061f4 100644 --- a/data/Dockerfiles/php-fpm/Dockerfile +++ b/data/Dockerfiles/php-fpm/Dockerfile @@ -4,10 +4,10 @@ MAINTAINER Andre Peters ENV DEBIAN_FRONTEND noninteractive RUN apt-get update \ - && apt-get install -y zlib1g-dev libicu-dev g++ libidn11-dev + && apt-get install -y zlib1g-dev libicu-dev g++ libidn11-dev libxml2-dev RUN docker-php-ext-configure intl -RUN docker-php-ext-install intl pdo pdo_mysql +RUN docker-php-ext-install intl pdo pdo_mysql xmlrpc COPY ./docker-entrypoint.sh / diff --git a/data/Dockerfiles/sogo/Dockerfile b/data/Dockerfiles/sogo/Dockerfile index 282bc406b..2d043fdd2 100644 --- a/data/Dockerfiles/sogo/Dockerfile +++ b/data/Dockerfiles/sogo/Dockerfile @@ -32,12 +32,12 @@ RUN echo '* * * * * sogo /usr/sbin/sogo-ealarms-notify' > /etc/cron.d/sogo RUN echo '* * * * * sogo /usr/sbin/sogo-tool expire-sessions 60' >> /etc/cron.d/sogo RUN echo '0 0 * * * sogo /usr/sbin/sogo-tool update-autoreply -p /etc/sogo/sieve.creds' >> /etc/cron.d/sogo -COPY ./docker-entrypoint.sh / +COPY ./reconf-domains.sh / COPY supervisord.conf /etc/supervisor/supervisord.conf EXPOSE 20000 +EXPOSE 9191 -ENTRYPOINT ["/docker-entrypoint.sh"] CMD exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* diff --git a/data/Dockerfiles/sogo/docker-entrypoint.sh b/data/Dockerfiles/sogo/reconf-domains.sh similarity index 81% rename from data/Dockerfiles/sogo/docker-entrypoint.sh rename to data/Dockerfiles/sogo/reconf-domains.sh index 619badf6c..78482859a 100755 --- a/data/Dockerfiles/sogo/docker-entrypoint.sh +++ b/data/Dockerfiles/sogo/reconf-domains.sh @@ -1,14 +1,17 @@ #!/bin/bash -# Wait for MySQL to warm-up -while ! mysqladmin ping --host mysql --silent; do - sleep 1 -done +# Go in a 5 minute loop +while true; do -mkdir -p /var/lib/sogo/GNUstep/Defaults/ + # Wait for MySQL to warm-up + while ! mysqladmin ping --host mysql --silent; do + sleep 1 + done -# Generate plist header with timezone data -cat < /var/lib/sogo/GNUstep/Defaults/sogod.plist + mkdir -p /var/lib/sogo/GNUstep/Defaults/ + + # Generate plist header with timezone data + cat < /var/lib/sogo/GNUstep/Defaults/sogod.plist @@ -33,11 +36,11 @@ cat < /var/lib/sogo/GNUstep/Defaults/sogod.plist EOF -# Generate multi-domain setup -while read line -do -DOMAIN_SANE=$(echo ${line} | tr '-' 'b' | tr '.' 'p' | tr -cd '[[:alnum:]]') -echo " ${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') @@ -73,8 +76,8 @@ echo " ${line} " >> /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 + 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 @@ -84,13 +87,15 @@ 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 -exec "$@" + sleep 300 + +done diff --git a/data/Dockerfiles/sogo/supervisord.conf b/data/Dockerfiles/sogo/supervisord.conf index 2377c3ff5..b59ff11c4 100644 --- a/data/Dockerfiles/sogo/supervisord.conf +++ b/data/Dockerfiles/sogo/supervisord.conf @@ -7,10 +7,19 @@ redirect_stderr=true autostart=true stdout_syslog=true +[group:sogo-group] +programs=reconf-domains,sogo + [program:sogo] command=/usr/sbin/sogod user=sogo autorestart=true +priority=20 + +[program:reconf-domains] +command=/reconf-domains.sh +autorestart=true +priority=10 [program:sogo-syslog] command=/usr/bin/tail -f /var/log/syslog -f /var/log/sogo/sogo.log @@ -21,6 +30,11 @@ stdout_logfile_maxbytes=0 command=/usr/sbin/cron -f autorestart=true -#[unix_http_server] -#file=/var/run/controller/supervisord.sock -#chown=www-data:nogroup +[inet_http_server] +port=9191 + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[supervisorctl] +serverurl=http://localhost:9191 diff --git a/data/web/call_sogo_ctrl.php b/data/web/call_sogo_ctrl.php new file mode 100644 index 000000000..c548bd56a --- /dev/null +++ b/data/web/call_sogo_ctrl.php @@ -0,0 +1,40 @@ +'utf-8')); + $context = stream_context_create(array('http' => array( + 'method' => "POST", + 'header' => "Content-Length: " . strlen($request), + 'content' => $request + ))); + $file = @file_get_contents("http://sogo:9191/RPC2", false, $context) or die("Cannot connect to $remote_server:$listener_port"); + $response = xmlrpc_decode($file); + if (isset($response['faultString'])) { + echo '' . $response['faultString'] . ''; + } + else { + echo 'OK'; + } +} +elseif ($_GET['ACTION'] == "stop") { + $request = xmlrpc_encode_request("supervisor.stopProcessGroup", 'sogo-group', array('encoding'=>'utf-8')); + $context = stream_context_create(array('http' => array( + 'method' => "POST", + 'header' => "Content-Length: " . strlen($request), + 'content' => $request + ))); + $file = @file_get_contents("http://sogo:9191/RPC2", false, $context) or die("Cannot connect to $remote_server:$listener_port"); + $response = xmlrpc_decode($file); + if (isset($response['faultString'])) { + echo '' . $response['faultString'] . ''; + } + else { + echo 'OK'; + } +} +?> \ No newline at end of file diff --git a/data/web/inc/footer.inc.php b/data/web/inc/footer.inc.php index a62740ef6..e9a8a18db 100644 --- a/data/web/inc/footer.inc.php +++ b/data/web/inc/footer.inc.php @@ -1,3 +1,26 @@ + + + @@ -59,6 +82,34 @@ $(document).ready(function() { // Init Bootstrap Selectpicker $('select').selectpicker(); + // Trigger SOGo restart + $('#triggerRestartSogo').click(function(){ + $(this).prop("disabled",true); + $('#statusTriggerRestartSogo').text('Stopping SOGo workers, this may take a while... '); + $.ajax({ + method: 'get', + url: 'call_sogo_ctrl.php', + data: { + 'ajax': true, + 'ACTION': 'stop' + }, + success: function(data) { + $('#statusTriggerRestartSogo').append(data); + $('#statusTriggerRestartSogo').append('
Starting SOGo... '); + $.ajax({ + method: 'get', + url: 'call_sogo_ctrl.php', + data: { + 'ajax': true, + 'ACTION': 'start' + }, + success: function(data) { + $('#statusTriggerRestartSogo').append(data); + } + }); + } + }); + }); }); + +
  • Restart SOGo
  • + - + @@ -238,7 +238,7 @@ $_SESSION['return_to'] = $_SERVER['REQUEST_URI']; - + @@ -368,7 +368,7 @@ $_SESSION['return_to'] = $_SERVER['REQUEST_URI']; - + @@ -479,7 +479,7 @@ $_SESSION['return_to'] = $_SERVER['REQUEST_URI']; - +