Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Win32::Daemon . Service installs but only runs for a few seconds

Posted on 2006-10-29
3
Medium Priority
?
863 Views
Last Modified: 2012-06-27
I'm using the below to turn a perl script into a windows service.  It seems to work correctly, as it shows up in the services.msc GUI and when I start the service, it starts and does it's job correctly for about 30 seconds, then I get an error:
  "The service is not responding to the control function." from the CLI

or from the GUI

  "Could not start the PerlSrv on the local computer.  Error 1053:   the serverice did not respond to the start or control request in  a timely fasion"

and the service stops running

Any sample code to spawn a simple service would be much appreciated!

### DaemonMaker.pl ###
    use Win32::Daemon;

    $script = 'c:\MyScript.pl';

    %Hash = (
        machine     => '',
        name        => 'PerlSrv',
        display     => 'PerlSrv',
        path        => 'c:\perl\bin\perl.exe',
        user        => '',
        pwd         => '',
        description => 'description of service',
        parameters  => "$script",
    );
    if ( Win32::Daemon::CreateService( \%Hash ) ) {
        print "Successfully added.\n";
    }
    else {
        print "Failed to add service: "
          . Win32::FormatMessage( Win32::Daemon::GetLastError() ) . "\n";
    }

### MyScript.pl  ###
      open(LOG,'>>c:\some.log');
      while (1) {
         sleep 1;
         print LOG "logging...\n";
    }
0
Comment
Question by:Marketing_Insists
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 2000 total points
ID: 17829993
You've only got code in there to install the service.   There's no code to take care of handling the requests from the service control manager (start, stop, pause, etc).   Take a look at http://www.roth.net/perl/Daemon/ for details on how to use the module-- look at examples 2 and 5 in particular.  A working example script is at http://www.roth.net/perl/scripts/scripts.asp?DirMon.pl

You might be interested in Win32::Daemon::Simple which encapsulates a lot of it for you.  You register a service loop routine and call DoEvents() within it to handle requests from the SCM.
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 17829995
0
 

Author Comment

by:Marketing_Insists
ID: 17835512
Ah, Thanks, I was able to mangle the example code into something that worked for my purposes (dirmon is pretty intense)

One more thing, Win32::Daemon::Simple you mentioned seems broken or maybe I need modules the make file isn't telling me about - I think I was able to get the sample code to work, but kept getting an error about "$HKLM" from the module.  

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question