Solved

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

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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 …
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

803 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