Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Syslog text file into database or into .CSV 19 91
perl rename 2 137
perl script 4 94
perl search and replace 6 161
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now