@@ -, +, @@
---
Makefile.PL | 7 ++++++
debian/templates/koha-conf-site.xml.in | 1 +
etc/koha-conf.xml | 1 +
misc/cronjobs/process_message_queue.pl | 42 ++++++++++++++++++++++++++++------
rewrite-config.PL | 1 +
5 files changed, 45 insertions(+), 7 deletions(-)
--- a/Makefile.PL
+++ a/Makefile.PL
@@ -220,6 +220,10 @@ Directory for Zebra's lock files. This includes subdirs for authorities,
biblios, and the zebra rebuild function. Any activity to reindex
zebra from koha should interlock here with rebuild_zebra.pl.
+=item CRON_LOCK_DIR
+
+Directory for cronjob lock files.
+
=item ZEBRA_DATA_DIR
Directory for Zebra's data files.
@@ -358,6 +362,7 @@ my $target_map = {
'./skel/var/lib/koha/zebradb/biblios/register' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
'./skel/var/lib/koha/zebradb/biblios/shadow' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
'./skel/var/lib/koha/zebradb/biblios/tmp' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
+ './skel/var/lock/koha/cron' => { target => 'CRON_LOCK_DIR', trimdir => 6 },
'./skel/var/lock/koha/zebradb/rebuild' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
'./skel/var/lib/koha/plugins' => { target => 'PLUGINS_DIR', trimdir => 6 },
'./sms' => 'INTRANET_CGI_DIR',
@@ -649,6 +654,7 @@ my %test_suite_override_dirs = (
BACKUP_DIR => ['var', 'spool'],
SCRIPT_DIR => ['bin'],
ZEBRA_LOCK_DIR => ['var', 'lock', 'zebradb'],
+ CRON_LOCK_DIR => ['var', 'lock', 'cron'],
ZEBRA_DATA_DIR => ['var', 'lib', 'zebradb'],
ZEBRA_RUN_DIR => ['var', 'run', 'zebradb'],
);
@@ -1350,6 +1356,7 @@ sub get_target_directories {
$dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
$dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
$dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
+ $dirmap{'CRON_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'cron');
$dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log');
$dirmap{'BACKUP_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'spool');
$dirmap{'PLUGINS_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'koha', 'plugins');
--- a/debian/templates/koha-conf-site.xml.in
+++ a/debian/templates/koha-conf-site.xml.in
@@ -295,6 +295,7 @@ __END_SRU_PUBLICSERVER__
0
0
/var/lock/koha/__KOHASITE__
+ /var/lock/koha/__KOHASITE__
1
/etc/koha/searchengine/queryparser.yaml
__KOHA_CONF_DIR__/log4perl.conf
--- a/etc/koha-conf.xml
+++ a/etc/koha-conf.xml
@@ -116,6 +116,7 @@ __PAZPAR2_TOGGLE_XML_POST__
0
0
__ZEBRA_LOCK_DIR__
+ __CRON_LOCK_DIR__
1
__KOHA_CONF_DIR__/searchengine/queryparser.yaml
__KOHA_CONF_DIR__/log4perl.conf
--- a/misc/cronjobs/process_message_queue.pl
+++ a/misc/cronjobs/process_message_queue.pl
@@ -29,6 +29,9 @@ use C4::Letters;
use C4::Log;
use Getopt::Long;
use C4::Context;
+use File::Path;
+
+use constant LOCK_FILENAME => 'message_queue..LCK';
my $username = undef;
my $password = undef;
@@ -37,10 +40,10 @@ my $method = 'LOGIN';
my $help = 0;
my $verbose = 0;
my $type = q{};
+my $use_flock;
use Fcntl ':flock';
-
GetOptions(
'u|username:s' => \$username,
'p|password:s' => \$password,
@@ -80,16 +83,31 @@ die $usage if $help;
cronlogaction();
if ($verbose) { print "start of program\n"; }
-my $logdir = C4::Context->config('logdir');
-chomp $logdir;
-my $instancemessagequeuefile = $logdir . "/messagequeue.lock";
-my $fh;
-open $fh, '>>', $instancemessagequeuefile or die "Cannot write to $instancemessagequeuefile: $!";
+#Create a lock file in either in cron_lockdir (config line), a standard location (/var/lock/cron_) or /tmp/cron_)
+my ($lockfile, $LockFH);
+foreach (
+ C4::Context->config("cron_lockdir"),
+ '/var/lock/cron_' . C4::Context->config('database'),
+ '/tmp/cron_' . C4::Context->config('database')
+) {
+ next if !$_;
+ ($LockFH, $lockfile) = _create_lockfile($_.'/message_queue');
+ last if defined $LockFH;
+}
+if( !defined $LockFH ) {
+ print "WARNING: Could not create lock file $lockfile: $!\n";
+ print "Please check your koha-conf.xml for ZEBRA_LOCKDIR.\n";
+ print "Verify file permissions for it too.\n";
+ $use_flock = 0; # we disable file locking now and will continue
+ # without it
+ # note that this mimics old behavior (before we used
+ # the lockfile)
+};
my $letter_code = '';
if ($verbose) { print "Getting the lock\n"; }
-unless (flock ( $fh, LOCK_EX|LOCK_NB )) {
+unless (flock ( $LockFH, LOCK_EX|LOCK_NB )) {
print STDERR "$0 is already running!\n";
#If verbose is set send email to inform administrator another process_message_queue.pl cron was attempted to run whilst previous execution of the file is taking place.
@@ -127,3 +145,13 @@ if ($verbose) {
sleep(15);
print "End of process_message_queue.pl cron process";
}
+
+sub _create_lockfile { #returns undef on failure
+ my $dir= shift;
+ unless (-d $dir) {
+ eval { mkpath($dir, 0, oct(755)) };
+ return if $@;
+ }
+ return if !open my $fh, q{>}, $dir.'/'.LOCK_FILENAME;
+ return ( $fh, $dir.'/'.LOCK_FILENAME );
+}
--- a/rewrite-config.PL
+++ a/rewrite-config.PL
@@ -124,6 +124,7 @@ $prefix = $ENV{'INSTALL_BASE'} || "/usr";
'__MAN_DIR__' => "$prefix/man",
'__DOC_DIR__' => "$prefix/doc",
'__ZEBRA_LOCK_DIR__' => "$prefix/var/lock/zebradb",
+ '__CRON_LOCK_DIR__' => "$prefix/var/lock/cron",
'__ZEBRA_DATA_DIR__' => "$prefix/var/lib/zebradb",
'__ZEBRA_RUN_DIR__' => "$prefix/var/run/zebradb",
'__ZEBRA_MARC_FORMAT__' => 'marc21',
--