summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Bugzilla/JobQueue/Runner.pm80
-rw-r--r--contrib/bugzilla-queue109
-rwxr-xr-xjobqueue.pl20
3 files changed, 208 insertions, 1 deletions
diff --git a/Bugzilla/JobQueue/Runner.pm b/Bugzilla/JobQueue/Runner.pm
index 3c392209a..ef1bb8ef9 100644
--- a/Bugzilla/JobQueue/Runner.pm
+++ b/Bugzilla/JobQueue/Runner.pm
@@ -27,7 +27,9 @@
package Bugzilla::JobQueue::Runner;
use strict;
+use Cwd qw(abs_path);
use File::Basename;
+use File::Copy;
use Pod::Usage;
use Bugzilla::Constants;
@@ -37,6 +39,11 @@ BEGIN { eval "use base qw(Daemon::Generic)"; }
our $VERSION = BUGZILLA_VERSION;
+# Info we need to install/uninstall the daemon on RHEL/Fedora.
+our $chkconfig = "/sbin/chkconfig";
+our $initd = "/etc/init.d";
+our $initscript = "bugzilla-queue";
+
# The Daemon::Generic docs say that it uses all sorts of
# things from gd_preconfig, but in fact it does not. The
# only thing it uses from gd_preconfig is the "pidfile"
@@ -92,6 +99,79 @@ sub gd_usage {
return 0
}
+sub gd_can_install {
+ my $self = shift;
+
+ my $source_file = "contrib/$initscript";
+ my $dest_file = "$initd/$initscript";
+ my $sysconfig = '/etc/sysconfig';
+ my $config_file = "$sysconfig/$initscript";
+
+ if (!-x $chkconfig or !-d $initd) {
+ return $self->SUPER::gd_can_install(@_);
+ }
+
+ return sub {
+ if (!-w $initd) {
+ print "You must run the 'install' command as root.\n";
+ return;
+ }
+ if (-e $dest_file) {
+ print "$initscript already in $initd.\n";
+ }
+ else {
+ copy($source_file, $dest_file)
+ or die "Could not copy $source_file to $dest_file: $!";
+ chmod(0755, $dest_file)
+ or die "Could not change permissions on $dest_file: $!";
+ }
+
+ system($chkconfig, '--add', $initscript);
+ print "$initscript installed.",
+ " To start the daemon, do \"$dest_file start\" as root.\n";
+
+ if (-d $sysconfig and -w $sysconfig) {
+ if (-e $config_file) {
+ print "$config_file already exists.\n";
+ return;
+ }
+
+ open(my $config_fh, ">", $config_file)
+ or die "Could not write to $config_file: $!";
+ my $directory = abs_path(dirname($self->{_original_zero}));
+ my $owner_id = (stat $self->{_original_zero})[4];
+ my $owner = getpwuid($owner_id);
+ print $config_fh <<END;
+#!/bin/sh
+BUGZILLA="$directory"
+USER=$owner
+END
+ close($config_fh);
+ }
+ else {
+ print "Please edit $dest_file to configure the daemon.\n";
+ }
+ }
+}
+
+sub gd_can_uninstall {
+ my $self = shift;
+
+ if (-x $chkconfig and -d $initd) {
+ return sub {
+ if (!-e "$initd/$initscript") {
+ print "$initscript not installed.\n";
+ return;
+ }
+ system($chkconfig, '--del', $initscript);
+ print "$initscript disabled.",
+ " To stop it, run: $initd/$initscript stop\n";
+ }
+ }
+
+ return $self->SUPER::gd_can_install(@_);
+}
+
sub gd_check {
my $self = shift;
diff --git a/contrib/bugzilla-queue b/contrib/bugzilla-queue
new file mode 100644
index 000000000..3e00cce24
--- /dev/null
+++ b/contrib/bugzilla-queue
@@ -0,0 +1,109 @@
+#!/bin/bash
+#
+# bugzilla-queue This starts, stops, and restarts the Bugzilla jobqueue.pl
+# daemon, which manages sending queued mail and possibly
+# other queued tasks in the future.
+#
+# chkconfig: 345 85 15
+# description: Bugzilla queue runner
+#
+### BEGIN INIT INFO
+# Provides: bugzilla-queue
+# Required-Start: $local_fs $syslog MTA mysqld
+# Required-Stop: $local_fs $syslog MTA mysqld
+# Default-Start: 3 5
+# Default-Stop: 0 1 2 6
+# Short-Description: Start and stop the Bugzilla queue runner.
+# Description: The Bugzilla queue runner (jobqueue.pl) sends any mail
+# that Bugzilla has queued to be sent in the background. If you
+# have enabled the use_mailer_queue parameter in Bugzilla, you
+# must run this daemon.
+### END INIT INFO
+
+NAME=`basename $0`
+
+#################
+# Configuration #
+#################
+
+# This should be the path to your Bugzilla
+BUGZILLA=/var/www/html/bugzilla
+# Who owns the Bugzilla directory and files?
+USER=root
+
+# If you want to pass any options to the daemon (like -d for debugging)
+# specify it here.
+OPTIONS=""
+
+# You can also override the configuration by creating a
+# /etc/sysconfig/bugzilla-queue file so that you don't
+# have to edit this script.
+if [ -r /etc/sysconfig/$NAME ]; then
+ . /etc/sysconfig/$NAME
+fi
+
+##########
+# Script #
+##########
+
+RETVAL=0
+BIN=$BUGZILLA/jobqueue.pl
+PIDFILE=/var/run/$NAME.pid
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+usage ()
+{
+ echo "Usage: service $NAME {start|stop|status|restart|condrestart}"
+ RETVAL=1
+}
+
+
+start ()
+{
+ if [ -f "$PIDFILE" ]; then
+ checkpid `cat $PIDFILE` && return 0
+ fi
+ echo -n "Starting $NAME: "
+ touch $PIDFILE
+ chown $USER $PIDFILE
+ daemon --user=$USER \
+ "$BIN ${OPTIONS} -p '$PIDFILE' -n $NAME start > /dev/null"
+ ret=$?
+ [ $ret -eq "0" ] && touch /var/lock/subsys/$NAME
+ echo
+ return $ret
+}
+
+stop ()
+{
+ [ -f /var/lock/subsys/$NAME ] || return 0
+ echo -n "Killing $NAME: "
+ killproc $NAME
+ echo
+ rm -f /var/lock/subsys/$NAME
+}
+
+restart ()
+{
+ stop
+ start
+}
+
+condrestart ()
+{
+ [ -e /var/lock/subsys/$NAME ] && restart || return 0
+}
+
+
+case "$1" in
+ start) start; RETVAL=$? ;;
+ stop) stop; RETVAL=$? ;;
+ status) $BIN -p $PIDFILE -n $NAME check; RETVAL=$?;;
+ restart) restart; RETVAL=$? ;;
+ condrestart) condrestart; RETVAL=$? ;;
+ *) usage ; RETVAL=2 ;;
+esac
+
+exit $RETVAL
diff --git a/jobqueue.pl b/jobqueue.pl
index eae05456a..78490ddf0 100755
--- a/jobqueue.pl
+++ b/jobqueue.pl
@@ -37,7 +37,7 @@ jobqueue.pl - Runs jobs in the background for Bugzilla.
=head1 SYNOPSIS
- ./jobqueue.pl [OPTION] { start | stop | restart | check | help | version }
+ ./jobqueue.pl [OPTIONS] COMMAND
OPTIONS:
-f Run in the foreground (don't detach)
@@ -53,9 +53,27 @@ jobqueue.pl - Runs jobs in the background for Bugzilla.
restart Stops a running jobqueue if one is running, and then
starts a new one.
check Report the current status of the daemon.
+ install On some *nix systems, this automatically installs and
+ configures jobqueue.pl as a system service so that it will
+ start every time the machine boots.
+ uninstall Removes the system service for jobqueue.pl.
help Display this usage info
version Display the version of jobqueue.pl
=head1 DESCRIPTION
See L<Bugzilla::JobQueue> and L<Bugzilla::JobQueue::Runner>.
+
+=head1 Running jobqueue.pl as a System Service
+
+For systems that use Upstart or SysV Init, there is a SysV/Upstart init
+script included with Bugzilla for jobqueue.pl: F<contrib/bugzilla-queue>.
+It should work out-of-the-box on RHEL, Fedora, CentOS etc.
+
+You can install it by doing C<./jobqueue.pl install> as root, after
+already having run L<checksetup> at least once to completion
+on this Bugzilla installation.
+
+If you are using a system that isn't RHEL, Fedora, CentOS, etc., then you
+may have to modify F<contrib/bugzilla-queue> and install it yourself
+manually in order to get C<jobqueue.pl> running as a system service.