in reply to Win32::Daemon problem

#...snip elsif ( SERVICE_RUNNING == $State ) { if ($DEBUG) { verbose("Service Running"); } if ( $DEBUG ) { verbose ("Waiting 100 seconds to continue\n"); } sleep(100); } #...snip
I think you want to reduce that sleep 100 to something smaller, like sleep 2. If you need a longer sleep, then split it up and do a Win32::Daemon::State() call between each one. The Win32 service control manager polls all active services every now and then and it needs to receive a response within 15 seconds or so, otherwise it says that the service isn't responding. IIRC, Dave mentions this in the docs.

As for whether this fixes your problem, I can't say at the moment - I don't have a Win32 machine to test it on right now.

Hope this helps.

__________________________________________________________
Simon Flack ($code or die)
$,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
=~y'_"' ';eval"die";print $_,lc substr$@,0,3;

Replies are listed 'Best First'.
Re: Re: Win32::Daemon problem
by cruelty (Novice) on Sep 20, 2001 at 21:56 UTC

    You're right, thanks for the spot but that's not what was causing the problem.

    After some research, I found that the real problem was that the perl interpreter wasn't able to find the package I was trying to include because the service gets started from a different directory than the one where I placed my script and module.

    This problem is now solved by adding the directory to the @INC list :

    use lib "c:/mypath";

    Regards,

    <ruelty

      Ahh. I've run into similar problems before. Win32 services are more difficult to debug because you can't see what's going on. What I've done in the past is log errors to a text file. This is fine for development, but in production you probably want to use the Event Log, with Win32::EventLog or Win32::EventLog::Message - I don't have a link, but I think it's another one of Dave Roth's.

      I find something along these lines useful:
      BEGIN { $SIG{__WARN__} = $SIG{__DIE__} = sub { open ERRORLOG, ">>/myerror.log" or die "error opening logfile"; print ERRORLOG, scalar localtime, " - $0\n", @_, "\n\n"; close ERRORLOG; } }
      I think this would have caught your problem and written it to a log file.

      John M. Dlugosz pointed out recently that you can also use Win32::MessageBox from within a Service. So you could replace that logfile with a more immediate and visual prompt.

      Simon Flack ($code or die)
      $,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
      =~y'_"' ';eval"die";print $_,lc substr$@,0,3;