Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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('', "Service: $me Started", 'Service Start +ed') } END { my $me = basename($0); sendmail('', "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.



Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://764323]
Front-paged by Arunbear
[Lady_Aleena]: What?! Can't stat ~/Music: No such file or directory? The ~/ doesn't expand?
[Lady_Aleena]: And the env variable $HOME doesn't work either. !@#$
[shmem]: no, that's a shell feature. Use $ENV{HOME}
[marioroy]: my $ans = qx{ find \$HOME -name "*.pl" -exec ls -l {} \\; };
[marioroy]: must backslash $ inside qx
[Lady_Aleena]: I haven't written perl for a while, I've been trying to do things at the command line. I'm having to relearn a lot.
[marioroy]: LA can you post the qx find again
[Lady_Aleena]: Things I would have written a script for while I was on Windows, I can run simply on the command line.

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2017-04-23 21:05 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (432 votes). Check out past polls.