From c7484434ddf96b212c4ec7df912260a07317bb44 Mon Sep 17 00:00:00 2001 From: andryyy Date: Mon, 31 Jul 2017 08:17:56 +0200 Subject: [PATCH] [Dovecot] Remove master.pid if not running; Check for active imapsync besides lock file; Reconnect MySQL connection in imapsync_cron.pl --- data/Dockerfiles/dovecot/Dockerfile | 1 + data/Dockerfiles/dovecot/docker-entrypoint.sh | 3 +++ data/Dockerfiles/dovecot/imapsync_cron.pl | 14 +++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/data/Dockerfiles/dovecot/Dockerfile b/data/Dockerfiles/dovecot/Dockerfile index 33f64382..6148ed52 100644 --- a/data/Dockerfiles/dovecot/Dockerfile +++ b/data/Dockerfiles/dovecot/Dockerfile @@ -40,6 +40,7 @@ RUN apt-get update && apt-get -y install \ libtest-pod-perl \ libtest-simple-perl \ libunicode-string-perl \ + libproc-processtable-perl \ liburi-perl \ lzma-dev \ make \ diff --git a/data/Dockerfiles/dovecot/docker-entrypoint.sh b/data/Dockerfiles/dovecot/docker-entrypoint.sh index a07a3896..4e9fe14b 100755 --- a/data/Dockerfiles/dovecot/docker-entrypoint.sh +++ b/data/Dockerfiles/dovecot/docker-entrypoint.sh @@ -74,4 +74,7 @@ chown -R vmail:vmail /var/vmail/sieve # Fix more than 1 hardlink issue touch /etc/crontab /etc/cron.*/* +# Clean old PID if any +[[ -f /usr/local/var/run/dovecot/master.pid ]] && rm /usr/local/var/run/dovecot/master.pid + exec "$@" diff --git a/data/Dockerfiles/dovecot/imapsync_cron.pl b/data/Dockerfiles/dovecot/imapsync_cron.pl index 27419aac..26b5ad67 100755 --- a/data/Dockerfiles/dovecot/imapsync_cron.pl +++ b/data/Dockerfiles/dovecot/imapsync_cron.pl @@ -2,11 +2,20 @@ use DBI; use LockFile::Simple qw(lock trylock unlock); +use Proc::ProcessTable; use Data::Dumper qw(Dumper); use IPC::Run 'run'; use String::Util 'trim'; use File::Temp; +my $t = Proc::ProcessTable->new; +my $imapsync_running = grep { $_->{cmndline} =~ /^\/usr\/bin\/perl \/usr\/local\/bin\/imapsync\s/ } @{$t->table}; +if ($imapsync_running eq 1) +{ + print "imapsync is active, exiting..."; + exit; +} + $DBNAME = ''; $DBUSER = ''; $DBPASS = ''; @@ -16,7 +25,10 @@ $dsn = "DBI:mysql:database=" . $DBNAME . ";host=mysql"; $lock_file = $run_dir . "/imapsync_busy"; $lockmgr = LockFile::Simple->make(-autoclean => 1, -max => 1); $lockmgr->lock($lock_file) || die "can't lock ${lock_file}"; -$dbh = DBI->connect($dsn, $DBUSER, $DBPASS); +$dbh = DBI->connect($dsn, $DBUSER, $DBPASS, { + mysql_auto_reconnect => 1, + mysql_enable_utf8mb4 => 1 +}); open my $file, '<', "/etc/sogo/sieve.creds"; my $creds = <$file>; close $file;