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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.