Bug 17376 - rebuild_zebra.pl in daemon mode no database access kills the process
When running rebuild_zebra.pl in daemon mode, a while loop runs the script for ever. But if something crashes inside the rebuild process, the all daemon crashes. For example when it can not access database. This problem may be temporary so daemon should keep running. This patch add eval around the rebuild process to allow a run to fail without killing the daemon. Also moves the DB handler get inside daemon loop because it is broken is DB stoppes. This is a big issue for indexer running in a systemd service. Test plan : - run rebuild_zebra.pl in daemon mode : /home/koha/src/misc/migration_tools/rebuild_zebra.pl -daemon -z -a -b -x --sleep 30 - stop the database - wait a minute => you see an error on database connexion => the daemon is still running - restart the database - test the indexer by creating a new record (wait for a minute) Signed-off-by: Jacek Ablewicz <abl@biblos.pk.edu.pl> Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> (cherry picked from commitbfcc7cad70) Signed-off-by: Frédéric Demians <f.demians@tamil.fr> (cherry picked from commitdb1bf801e6) Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
This commit is contained in:
parent
a67c666da4
commit
28fc01a612
|
|
@ -164,7 +164,6 @@ my $kohadir = C4::Context->config('intranetdir');
|
|||
my $bib_index_mode = C4::Context->config('zebra_bib_index_mode') // 'dom';
|
||||
my $auth_index_mode = C4::Context->config('zebra_auth_index_mode') // 'dom';
|
||||
|
||||
my $dbh = C4::Context->dbh;
|
||||
my ($biblionumbertagfield,$biblionumbertagsubfield) = &GetMarcFromKohaField("biblio.biblionumber","");
|
||||
my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaField("biblioitems.biblioitemnumber","");
|
||||
|
||||
|
|
@ -216,6 +215,7 @@ if ( $verbose_logging ) {
|
|||
}
|
||||
|
||||
my $tester = XML::LibXML->new();
|
||||
my $dbh;
|
||||
|
||||
# The main work is done here by calling do_one_pass(). We have added locking
|
||||
# avoid race conditions between full rebuilds and incremental updates either from
|
||||
|
|
@ -232,7 +232,13 @@ if ($daemon_mode) {
|
|||
while (1) {
|
||||
# For incremental updates, skip the update if the updates are locked
|
||||
if (_flock($LockFH, LOCK_EX|LOCK_NB)) {
|
||||
do_one_pass() if ( zebraqueue_not_empty() );
|
||||
eval {
|
||||
$dbh = C4::Context->dbh;
|
||||
do_one_pass() if ( zebraqueue_not_empty() );
|
||||
};
|
||||
if ($@ && $verbose_logging) {
|
||||
warn "Warning : $@\n";
|
||||
}
|
||||
_flock($LockFH, LOCK_UN);
|
||||
}
|
||||
sleep $daemon_sleep;
|
||||
|
|
@ -241,6 +247,7 @@ if ($daemon_mode) {
|
|||
# all one-off invocations
|
||||
my $lock_mode = ($wait_for_lock) ? LOCK_EX : LOCK_EX|LOCK_NB;
|
||||
if (_flock($LockFH, $lock_mode)) {
|
||||
$dbh = C4::Context->dbh;
|
||||
do_one_pass();
|
||||
_flock($LockFH, LOCK_UN);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue