Solved

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

Posted on 2006-10-29
3
834 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

749 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