Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Trapping "Stop" on perl windows service

by sweetblood (Prior)
on May 15, 2009 at 17:44 UTC ( [id://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

Replies are listed 'Best First'.
Re: Trapping "Stop" on perl windows service
by ikegami (Patriarch) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-26 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found