Skip to content

Commit a58b139

Browse files
committedJul 10, 2012
Add a graceful restart for modperl/modproxy to wreservice.
1 parent 7b22b66 commit a58b139

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed
 

‎wre/lib/WRE/Modperl.pm

+36
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,42 @@ sub getName {
4343

4444
#-------------------------------------------------------------------
4545

46+
=head2 graceful ( )
47+
48+
Performs a graceful restart of this service.
49+
50+
Note: The process that runs this command must be either root or the user specified in the WRE config file.
51+
52+
=cut
53+
54+
sub graceful {
55+
my $self = shift;
56+
my $wreConfig = $self->wreConfig;
57+
my $host = WRE::Host->new(wreConfig=>$wreConfig);
58+
unless ($wreConfig->get("apache/modperlPort") > 1024 || $host->isPrivilegedUser) {
59+
croak "You are not an administrator on this machine so you cannot start services with ports 1-1024.";
60+
}
61+
my $cmd = "";
62+
if ($host->getOsName eq "windows") {
63+
$cmd = "net start WREmodperl";
64+
}
65+
else {
66+
$cmd = $wreConfig->getRoot("/prereqs/bin/apachectl")." -f ".$wreConfig->getRoot("/etc/modperl.conf")
67+
." -D WRE-modperl -E ".$wreConfig->getRoot("/var/logs/modperl.error.log")." -k graceful";
68+
}
69+
my $count = 0;
70+
my $success = 0;
71+
`$cmd`; # catch command line output
72+
while ($count < 10 && $success == 0) {
73+
sleep(1);
74+
eval {$success = $self->ping};
75+
$count++;
76+
}
77+
return $success;
78+
}
79+
80+
#-------------------------------------------------------------------
81+
4682
=head killRunaways ()
4783
4884
Kills any processes that are larger than the maxMemory setting in the config file. Returns the number of processes

‎wre/lib/WRE/Modproxy.pm

+36
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,42 @@ sub getName {
3939
}
4040

4141

42+
#-------------------------------------------------------------------
43+
44+
=head2 graceful ( )
45+
46+
Performs a graceful restart of this service.
47+
48+
Note: The process that runs this command must be either root or the user specified in the WRE config file.
49+
50+
=cut
51+
52+
sub graceful {
53+
my $self = shift;
54+
my $wreConfig = $self->wreConfig;
55+
my $host = WRE::Host->new(wreConfig=>$wreConfig);
56+
unless ($wreConfig->get("apache/modproxyPort") > 1024 || $host->isPrivilegedUser) {
57+
croak "You are not an administrator on this machine so you cannot start services with ports 1-1024.";
58+
}
59+
my $cmd = "";
60+
if ($host->getOsName eq "windows") {
61+
$cmd = "net start WREmodproxy";
62+
}
63+
else {
64+
$cmd = $wreConfig->getRoot("/prereqs/bin/apachectl")." -f ".$wreConfig->getRoot("/etc/modproxy.conf")
65+
." -D WRE-modproxy -E ".$wreConfig->getRoot("/var/logs/modproxy.error.log")." -k graceful";
66+
}
67+
my $count = 0;
68+
my $success = 0;
69+
`$cmd`; # catch command line output
70+
while ($count < 10 && $success == 0) {
71+
sleep(1);
72+
eval {$success = $self->ping};
73+
$count++;
74+
}
75+
return $success;
76+
}
77+
4278
#-------------------------------------------------------------------
4379

4480
=head2 ping ( )

‎wre/sbin/wreservice.pl

+14-2
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@
2323
$|=1; # turn off buffering
2424

2525
my ($quiet, $help, $verbose) = "";
26-
my (@start, @stop, @restart, @status) = ();
26+
my (@start, @stop, @restart, @status, @graceful) = ();
2727

2828
GetOptions(
2929
"help" => \$help,
3030
"start|begin=s{1,4}" => \@start,
3131
"stop|end|shutdown=s{1,4}" => \@stop,
3232
"restart|cycle=s{1,4}" => \@restart,
3333
"status|ping=s{1,4}" => \@status,
34+
"graceful|ping=s{1,2}" => \@graceful,
3435
"verbose" => \$verbose,
3536
"quiet" => \$quiet,
3637
);
3738

38-
if ($help || !(scalar(@start) || scalar(@stop) || scalar(@restart) || scalar(@status))) {
39+
if ($help || !(scalar(@start) || scalar(@stop) || scalar(@restart) || scalar(@status) || scalar(@graceful))) {
3940
print <<STOP;
4041
Usage: $0 --[action] [service] [service] [service]
4142
@@ -64,6 +65,8 @@
6465
6566
--restart Stops and then starts a service again.
6667
68+
--graceful Does a graceful restart, but only for apache based services
69+
6770
--shutdown An alias for --stop.
6871
6972
--start Puts a service online.
@@ -151,6 +154,15 @@
151154
}
152155
}
153156

157+
if (scalar(@graceful)) {
158+
if (grep /^modperl|all|web$/, @status) {
159+
printSuccess(sub{WRE::Modperl->new(wreConfig=>$config)->graceful}, "Graceful mod_perl");
160+
}
161+
if (grep /^modproxy|all|web$/, @status) {
162+
printSuccess(sub{WRE::Modproxy->new(wreConfig=>$config)->graceful}, "Graceful mod_proxy");
163+
}
164+
}
165+
154166
#-------------------------------------------------------------------
155167
sub printSuccess {
156168
my $action = shift;

0 commit comments

Comments
 (0)
Please sign in to comment.