Skip to content
Permalink
Browse files

Add a graceful restart for modperl/modproxy to wreservice.

  • Loading branch information...
perlDreamer committed Jul 10, 2012
1 parent 7b22b66 commit a58b13917f4c195aaa7ef5946febbd5e26f3c7f6
Showing with 86 additions and 2 deletions.
  1. +36 −0 wre/lib/WRE/Modperl.pm
  2. +36 −0 wre/lib/WRE/Modproxy.pm
  3. +14 −2 wre/sbin/wreservice.pl
@@ -43,6 +43,42 @@ sub getName {

#-------------------------------------------------------------------

=head2 graceful ( )
Performs a graceful restart of this service.
Note: The process that runs this command must be either root or the user specified in the WRE config file.
=cut

sub graceful {
my $self = shift;
my $wreConfig = $self->wreConfig;
my $host = WRE::Host->new(wreConfig=>$wreConfig);
unless ($wreConfig->get("apache/modperlPort") > 1024 || $host->isPrivilegedUser) {
croak "You are not an administrator on this machine so you cannot start services with ports 1-1024.";
}
my $cmd = "";
if ($host->getOsName eq "windows") {
$cmd = "net start WREmodperl";
}
else {
$cmd = $wreConfig->getRoot("/prereqs/bin/apachectl")." -f ".$wreConfig->getRoot("/etc/modperl.conf")
." -D WRE-modperl -E ".$wreConfig->getRoot("/var/logs/modperl.error.log")." -k graceful";
}
my $count = 0;
my $success = 0;
`$cmd`; # catch command line output
while ($count < 10 && $success == 0) {
sleep(1);
eval {$success = $self->ping};
$count++;
}
return $success;
}

#-------------------------------------------------------------------

=head killRunaways ()
Kills any processes that are larger than the maxMemory setting in the config file. Returns the number of processes
@@ -39,6 +39,42 @@ sub getName {
}


#-------------------------------------------------------------------

=head2 graceful ( )
Performs a graceful restart of this service.
Note: The process that runs this command must be either root or the user specified in the WRE config file.
=cut

sub graceful {
my $self = shift;
my $wreConfig = $self->wreConfig;
my $host = WRE::Host->new(wreConfig=>$wreConfig);
unless ($wreConfig->get("apache/modproxyPort") > 1024 || $host->isPrivilegedUser) {
croak "You are not an administrator on this machine so you cannot start services with ports 1-1024.";
}
my $cmd = "";
if ($host->getOsName eq "windows") {
$cmd = "net start WREmodproxy";
}
else {
$cmd = $wreConfig->getRoot("/prereqs/bin/apachectl")." -f ".$wreConfig->getRoot("/etc/modproxy.conf")
." -D WRE-modproxy -E ".$wreConfig->getRoot("/var/logs/modproxy.error.log")." -k graceful";
}
my $count = 0;
my $success = 0;
`$cmd`; # catch command line output
while ($count < 10 && $success == 0) {
sleep(1);
eval {$success = $self->ping};
$count++;
}
return $success;
}

#-------------------------------------------------------------------

=head2 ping ( )
@@ -23,19 +23,20 @@
$|=1; # turn off buffering

my ($quiet, $help, $verbose) = "";
my (@start, @stop, @restart, @status) = ();
my (@start, @stop, @restart, @status, @graceful) = ();

GetOptions(
"help" => \$help,
"start|begin=s{1,4}" => \@start,
"stop|end|shutdown=s{1,4}" => \@stop,
"restart|cycle=s{1,4}" => \@restart,
"status|ping=s{1,4}" => \@status,
"graceful|ping=s{1,2}" => \@graceful,
"verbose" => \$verbose,
"quiet" => \$quiet,
);

if ($help || !(scalar(@start) || scalar(@stop) || scalar(@restart) || scalar(@status))) {
if ($help || !(scalar(@start) || scalar(@stop) || scalar(@restart) || scalar(@status) || scalar(@graceful))) {
print <<STOP;
Usage: $0 --[action] [service] [service] [service]
@@ -64,6 +65,8 @@
--restart Stops and then starts a service again.
--graceful Does a graceful restart, but only for apache based services
--shutdown An alias for --stop.
--start Puts a service online.
@@ -151,6 +154,15 @@
}
}

if (scalar(@graceful)) {
if (grep /^modperl|all|web$/, @status) {
printSuccess(sub{WRE::Modperl->new(wreConfig=>$config)->graceful}, "Graceful mod_perl");
}
if (grep /^modproxy|all|web$/, @status) {
printSuccess(sub{WRE::Modproxy->new(wreConfig=>$config)->graceful}, "Graceful mod_proxy");
}
}

#-------------------------------------------------------------------
sub printSuccess {
my $action = shift;

0 comments on commit a58b139

Please sign in to comment.
You can’t perform that action at this time.