|
Lines 14-19
use C4::Items;
Link Here
|
| 14 |
use Koha::RecordProcessor; |
14 |
use Koha::RecordProcessor; |
| 15 |
use XML::LibXML; |
15 |
use XML::LibXML; |
| 16 |
|
16 |
|
|
|
17 |
use constant LOCK_FILENAME => 'rebuild..LCK'; |
| 18 |
|
| 17 |
# script that checks zebradir structure & create directories & mandatory files if needed |
19 |
# script that checks zebradir structure & create directories & mandatory files if needed |
| 18 |
# |
20 |
# |
| 19 |
# |
21 |
# |
|
Lines 161-173
my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaFi
Link Here
|
| 161 |
# does not exist and cannot be created, we fall back on /tmp - which will |
163 |
# does not exist and cannot be created, we fall back on /tmp - which will |
| 162 |
# always work. |
164 |
# always work. |
| 163 |
|
165 |
|
| 164 |
my $lockdir = C4::Context->config("zebra_lockdir") // "/var/lock"; |
166 |
my ($lockfile, $LockFH); |
| 165 |
$lockdir .= "/rebuild"; |
167 |
foreach( C4::Context->config("zebra_lockdir"), "/var/lock/zebra_".C4::Context->config('database'), "/tmp/zebra_".C4::Context->config('database') ) { |
| 166 |
unless (-d $lockdir) { |
168 |
#we try three possibilities (we really want to lock :) |
| 167 |
eval { mkpath($lockdir, 0, oct(755)) }; |
169 |
next if !$_; |
| 168 |
$lockdir = "/tmp" if ($@); |
170 |
($LockFH, $lockfile) = _create_lockfile($_.'/rebuild'); |
| 169 |
} |
171 |
last if defined $LockFH; |
| 170 |
my $lockfile = $lockdir . "/rebuild..LCK"; |
172 |
} |
|
|
173 |
if( !defined $LockFH ) { |
| 174 |
print "WARNING: Could not create lock file $lockfile: $!\n"; |
| 175 |
print "Please check your koha-conf.xml for ZEBRA_LOCKDIR.\n"; |
| 176 |
print "Verify file permissions for it too.\n"; |
| 177 |
$use_flock=0; #we disable file locking now and will continue without it |
| 178 |
#note that this mimics old behavior (before we used the lockfile) |
| 179 |
}; |
| 171 |
|
180 |
|
| 172 |
if ( $verbose_logging ) { |
181 |
if ( $verbose_logging ) { |
| 173 |
print "Zebra configuration information\n"; |
182 |
print "Zebra configuration information\n"; |
|
Lines 175-181
if ( $verbose_logging ) {
Link Here
|
| 175 |
print "Zebra biblio directory = $biblioserverdir\n"; |
184 |
print "Zebra biblio directory = $biblioserverdir\n"; |
| 176 |
print "Zebra authorities directory = $authorityserverdir\n"; |
185 |
print "Zebra authorities directory = $authorityserverdir\n"; |
| 177 |
print "Koha directory = $kohadir\n"; |
186 |
print "Koha directory = $kohadir\n"; |
| 178 |
print "Lockfile = $lockfile\n"; |
187 |
print "Lockfile = $lockfile\n" if $lockfile; |
| 179 |
print "BIBLIONUMBER in : $biblionumbertagfield\$$biblionumbertagsubfield\n"; |
188 |
print "BIBLIONUMBER in : $biblionumbertagfield\$$biblionumbertagsubfield\n"; |
| 180 |
print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n"; |
189 |
print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n"; |
| 181 |
print "================================\n"; |
190 |
print "================================\n"; |
|
Lines 194-200
my $tester = XML::LibXML->new();
Link Here
|
| 194 |
# to prevent the potential for a infinite backlog from cron invocations, but an |
203 |
# to prevent the potential for a infinite backlog from cron invocations, but an |
| 195 |
# option (wait-for-lock) is provided to let the program wait for the lock. |
204 |
# option (wait-for-lock) is provided to let the program wait for the lock. |
| 196 |
# See http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=11078 for details. |
205 |
# See http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=11078 for details. |
| 197 |
open my $LockFH, q{>}, $lockfile or die "$lockfile: $!"; |
|
|
| 198 |
if ($daemon_mode) { |
206 |
if ($daemon_mode) { |
| 199 |
while (1) { |
207 |
while (1) { |
| 200 |
# For incremental updates, skip the update if the updates are locked |
208 |
# For incremental updates, skip the update if the updates are locked |
|
Lines 210-218
if ($daemon_mode) {
Link Here
|
| 210 |
if (_flock($LockFH, $lock_mode)) { |
218 |
if (_flock($LockFH, $lock_mode)) { |
| 211 |
do_one_pass(); |
219 |
do_one_pass(); |
| 212 |
_flock($LockFH, LOCK_UN); |
220 |
_flock($LockFH, LOCK_UN); |
| 213 |
} else { |
221 |
} |
| 214 |
# Can't die() here because we have files to dlean up. |
222 |
else { |
| 215 |
print "Aborting rebuild. Unable to flock $lockfile: $!\n"; |
223 |
print "Skipping rebuild/update because flock failed on $lockfile: $!\n"; |
| 216 |
} |
224 |
} |
| 217 |
} |
225 |
} |
| 218 |
|
226 |
|
|
Lines 787-792
sub _flock {
Link Here
|
| 787 |
} |
795 |
} |
| 788 |
} |
796 |
} |
| 789 |
|
797 |
|
|
|
798 |
sub _create_lockfile { #returns undef on failure |
| 799 |
my $dir= shift; |
| 800 |
unless (-d $dir) { |
| 801 |
eval { mkpath($dir, 0, oct(755)) }; |
| 802 |
return if $@; |
| 803 |
} |
| 804 |
return if !open my $fh, q{>}, $dir.'/'.LOCK_FILENAME; |
| 805 |
return ( $fh, $dir.'/'.LOCK_FILENAME ); |
| 806 |
} |
| 807 |
|
| 790 |
sub print_usage { |
808 |
sub print_usage { |
| 791 |
print <<_USAGE_; |
809 |
print <<_USAGE_; |
| 792 |
$0: reindex MARC bibs and/or authorities in Zebra. |
810 |
$0: reindex MARC bibs and/or authorities in Zebra. |
| 793 |
- |
|
|