diff options
author | mkanat%bugzilla.org <> | 2009-09-04 21:20:16 +0000 |
---|---|---|
committer | mkanat%bugzilla.org <> | 2009-09-04 21:20:16 +0000 |
commit | 27cc3de61a1ad1a02b859cfe3dd96aa916295426 (patch) | |
tree | 40eb935167c78b9a0040f0f1114279763dbe22d1 /Bugzilla | |
parent | ccaf82a249d988a9192034b5afa33b754aefd379 (diff) | |
download | bugs-27cc3de61a1ad1a02b859cfe3dd96aa916295426.tar bugs-27cc3de61a1ad1a02b859cfe3dd96aa916295426.tar.gz bugs-27cc3de61a1ad1a02b859cfe3dd96aa916295426.tar.bz2 bugs-27cc3de61a1ad1a02b859cfe3dd96aa916295426.tar.xz bugs-27cc3de61a1ad1a02b859cfe3dd96aa916295426.zip |
Bug 475403: A RHEL SysV Init Script for jobqueue.pl
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=dkl, a=mkanat
Diffstat (limited to 'Bugzilla')
-rw-r--r-- | Bugzilla/JobQueue/Runner.pm | 80 |
1 files changed, 80 insertions, 0 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; |