[Catalyst] Proper way to perform cleanups on server shutdown?

John Napiorkowski jjn1056 at yahoo.com
Wed Jul 11 19:29:29 GMT 2007


--- Mark Zealey <mark at itsolve.co.uk> wrote:

> Perhaps I'm missing something, but what's the
> problem with doing something 
> like:
> 
> package MyApp;
> 
> $SIG{INT} = sub {
>   graceful_shutdown();
>   exit(1);
> }
> 
> END { graceful_shutdown() }
> 
> sub graceful_shutdown {
>   # Code here...
> }
> 
> Note that a $SIG{INT} will not exit if you override
> it, which is why you need 
> the exit. This means that you could make it restart
> on a SIG{INT} (or perhaps 
> better, $SIG{HUP})

Hmm, I didn't know that (obviously).  That's probably
why when I do 

$SIG{INT} = sub {}

in my MyApp.pm file I get the proper cleanup, since
I'm capturing the call for an immediate interrupt.  I
guess the TERM signal must work the same way.

The main problem for me is not that I have shutdown
and cleanup in my custom code, but that some modules
I'm using (File::Temp) define END blocks to perform
their own cleanup chores.  Really I think this is the
best way, rather than to try and have one big uber
cleanup routine in my core module, let each module
that needs to do housekeeping handle it's own.

Thanks to you for pointing this out to me, and to
others who've responded and pointed out other useful
bits.

--john

> 
> Mark
> 



       
____________________________________________________________________________________Ready for the edge of your seat? 
Check out tonight's top picks on Yahoo! TV. 
http://tv.yahoo.com/



More information about the Catalyst mailing list