Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Trapping "Stop" on perl windows service

by sweetblood (Parson)
on May 15, 2009 at 17:44 UTC ( #764323=perlquestion: print w/ replies, xml ) Need Help??
sweetblood has asked for the wisdom of the Perl Monks concerning the following question:

I have built a perl script and have it running fine as a windows service using srvany. The service runs and does everything I want except, when the service is stopped by a "net stop" or by stopping the service via the control panel "services" app using "stop" or "restart" my END{} block does not fire. I'm using sigtrap to capture untrapped, normal-signals and error-signals and this works for most situations even if the server is brought down. The code below illustrates the issue, of course it must be added as a service in order to test.
#!/usr/bin/perl use strict; use warnings; use File::Basename; use sigtrap qw(die untrapped normal-signals error-signals); INIT { my $me = basename($0); sendmail('me@mydomain.com', "Service: $me Started", 'Service Start +ed') } END { my $me = basename($0); sendmail('me@mydomain.com', "Service: $me Ended", 'Service Ended') }
Although the service otherwise works it's a real nuisance not being able to trap these stop signals, I'd really prefer to do clean up on the stop rather than do it when the service starts.
Any thoughts are appreciated.

TIA

Sweetblood

Comment on Trapping "Stop" on perl windows service
Download Code
Re: Trapping "Stop" on perl windows service
by ikegami (Pope) on May 15, 2009 at 18:44 UTC

    Although the service otherwise works it's a real nuisance not being able to trap these stop signals,

    The whole point of SvrAny is to handle these for you. You'll have to stop using SvrAny to handle them yourself.

Re: Trapping "Stop" on perl windows service
by Jenda (Abbot) on May 17, 2009 at 09:37 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://764323]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2014-07-23 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (154 votes), past polls