> 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.
Thank you very much, that works great and it looks much neater than what
I had before.
BTW. what is the function of the chdir '/', is that needed or can I
leave that out?
Kees