Below is a solution to this problem:
* fork the long running process from mod_perl
* and be able to restart the server
o without killing this process
o without this process keeping the socket busy
and thus preventing the server restart
Thanks to Doug for the hint. You need to patch Apache::SubProcess (CPAN):
--- SubProcess.xs.orig Sat Sep 25 19:17:12 1999
+++ SubProcess.xs Tue Dec 19 21:03:22 2000
@@ -103,6 +103,14 @@
XPUSHs(io_hook(ioep, io_hook_read));
}
+
+void
+ap_cleanup_after_fork(r)
+ Apache r
+
+ CODE:
+ ap_cleanup_for_exec();
+
int
ap_call_exec(r, pgm=r->filename)
Apache r
which makes the new method available: cleanup_after_fork()
This is the clean test case that shows that the conditions are fulfilled
properly:
use strict;
use POSIX 'setsid';
use Apache::SubProcess;
my $r = shift;
$r->send_http_header("text/plain");
$SIG{CHLD} = 'IGNORE';
defined (my $kid = fork) or die "Cannot fork: $!\n";
if ($kid) {
print "Parent $$ has finished, kid's PID: $kid\n";
} else {
$r->cleanup_after_fork();
chdir '/' or die "Can't chdir to /: $!";
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
open STDOUT, '>/dev/null'
or die "Can't write to /dev/null: $!";
open STDERR, '>/tmp/log' or die "Can't write to /tmp/log: $!";
setsid or die "Can't start a new session: $!";
local $|=1;
warn "started\n";
# do something time-consuming
sleep 1, warn "$_\n" for 1..20;
warn "completed\n";
# we want the process to be terminated, Apache::exit() won't
# terminate the process
CORE::exit(0);
}
both processes are completely idependent now. Watch the /tmp/log as the
forked process works, while you can restart the server.
When I'll complete the rewrite of this section I'll post it all, with the
solutions for exec/system as well (using Apache::SubProcess of course).
And just a note, you always need setsid, so the server won't kill the
spawned process when the server restarts.
More cases/explanations to come soonish.
Thanks to those who have raised this problem.
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:[EMAIL PROTECTED] http://apachetoday.com http://logilune.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/