in reply to Debugging Windows Services created with Win32::Daemon

I'd redirect STDERR to a file (and probably do that in a BEGIN block near the top of the main script file). When Perl dies, it almost always says something on the way down. I suspect Win32 is just throwing this information away.

Using threads in Perl sounds like a recipe for having things die rather mysterious to me. So I'm not surprised you've experienced this.

You might want to write a manager that gets run as a service and have it launch and re-launch the script that does the real work. It is also a good idea to have long-running processes restart themselves periodically. If you write the manager, then you could just have the worker script exit when idle if its been running longer than X. Getting the manager restarted periodically is trickier. On Unix, I'd just occasionally do exec($^X,$0,@ARGV), but I recall exec being more like system+exit in Win32 (despite MicroSoft claiming "the new process is placed in the memory previously occupied by the calling process") and that might not play well with the Service Control Manager or other bits.

- tye        

  • Comment on Re: Debugging Windows Services created with Win32::Daemon (STDERR)
  • Download Code

Replies are listed 'Best First'.
Re^2: Debugging Windows Services created with Win32::Daemon (STDERR)
by BrowserUk (Patriarch) on Nov 16, 2005 at 18:36 UTC
    I'd redirect STDERR to a file (and probably do that in a BEGIN block near the top of the main script file).

    Using Win32::EventLog in conjunction with a __DIE__ handler would perhaps be a better solution.

    When Perl dies, it almost always says something on the way down. I suspect Win32 is just throwing this information away.

    Wouldn't a pucker *nix daemon also throw away any parting STDERR output? The done thing is to close all the standard filestreams isn't it?

    It's quite likely that (if enabled) any non-zero termination code or STDERR output would end up in the system or application portion of the event log


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Using Win32::EventLog in conjunction with a __DIE__ handler would perhaps be a better solution.

      If you define "better" as "still throws away lots of possible sources of information". Eventually, I'd do both. As a first step in figuring out what is going wrong, I'd go with the much simpler approach that catches stuff other than just die cases. To illustrate just one case: I wouldn't be at all surprised if Perl, after reporting "panic: ...", might not survive long enough to make it all the way to the end of the non-trivial number of opcodes required to catch then get stuff into the event log.

      Wouldn't a pucker *nix daemon also throw away any parting STDERR output? The done thing is to close all the standard filestreams isn't it?

      A production-quality daemon usually redirects STDERR to /dev/null (closing is a bad idea). But a Unix daemon who doesn't do this could end up with its output automatically going to the system log (or, on some older Unixes, to "the console"). On some old Unix configurations, this could actually cause problems. My comment wasn't meant to be a dig against Win32. I still suspect that Win32 is just throwing away the information. And sometimes that has its advantages. No need to get defensive. (:

      It's quite likely that (if enabled) any non-zero termination code or STDERR output would end up in the system or application portion of the event log

      What does "if enabled" mean? If there is a Win32 option to redirect daemon output to the event log, then hackdaddy would probably appreciate a pointer to it. He reports that such isn't happening for him.

      - tye        

        I was thinking of the option on Settings->cotrolPanel->System->Advanced->Startup&Recovery->System failure->[X] Write an event to the system log.

        That logs messages like

        "Application popup: perl.exe - Application Error : The instruction at "0x280b1efe" referenced memory at "0x00000009". The memory could not be "read".


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.