Re: How to recognize server shutdown?

2001-01-11 Thread Perrin Harkins

On Thu, 11 Jan 2001, Doug MacEachern wrote:
> of course, there is such a "trick"
> 
>[EMAIL PROTECTED]">http://forum.swarthmore.edu/epigone/modperl/thandflunjimp/[EMAIL PROTECTED]

Documentation patch attached.
- Perrin


1039a1040,1046
> Cleanup functions registered in the parent process (before forking) will run
> once when the server is shut down:
> 
>#PerlRequire startup.pl
>warn "parent pid is $$\n";
>Apache->server->register_cleanup(sub { warn "server cleanup in $$\n"});
> 



Re: How to recognize server shutdown?

2001-01-11 Thread Ernest Lergon

Doug MacEachern wrote:
>
>> I meant "is there a way to run a cleanup handler in the parent after it's
>> work is done?", but I don't see one.  Dave says the END block trick worked
>> for him, so maybe it only fails under certain circumstances.
>>
> of course, there is such a "trick"
> 
>[EMAIL PROTECTED]">http://forum.swarthmore.edu/epigone/modperl/thandflunjimp/[EMAIL PROTECTED]

Sorry, I should have dropped earlier into this thread: Doug's "trick"
works great for me!

Thanks!

Ernest




--
Yours sincerely
Mit freundlichen Grüßen

Ernest Lergon

VIRTUALITAS
Artists online, Fine Arts online, Poets online
http://www.virtualitas.com/




Re: How to recognize server shutdown?

2001-01-11 Thread Doug MacEachern

On Wed, 10 Jan 2001, Stas Bekman wrote:
 
> All we need is to add a $Apache::Server::Quitting or alike, in addition to
> the existing $Apache::Server::Starting and $Apache::Server::ReStarting,
> should be an easy patch in XS.

nooo, as i've mentioned before Starting,ReStarting variables were
mistakes, and they will be either deprecated or more likely non-existent
in 2.0





Re: How to recognize server shutdown?

2001-01-11 Thread Dave Rolsky

On Thu, 11 Jan 2001, Perrin Harkins wrote:

> I meant "is there a way to run a cleanup handler in the parent after it's
> work is done?", but I don't see one.  Dave says the END block trick worked
> for him, so maybe it only fails under certain circumstances.

Actually, I should have pointed out that I haven't yet tested it in
mod_perl.  I tested it in an environment where I was spawning some of my
own proceses.  That worked.  I'll test it in mod_perl soon.


-dave

/*==
www.urth.org
We await the New Sun
==*/




Re: How to recognize server shutdown?

2001-01-11 Thread Doug MacEachern

On Thu, 11 Jan 2001, Perrin Harkins wrote:

> > > but it's a bummer that the parent
> > > doesn't run END blocks.  Will it run cleanup handlers?
> >
> > Cleanup handlers are run by child processes. What it has to do with
> > parent? Or do I miss something?

cleanup handlers are run when a pool is cleared.  the request lifetime
pool is one pool, the server lifetime pool is another, etc.

> I meant "is there a way to run a cleanup handler in the parent after it's
> work is done?", but I don't see one.  Dave says the END block trick worked
> for him, so maybe it only fails under certain circumstances.

of course, there is such a "trick"
[EMAIL PROTECTED]">http://forum.swarthmore.edu/epigone/modperl/thandflunjimp/[EMAIL PROTECTED]




Re: How to recognize server shutdown?

2001-01-11 Thread Perrin Harkins

> > but it's a bummer that the parent
> > doesn't run END blocks.  Will it run cleanup handlers?
>
> Cleanup handlers are run by child processes. What it has to do with
> parent? Or do I miss something?

I meant "is there a way to run a cleanup handler in the parent after it's
work is done?", but I don't see one.  Dave says the END block trick worked
for him, so maybe it only fails under certain circumstances.
- Perrin




Re: How to recognize server shutdown?

2001-01-11 Thread G.W. Haywood

Hi all,

On 10 Jan 2001, Randal L. Schwartz wrote:

> Here's an idea... in the startup code, create a pipe and fork.
> block the kid on a read.  ni-night, kid.

Nice, Randall!

73,
Ged.




Re: How to recognize server shutdown?

2001-01-11 Thread Stas Bekman

On Wed, 10 Jan 2001, Perrin Harkins wrote:

> On Thu, 11 Jan 2001, Stas Bekman wrote:
> > the parent process doesn't run the END block.
>
> Randal's solution is probably better,

But it's not a very nice solution if you want to release something on CPAN
that relies on this hack. A support from mod_perl seems like a much
simpler solution.

> but it's a bummer that the parent
> doesn't run END blocks.  Will it run cleanup handlers?

Cleanup handlers are run by child processes. What it has to do with
parent? Or do I miss something?

_
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/





Re: How to recognize server shutdown?

2001-01-10 Thread Dave Rolsky

On Wed, 10 Jan 2001, Perrin Harkins wrote:

> Randal's solution is probably better, but it's a bummer that the parent
> doesn't run END blocks.  Will it run cleanup handlers?

I'm pretty sure the parent runs END blocks.  I just didn't want to have
the cleanup code run during child shutdown.

What I've done for now is this hack:


use vars qw($PID);

BEGIN
{

$PID = $$;
}

END
{
if ($$ == $PID )
{
# do cleanup
}
}

The only issue with that is what happens if the code is used in an
environment where a process starts up, forks a child, and then dies,
allowing the child to continue.

Hmm, I think I'll have to just doc it.

This is all related to clearing up an shared memory segment (and
semaphores) created by IPC::Shareable.  Except I realized IPC::Shareable
can do it.  Its just that for its boolean options it expects 'yes' or
'no', not 1 or 0.  That's freaking brilliant.  ARGH!


-dave

/*==
www.urth.org
We await the New Sun
==*/




Re: How to recognize server shutdown?

2001-01-10 Thread Perrin Harkins

On Thu, 11 Jan 2001, Stas Bekman wrote:
> the parent process doesn't run the END block.

Randal's solution is probably better, but it's a bummer that the parent
doesn't run END blocks.  Will it run cleanup handlers?
- Perrin




Re: How to recognize server shutdown?

2001-01-10 Thread Randal L. Schwartz

> "Stas" == Stas Bekman <[EMAIL PROTECTED]> writes:

Stas> On Wed, 10 Jan 2001, Perrin Harkins wrote:
>> On Wed, 10 Jan 2001, Dave Rolsky wrote:
>> > Is there any way to distinguish between a child being shutdown (say
>> > maxrequests has been exceeded) versus all of Apache going down (kill
>> > signal sent to the original process or something).
>> 
>> Register an END block in your startup.pl, and have it check it's PID to
>> see if it's the parent.

Stas> It doesn't work. I've tested:

Here's an idea... in the startup code, create a pipe and fork.
block the kid on a read.  ni-night, kid.

when the parent quits, the kid will get EOF, and can go off and clean
things up.

in fact, it won't get the EOF until *all* the processes sharing the
write-end have quit, so it would seem to be exactly what is needed.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



Re: How to recognize server shutdown?

2001-01-10 Thread Stas Bekman

On Wed, 10 Jan 2001, Perrin Harkins wrote:

> On Wed, 10 Jan 2001, Dave Rolsky wrote:
> > Is there any way to distinguish between a child being shutdown (say
> > maxrequests has been exceeded) versus all of Apache going down (kill
> > signal sent to the original process or something).
>
> Register an END block in your startup.pl, and have it check it's PID to
> see if it's the parent.

It doesn't work. I've tested:

startup.pl:
---
package Cleanup;

$Cleanup::parent_pid = $$;

END{

eval q{
   if ($$ == $Cleanup::parent_pid) {
   `echo $Cleanup::parent_pid $$ >> /tmp/parent`;
   } else {
   `echo $Cleanup::parent_pid $$ >> /tmp/children`;
   }
  };
}

the parent process doesn't run the END block.

_
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/





Re: How to recognize server shutdown?

2001-01-10 Thread Perrin Harkins

On Wed, 10 Jan 2001, Dave Rolsky wrote:
> Is there any way to distinguish between a child being shutdown (say
> maxrequests has been exceeded) versus all of Apache going down (kill
> signal sent to the original process or something).

Register an END block in your startup.pl, and have it check it's PID to
see if it's the parent.
- Perrin




Re: How to recognize server shutdown?

2001-01-10 Thread Dave Rolsky

On Wed, 10 Jan 2001, Stas Bekman wrote:

> All we need is to add a $Apache::Server::Quitting or alike, in addition to
> the existing $Apache::Server::Starting and $Apache::Server::ReStarting,
> should be an easy patch in XS.

I'm not much of an C coder (much less XS) but maybe I'll poke around a
bit.


-dave

/*==
www.urth.org
We await the New Sun
==*/




Re: How to recognize server shutdown?

2001-01-10 Thread Stas Bekman

On Wed, 10 Jan 2001, Dave Rolsky wrote:

> On Wed, 10 Jan 2001, G.W. Haywood wrote:
>
> > Don't you get a message in error_log to the effect that a signal has
> > been received?
>
> Sure, but I don't think that would help me do what I want.
>
> Let me illustrate:
>
> 1.  server is started
> 2.  config is read, modules are loaded, BEGIN blocks are run in this
> process (just once)
> 3.  X children are created
> 4.  children are born, they die, yadda yadda.  The END block is run
> whenever a child dies.
> 5.  the server is told to shut down
> 6.  the first server to start (the one running as root or whatever) sends
> signals to the children telling them to shutdown.  END blocks run in all
> children.
> 7.  the first server shuts down - I'd like to run something here because
> it should only be happening to during a 'final' shutdown and only after
> the children have finished serving their last requests.

All we need is to add a $Apache::Server::Quitting or alike, in addition to
the existing $Apache::Server::Starting and $Apache::Server::ReStarting,
should be an easy patch in XS.

>
>
> -dave
>
> /*==
> www.urth.org
> We await the New Sun
> ==*/
>



_
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/





Re: How to recognize server shutdown?

2001-01-10 Thread G.W. Haywood

Hi there,

On Wed, 10 Jan 2001, Dave Rolsky wrote:

> On Wed, 10 Jan 2001, G.W. Haywood wrote:
> 
> > Don't you get a message in error_log to the effect that a signal has
> > been received?
> 
> Sure, but I don't think that would help me do what I want.

What I meant was you could perhaps find the place in the code where it
did that and do something else there too...

73,
Ged.




Re: How to recognize server shutdown?

2001-01-10 Thread Dave Rolsky

On Wed, 10 Jan 2001, Danny Rathjens wrote:

> Perhaps you could send a USR1 prior to your TERM signal and have your
> END blocks perform your shutdown tasks if they see the USR1 signal.
> But then you have the problem of new children being started due to the
> USR1 not to mention it would preclude using USR1 for doing normal
> graceful restarts, 8^)

This is for code that will be publicly distributed.  I don't want to
require people to send a nonstandard signal just to shut down their
server.

> Hrm, would be nice if $r->server had a method to tell you if apache is
> in the process of shutting down or not.

That's what I want.


/*==
www.urth.org
We await the New Sun
==*/




Re: How to recognize server shutdown?

2001-01-10 Thread Robin Berjon

At 18:55 10/01/2001 +, Danny Rathjens wrote:
>Perhaps you could send a USR1 prior to your TERM signal and have your
>END blocks perform your shutdown tasks if they see the USR1 signal.
>But then you have the problem of new children being started due to the
>USR1
>not to mention it would preclude using USR1 for doing normal graceful
>restarts, 8^)

What about USR2 ? Afair it isn't used and could probably be caught. In that
case it would be possible to use it prior to a TERM to signal imminent
shutdown.

-- robin b.
The computer can't tell you the emotional story.  It can give you the exact
mathematical design, but what's missing is the eyebrows. -- Frank Zappa




Re: How to recognize server shutdown?

2001-01-10 Thread Danny Rathjens

Dave Rolsky wrote:
> 
> On Wed, 10 Jan 2001, G.W. Haywood wrote:
> 
> > Don't you get a message in error_log to the effect that a signal has
> > been received?
> 
> Sure, but I don't think that would help me do what I want.
> 
> Let me illustrate:
> 
> 1.  server is started
> 2.  config is read, modules are loaded, BEGIN blocks are run in this
> process (just once)
> 3.  X children are created
> 4.  children are born, they die, yadda yadda.  The END block is run
> whenever a child dies.
> 5.  the server is told to shut down
> 6.  the first server to start (the one running as root or whatever) sends
> signals to the children telling them to shutdown.  END blocks run in all
> children.
> 7.  the first server shuts down - I'd like to run something here because
> it should only be happening to during a 'final' shutdown and only after
> the children have finished serving their last requests.
> 
Perhaps you could send a USR1 prior to your TERM signal and have your
END blocks perform your shutdown tasks if they see the USR1 signal.
But then you have the problem of new children being started due to the
USR1
not to mention it would preclude using USR1 for doing normal graceful
restarts, 8^)

Hrm, would be nice if $r->server had a method to tell you if apache is
in the process of shutting down or not.
-- 
struct Programmer/Analyst 'Danny Rathjens' {this.place =
"MyCity.com";}
I know you believe you understood what you think I said, but I
am not sure you realize that what you heard is not what I meant.



Re: How to recognize server shutdown?

2001-01-10 Thread Dave Rolsky

On Wed, 10 Jan 2001, G.W. Haywood wrote:

> Don't you get a message in error_log to the effect that a signal has
> been received?

Sure, but I don't think that would help me do what I want.

Let me illustrate:

1.  server is started
2.  config is read, modules are loaded, BEGIN blocks are run in this
process (just once)
3.  X children are created
4.  children are born, they die, yadda yadda.  The END block is run
whenever a child dies.
5.  the server is told to shut down
6.  the first server to start (the one running as root or whatever) sends
signals to the children telling them to shutdown.  END blocks run in all
children.
7.  the first server shuts down - I'd like to run something here because
it should only be happening to during a 'final' shutdown and only after
the children have finished serving their last requests.


-dave

/*==
www.urth.org
We await the New Sun
==*/




Re: How to recognize server shutdown?

2001-01-10 Thread G.W. Haywood

Hi Dave,

On Wed, 10 Jan 2001, Dave Rolsky wrote:

> Is there any way to distinguish between a child being shutdown (say
> maxrequests has been exceeded) versus all of Apache going down (kill
> signal sent to the original process or something).

Don't you get a message in error_log to the effect that a signal has
been received?

73,
Ged.





How to recognize server shutdown?

2001-01-09 Thread Dave Rolsky

Is there any way to distinguish between a child being shutdown (say
maxrequests has been exceeded) versus all of Apache going down (kill
signal sent to the original process or something).

The reason I ask is that while I can do:

BEGIN
{
 # make a file
}

I can't do:

END
{
 # delete a file
}

and get good results.


I suspect the answer to this is no but I'm curious as to whether anybody's
come up with a way to detect a 'real' shutdown.


-dave

/*==
www.urth.org
We await the New Sun
==*/