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

master
andryyy 2017-07-31 08:17:56 +02:00
parent 10b2ae09b9
commit c7484434dd
3 changed files with 17 additions and 1 deletions

View File

@ -40,6 +40,7 @@ RUN apt-get update && apt-get -y install \
libtest-pod-perl \ libtest-pod-perl \
libtest-simple-perl \ libtest-simple-perl \
libunicode-string-perl \ libunicode-string-perl \
libproc-processtable-perl \
liburi-perl \ liburi-perl \
lzma-dev \ lzma-dev \
make \ make \

View File

@ -74,4 +74,7 @@ chown -R vmail:vmail /var/vmail/sieve
# Fix more than 1 hardlink issue # Fix more than 1 hardlink issue
touch /etc/crontab /etc/cron.*/* 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 "$@" exec "$@"

View File

@ -2,11 +2,20 @@
use DBI; use DBI;
use LockFile::Simple qw(lock trylock unlock); use LockFile::Simple qw(lock trylock unlock);
use Proc::ProcessTable;
use Data::Dumper qw(Dumper); use Data::Dumper qw(Dumper);
use IPC::Run 'run'; use IPC::Run 'run';
use String::Util 'trim'; use String::Util 'trim';
use File::Temp; 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 = ''; $DBNAME = '';
$DBUSER = ''; $DBUSER = '';
$DBPASS = ''; $DBPASS = '';
@ -16,7 +25,10 @@ $dsn = "DBI:mysql:database=" . $DBNAME . ";host=mysql";
$lock_file = $run_dir . "/imapsync_busy"; $lock_file = $run_dir . "/imapsync_busy";
$lockmgr = LockFile::Simple->make(-autoclean => 1, -max => 1); $lockmgr = LockFile::Simple->make(-autoclean => 1, -max => 1);
$lockmgr->lock($lock_file) || die "can't lock ${lock_file}"; $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"; open my $file, '<', "/etc/sogo/sieve.creds";
my $creds = <$file>; my $creds = <$file>;
close $file; close $file;