Solved

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

Posted on 2006-10-29
3
849 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

624 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