Bug 5139 - packages now do email and other cron jobs

By default the packages now set up the cron jobs to handle things like
overdues and email etc. By default, email is off, 'koha-email-enable'
and 'koha-email-disable' can manage this.

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Galen Charlton <gmcharlt@gmail.com>
This commit is contained in:
Robin Sheat 2010-08-31 11:48:20 +12:00 committed by Galen Charlton
parent 95cb1c3a7f
commit 18a1c3db11
11 changed files with 181 additions and 26 deletions

View file

@ -33,6 +33,8 @@ The Debian packaging of Koha puts files in the following places:
* /etc/koha -- system configuration files
* /etc/cron.hourly/koha-common -- cron job
* /etc/cron.daily/koha-common -- cron job
* /etc/cron.d/koha-common -- cron job
* /usr/share/koha -- shared files (HTML templates, Perl code, etc)
Each Koha instance has files in the following places:

View file

@ -7,3 +7,4 @@ SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
*/5 * * * * root test -x /usr/sbin/koha-rebuild-zebra && koha-rebuild-zebra $(koha-list --enabled)
*/15 * * * * root koha-foreach --enabled --email /usr/share/koha/bin/cronjobs/process_message_queue.pl

24
debian/koha-common.cron.daily vendored Normal file
View file

@ -0,0 +1,24 @@
#!/bin/sh
# /etc/cron.daily/koha-common -- Daily housekeeping tasks for all Kohas.
# Copyright 2010 Catalyst IT, Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
koha-foreach --enabled --email /usr/share/koha/bin/cronjobs/overdue_notices.pl -t
koha-foreach --enabled /usr/share/koha/bin/cronjobs/fines.pl
koha-foreach --enabled --email /usr/share/koha/bin/cronjobs/advance_notices.pl -c
koha-foreach --enabled /usr/share/koha/bin/cronjobs/holds/cancel_expired_holds.pl >/dev/null 2>&1
koha-foreach --enabled /usr/share/koha/bin/cronjobs/services_throttle.pl > /dev/null 2>&1
koha-foreach --enabled /usr/share/koha/bin/cronjobs/cleanup_database.pl --sessions --zebraqueue 10
koha-foreach --enabled --noemail /usr/share/koha/bin/cronjobs/cleanup_database.pl --mail

View file

@ -3,7 +3,7 @@ debian/tmp/usr/* usr
debian/tmp/etc/koha/pazpar2
debian/tmp/etc/koha/zebradb/[!z]*
debian/templates/* etc/koha
debian/koha-post-install-setup usr/sbin
debian/koha-post-install-setup usr/sbin
debian/unavailable.html usr/share/koha/intranet/htdocs
debian/unavailable.html usr/share/koha/opac/htdocs
debian/templates/* etc/koha
@ -12,6 +12,8 @@ debian/scripts/koha-create-dirs usr/sbin
debian/scripts/koha-disable usr/sbin
debian/scripts/koha-dump usr/sbin
debian/scripts/koha-dump-defaults usr/sbin
debian/scripts/koha-email-disable usr/sbin
debian/scripts/koha-email-enable usr/sbin
debian/scripts/koha-enable usr/sbin
debian/scripts/koha-foreach usr/sbin
debian/scripts/koha-list usr/sbin

View file

@ -234,3 +234,9 @@ if [ "$op" = request ]
then
koha-disable "$name"
fi
echo <<eoh
Email for this instance is disabled. When you're ready to enable it, use:
koha-email-enable $name
eoh

36
debian/scripts/koha-email-disable vendored Executable file
View file

@ -0,0 +1,36 @@
#!/bin/sh
#
# koha-email-disable -- turn off the email for a Koha instance
# Copyright 2010 Catalyst IT, Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
if [ "$#" = 0 ]
then
echo "Disables the email for a koha instance." 1>&2
echo "Usage: $0 instancename..." 1>&2
exit 1
fi
libdir=/var/lib/koha
for name in "$@"
do
if [ ! -d $libdir/$name ]
then
echo "$0: no koha instance \"$name\"" 1>&2
continue
fi
rm -f $libdir/$name/email.enabled
done

36
debian/scripts/koha-email-enable vendored Executable file
View file

@ -0,0 +1,36 @@
#!/bin/sh
#
# koha-email-enable -- turn on the email for a Koha instance
# Copyright 2010 Catalyst IT, Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
if [ "$#" = 0 ]
then
echo "Enables email for a koha instance." 1>&2
echo "Usage: $0 instancename..." 1>&2
exit 1
fi
libdir=/var/lib/koha
for name in "$@"
do
if [ ! -d $libdir/$name ]
then
echo "$0: no koha instance \"$name\"" 1>&2
continue
fi
touch $libdir/$name/email.enabled
done

0
debian/scripts/koha-enable vendored Normal file → Executable file
View file

View file

@ -18,15 +18,18 @@
set -e
listopts=""
if [ "$1" = --enabled ]
then
listopts="--enabled"
while [ ! -z "$1" ]
do
case "$1" in
--email) listopts="$listopts --email";;
--noemail) listopts="$listopts --noemail";;
--enabled) listopts="$listopts --enabled";;
*) break;;
esac
shift
fi
done
for name in $(koha-list $listopts)
do
sudo -u "$name-koha" \

View file

@ -29,19 +29,46 @@ is_enabled() {
fi
}
all=yes
if [ "$1" = --enabled ]
then
help() {
echo <<eoh
Lists Koha instances, optionally only those that are enabled or have
email turned on.
Usage: $0 [--enabled] [--email] [-h]
Options:
--enabled only show instances that are enabled
--email only show instances that have email enabled
--noemail only show instances that do not have email enabled
-h this help
The filtering options can be combined, and you probably want to do this
(except --email and --noemail, that's just silly.)
eoh
}
enabled=no
email=no
noemail=no
args=$(getopt -l enabled,email,noemail -o h -n $0 -- "$@")
set -- $args
while [ ! -z "$1" ]
do
case "$1" in
-h) help; exit;;
--email) email=yes;;
--enabled) enabled=yes;;
--noemail) noemail=yes;;
*) break;;
esac
shift
all=no
fi
done
find /etc/koha/sites -mindepth 1 -maxdepth 1 -type d -printf '%f\n' |
sort |
while read name
do
if [ "$all" = yes ] || is_enabled "$name"
then
echo "$name"
fi
[ "$enabled" = yes ] && ! is_enabled "$name" && continue
[ "$email" = yes ] && [ ! -e /var/lib/koha/$name/email.enabled ] && continue
[ "$noemail" = yes ] && [ -e /var/lib/koha/$name/email.enabled ] && continue
echo "$name"
done

View file

@ -38,21 +38,27 @@ use Getopt::Long;
sub usage {
print STDERR <<USAGE;
Usage: $0 [-h|--help] [--sessions] [-v|--verbose] [--zebraqueue DAYS]
-h --help prints this help message, and exits, ignoring all other options
--sessions purge the sessions table. If you use this while users are logged
into Koha, they will have to reconnect.
-v --verbose will cause the script to give you a bit more information about the run.
--zebraqueue DAYS purge completed entries from the zebraqueue from more than DAYS days ago.
[-m|--mail]
-h --help prints this help message, and exits, ignoring all
other options
--sessions purge the sessions table. If you use this while users
are logged into Koha, they will have to reconnect.
-v --verbose will cause the script to give you a bit more information
about the run.
--zebraqueue DAYS purge completed entries from the zebraqueue from
more than DAYS days ago.
-m --mail purge the mail queue.
USAGE
exit $_[0];
}
my ($help, $sessions, $verbose, $zebraqueue_days);
my ($help, $sessions, $verbose, $zebraqueue_days, $mail);
GetOptions(
'h|help' => \$help,
'sessions' => \$sessions,
'h|help' => \$help,
'sessions' => \$sessions,
'v|verbose' => \$verbose,
'm|mail' => \$mail,
'zebraqueue:i' => \$zebraqueue_days,
) || usage(1);
@ -60,7 +66,7 @@ if ($help) {
usage(0);
}
if (!($sessions || $zebraqueue_days)){
if (!($sessions || $zebraqueue_days || $mail)){
print "You did not specify any cleanup work for the script to do.\n\n";
usage(1);
}
@ -103,4 +109,16 @@ if ($zebraqueue_days){
print "$count records were deleted.\nDone with zebraqueue purge.\n";
}
}
if ($mail) {
if ($verbose) {
$sth = $dbh->prepare("SELECT COUNT(*) FROM message_queue");
$sth->execute() or die $dbh->errstr;
my @count_arr = $sth->fetchrow_array;
print "Deleting $count_arr[0] entries from the mail queue.\n";
}
$sth = $dbh->prepare("TRUNCATE message_queue");
$sth->execute() or $dbh->errstr;
print "Done with purging the mail queue.\n" if ($verbose);
}
exit(0);