瀏覽代碼

[Dovecot] Remove master.pid if not running; Check for active imapsync besides lock file; Reconnect MySQL connection in imapsync_cron.pl

andryyy 8 年之前
父節點
當前提交
c7484434dd

+ 1 - 0
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 \

+ 3 - 0
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 "$@"

+ 13 - 1
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;