On Fri, 10 Oct 2003, Steve Hay wrote:
[ ... ]
> I don't know how to do the "graceful" stop, though. What
> we want is a bit like trying TERM then KILL on Unix, but
> that doesn't work on Win32 -- see the entry for kill() in
> the perlport manpage! Win32::Process doesn't have any
> "graceful" kill options either, and the "apache.exe -k
> stop" command-line that I mentioned above only relates to
> installed Apache2 *services*, not processes started from a
> command shell. Any ideas, Randy?
At one point I had played around with using a service to get
around this problem - have Apache::Test install a temporary
service, then use "Apache -k start" / "Apache -k stop" to
start / stop the server. While this does things gracefully,
so that the pid file is removed, I think there may be some
problems with some users not having the right permissions
to install a service.
Like you, I can't see how Win32::Process can gracefully kill
a process (one seems to need to terminate a process using
WM_CLOSE - I've seen examples of how to do this, but this
involves non-standard Win32 modules). What about the following:
============================================================
Index: lib/Apache/TestServer.pm
===================================================================
RCS file:
/home/cvspublic/httpd-test/perl-framework/Apache-Test/lib/Apache/TestServer.pm,v
retrieving revision 1.67
diff -u -r1.67 TestServer.pm
--- lib/Apache/TestServer.pm 10 Oct 2003 04:05:56 -0000 1.67
+++ lib/Apache/TestServer.pm 10 Oct 2003 17:06:15 -0000
@@ -314,18 +314,22 @@
my $aborted = shift;
if (Apache::TestConfig::WIN32) {
- if ($self->{config}->{win32obj}) {
- $self->{config}->{win32obj}->Kill(0);
- warning "server $self->{name} shutdown";
- return 1;
+ my $pid;
+ if (my $obj = $self->{config}->{win32obj}) {
+ $pid = $obj->GetProcessID();
}
else {
+ $pid = $self->pid;
+ }
+ if (kill(0, $pid)) {
require Win32::Process;
- my $pid = $self->pid;
Win32::Process::KillProcess($pid, 0);
warning "server $self->{name} shutdown";
- return 1;
- }
+ if (-f $self->pid_file) {
+ unlink $self->pid_file;
+ }
+ }
+ return 1;
}
my $pid = 0;
@@ -437,6 +441,10 @@
my $old_sig;
if (Apache::TestConfig::WIN32) {
+ # make sure no stale pid file is around
+ if (-f $self->pid_file) {
+ unlink $self->pid_file;
+ }
#make sure only 1 process is started for win32
#else Kill will only shutdown the parent
my $one_process = $self->version_of(\%one_process);
==================================================================
which kills the process (if it's alive - that's what
kill(0, $pid) is supposed to check), and if it does so,
explicitly unlinks the pid file. It also, when the server
starts, unlinks a pid file if that exists, as presumably
that's a stale one.
--
best regards,
randy
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]