From 27cc3de61a1ad1a02b859cfe3dd96aa916295426 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Fri, 4 Sep 2009 21:20:16 +0000 Subject: Bug 475403: A RHEL SysV Init Script for jobqueue.pl Patch by Max Kanat-Alexander r=dkl, a=mkanat --- Bugzilla/JobQueue/Runner.pm | 80 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'Bugzilla/JobQueue') 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 <SUPER::gd_can_install(@_); +} + sub gd_check { my $self = shift; -- cgit v1.2.3-24-g4f1b