Skip to content

Commit

Permalink
Add a graceful restart for modperl/modproxy to wreservice.
Browse files Browse the repository at this point in the history
  • Loading branch information
perlDreamer committed Jul 10, 2012
1 parent 7b22b66 commit a58b139
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
36 changes: 36 additions & 0 deletions wre/lib/WRE/Modperl.pm
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions wre/lib/WRE/Modproxy.pm
Expand Up @@ -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 ( )
Expand Down
16 changes: 14 additions & 2 deletions wre/sbin/wreservice.pl
Expand Up @@ -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]
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a58b139

Please sign in to comment.