merging changes from rel-1-2

This commit is contained in:
tonnesen 2002-07-02 22:08:50 +00:00
parent 682ae23959
commit 219e006412
3 changed files with 256 additions and 197 deletions

View file

@ -6,19 +6,50 @@ use C4::Acquisitions;
use C4::Biblio; use C4::Biblio;
use C4::Output; use C4::Output;
use Net::Z3950; use Net::Z3950;
if ($< == 0) {
# Running as root, switch privs
if (-d "/var/run") {
open PID, ">/var/run/processz3950queue.pid";
print PID $$."\n";
close PID;
}
# Get real apacheuser from koha.conf or reparsing httpd.conf
my $apacheuser='www-data';
my $uid=0;
unless ($uid = (getpwnam($apacheuser))[2]) {
die "Attempt to run daemon as non-existent or superuser\n";
}
$>=$uid;
$<=$uid;
}
my $dbh=C4Connect; my $dbh=C4Connect;
my $sth=$dbh->prepare("update z3950results set active=0"); my $sth=$dbh->prepare("update z3950results set active=0");
$sth->execute; $sth->execute;
$sth->finish; $sth->finish;
$SIG{CHLD}='reap'; $SIG{CHLD}='reap';
$SIG{HUP}='checkqueue';
my $logdir=$ARGV[0];
open PID, ">$logdir/processz3950queue.pid";
print PID $$."\n";
close PID;
my $reapcounter=0; my $reapcounter=0;
my $forkcounter=0; my $forkcounter=0;
my $checkqueue=1;
my $pid=$$; my $pid=$$;
my $lastrun=0; my $lastrun=0;
while (1) { while (1) {
if ((time-$lastrun)>5) { if ((time-$lastrun)>5) {
if ($checkqueue) {
$checkqueue=0;
my $sth=$dbh->prepare("select id,term,type,servers from z3950queue order by id"); my $sth=$dbh->prepare("select id,term,type,servers from z3950queue order by id");
$sth->execute; $sth->execute;
while (my ($id, $term, $type, $servers) = $sth->fetchrow) { while (my ($id, $term, $type, $servers) = $sth->fetchrow) {
@ -197,9 +228,6 @@ while (1) {
ADDTL: $ai ADDTL: $ai
EOF EOF
# if ($msg =~/not yet available/) {
# return 1;
# }
return 0; return 0;
} }
} }
@ -208,21 +236,15 @@ EOF
#$sti->execute; #$sti->execute;
#my ($enddate) = $sti->fetchrow; #my ($enddate) = $sti->fetchrow;
#unless ($enddate) { #unless ($enddate) {
# my $now=time;
# $sti=$dbh->prepare("update z3950queue set done=1,numrecords=$totalrecords,enddate=$now where id=$id");
# $sti->execute;
# }
} }
} else { } else {
# my $q_serverinfo=$dbh->quote($serverinfo);
# my $stj=$dbh->prepare("insert into z3950results (server, queryid, startdate) values ($q_serverinfo, $id, 0)");
# $stj->execute;
} }
} }
$lastrun=time(); $lastrun=time();
} }
sleep 10; sleep 10;
} }
}
sub getrecord { sub getrecord {
my $server=shift; my $server=shift;
@ -256,7 +278,12 @@ EOF
} }
sub reap { sub reap {
$forkcounter--; $forkcounter--;
wait;
} }
sub checkqueue {
$checkqueue=1;
}

View file

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
# $Id$
# Script to start Koha background Z39.50 search daemon # Script to start Koha background Z39.50 search daemon
# Part of the Koha Library Mgmt System - www.koha.org # Part of the Koha Library Mgmt System - www.koha.org
@ -15,17 +17,17 @@
# User ID to run the daemon as. Don't use "root" # User ID to run the daemon as. Don't use "root"
RunAsUser=apache RunAsUser=apache
KohaDir=/usr/local/www/koha/htdocs/cgi-bin/koha/acqui.simple KohaZ3950Dir=/usr/local/www/koha/htdocs/cgi-bin/koha/acqui.simple
export KohaDir export KohaZ3950Dir
#---------------------------- #----------------------------
if [ ! -d $KohaDir ] if [ ! -d $KohaZ3950Dir ]
then then
echo ERROR: Cannot find Koha directory $KohaDir echo ERROR: Cannot find Koha directory $KohaZ3950Dir
exit 1 exit 1
fi fi
KohaZ3950Shell=$KohaDir/z3950-daemon-shell.sh KohaZ3950Shell=$KohaZ3950Dir/z3950-daemon-shell.sh
if [ ! -x $KohaZ3950Shell ] if [ ! -x $KohaZ3950Shell ]
then then
@ -33,4 +35,19 @@ then
exit 1 exit 1
fi fi
su -s /bin/sh -c '$KohaZ3950Shell &' - $RunAsUser & su -s /bin/sh -c $KohaZ3950Shell - $RunAsUser &
exit
#--------------
# $Log$
# Revision 1.3 2002/07/02 22:08:50 tonnesen
# merging changes from rel-1-2
#
# Revision 1.1.2.3 2002/06/26 19:56:57 tonnesen
# Bug fix. Single quotes were causing $KohaZ3950Shell variable to not get
# expanded
#
# Revision 1.1.2.2 2002/06/26 16:25:51 amillar
# Make directory variable name more explanatory
#

View file

@ -1,17 +1,19 @@
#!/bin/sh #!/bin/sh
# $Id$
# Script to start Koha background Z39.50 search daemon # Script to start Koha background Z39.50 search daemon
# Part of the Koha Library Mgmt System - www.koha.org # Part of the Koha Library Mgmt System - www.koha.org
# Licensed under the GPL # Licensed under the GPL
#---------------------------- #----------------------------
# Do NOT run this script directly from system startup- # Do NOT run this script directly from system startup-- this should not run as root
# Call z3950-daemon-launch.sh instead # Call z3950-daemon-launch.sh instead
#---------------------------- #----------------------------
KohaDir=/usr/local/www/koha/htdocs/cgi-bin/koha/acqui.simple KohaZ3950Dir=/usr/local/www/koha/htdocs/cgi-bin/koha/acqui.simple
KohaModuleDir=/usr/local/koha/modules KohaModuleDir=/usr/local/koha/modules
LogDir=/var/log/koha LogDir=/var/log/koha
@ -25,7 +27,7 @@ then
exit 1 exit 1
fi fi
KohaZ3950Script=$KohaDir/processz3950queue KohaZ3950Script=$KohaZ3950Dir/processz3950queue
if [ ! -x $KohaZ3950Script ] if [ ! -x $KohaZ3950Script ]
then then
echo ERROR: Cannot find Koha Z39.50 daemon script $KohaZ3950Script echo ERROR: Cannot find Koha Z39.50 daemon script $KohaZ3950Script
@ -35,4 +37,17 @@ fi
PERL5LIB=$KohaModuleDir PERL5LIB=$KohaModuleDir
export PERL5LIB export PERL5LIB
exec $KohaDir/processz3950queue >>$LOGFILE 2>&1 exec $KohaZ3950Script $LogDir >>$LOGFILE 2>&1
#-------------------
# $Log$
# Revision 1.3 2002/07/02 22:08:50 tonnesen
# merging changes from rel-1-2
#
# Revision 1.1.2.3 2002/06/28 17:45:39 tonnesen
# z3950queue now listens for a -HUP signal before processing the queue. Z3950.pm
# sends the -HUP signal when queries are added to the queue.
#
# Revision 1.1.2.2 2002/06/26 16:25:51 amillar
# Make directory variable name more explanatory
#