Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Perl exe as a service, stuck on starting

by Garden Dwarf (Beadle)
on Feb 26, 2018 at 16:13 UTC ( [id://1209982]=perlquestion: print w/replies, xml ) Need Help??

Garden Dwarf has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

I'm using Win32::Daemon::Simple amongst with Perl Packer (pp) to generate an exe from a perl script. Then - as an administrator - I start the exe, and install the service. After that, in the task manager -> services, I start the service.

I can check the service activity as it writes into a file. And it seems to execute without problems. What I do not understand is that into the task manager -> services, the service state is "starting" and not "running". Therefore I cannot ask the service to stop, I have to kill the process instead. Which is not very nice.

The script looks like this (well, I removed a lot of lines to go to the essential):
#!/bin/perl use strict; use warnings; use Data::Dumper; use FindBin; use Win32::Daemon; use Win32::Daemon::Simple Service => 'Service_name', Name => 'Service name', Version => '0.3', Info => { display => 'myService', description => 'My service', user => '', pwd => '', interactive => 0, }, Params => { # the default parameters Tick => 0, Talkative => 0, Interval => 1, # minutes LogFile => 'mylogfile.txt'}; ServiceLoop(\&doTheJob); exit(0); sub doTheJob{ ### Here I write some lines into a file }

I'm developing with Strawberry and running the service on Windows Server 2012

I anyone has a clue, I will be grateful! Thank you in advance :)

Replies are listed 'Best First'.
Re: Perl exe as a service, stuck on starting
by dasgar (Priest) on Feb 26, 2018 at 17:52 UTC

    How are you starting the service? I'm wondering of the details in the Comments section of Win32::Daemon::Simple, which describes what happens with various methods of running the scripts using the module, might help explain the issue that you are having.

      I run the exe as administrator, this open a cmd prompt with multiple options:

      Type "continue" and press ENTER to start processing files in commandli +ne mode, type "install" and press ENTER to install the service, type "uninstall" and press ENTER to uninstall the service, type "start" and press ENTER to start the service, type "stop" and press ENTER to stop the service, type "ParameterName=Value" and press ENTER to change a service paramet +er or press ENTER to exit

      I select "install", which leads into a popup window saying that the service installed successfully.

      Then I go into the Windows' Task Manager (right-click on the start menu bar, select Task Manager, display more details, then select the "Services" tab). From there, I can see my service (Status "Stopped"). Right click on the service, select "Start". That's it. Status is changing to "Starting".

Re: Perl exe as a service, stuck on starting
by Discipulus (Canon) on Feb 27, 2018 at 10:40 UTC
    hello Garden Dwarf,

    I'd really like to help you (I abandoned my tries with windows services since service did not start in timely fashion errors..) but I'm unable to reproduce your ~working example.

    I'm trying on Win10 with strawberry 5.26 64bit with all modules up to date: Win32::Daemon::Simple 0.2.6 Win32::Daemon 20131206 Win32::Registry 0.12 PAR::Packer 1.041

    If I try your example (with a simple print to file and sleep function as work) or even if I try the TestSimpleService.pl that comes within the distribution I get no luck make them working..

    First annoyances are in packing it: if I

    pp daemon-simple01.pl -o daemon-simple01.exe

    when I run as administrator I get

    Can't locate utf8_heavy.pl in @INC (@INC contains:...

    I found somewhere pp -u so I issued the packing with -u but I get:

    Global symbol "$HKLM" requires explicit package name (did you forget t +o declare "my $HKLM"?) at Win32/Daemon/Simple.pm line 66.

    This come from the no more used Win32::Registry module...

    So how did you packed the program? Which strawberry version are you using? 32bit?

    The only help I can offer you at the moment is about different way you can start and query a service: you have the gui interface services that is different from that of the task manager and you also have, as commandline tools, the net service command and the sc one. just to be sure all of them return the same results you are seeing now from the task manager.

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      I first replaced the Registry.pm (./perl/site/lib/Win32/ on my installation) from the installed module Win32::Registry by the one found here: http://jenda.krynicky.cz/#Win32::Registry2. This Registry.pm package contains the HKLM definition (amongst with other changes). I had also to change the version as it was expecting the one from the original Win32::Registry (you'll see that error and the expected version if you do not change anything). There should be a more "clean" way to replace this package, but at least what I did is working. This should solve your issue.

      Then I'm using an older version of pp (1.014). This is because I wanted to change the exe icon, and with newer versions you can't.

      Maybe not important for you, but with the installation of libraries I also have an issue with the "ar" command, which generates issues at compilation time (g++ issue message about ".a" files that are not recognized). I compiled the ".a" files with "ar" on another platform (Cygwin).

      I'm using Strawberry Portable (v5.14.4) on Win10.

      I hope that this will help you running your program. If not, just ask ;)

Re: Perl exe as a service, stuck on starting
by Garden Dwarf (Beadle) on Feb 27, 2018 at 08:50 UTC

    I have tried to compile with option "-g" (build an executable that does not have a console window) and now it works correctly. The sequence "Click start" > Starting > Running > "Click stop" > Stopping > Stopped works now.

    The only issue is that without a console window, I cannot "interactively" install the service (as described above). However I should be able to open a CMD prompt and start the exe with "-install" instruction. This should do the trick.

      Well, I reply a little bit to myself... With the "-g" option, it seems that I cannot install the service by running the exe. Even with arguments.

      So if I compile 2 exe, 1 without the "-g" to install the service and another one with the "-g" to run the service, it works. But it is not nice... help is still welcome :)

        I made progress on this one. Option -g with pp, and "sc create" in a DOS terminal to install the service. No further issues so far.

Re: Perl exe as a service, stuck on starting
by Jenda (Abbot) on Feb 28, 2018 at 09:28 UTC

    What gets printed into the log file if you set both Tick and Talkative to 1.

    How long does the doTheJob() subroutine take to complete?

    Does it do the same if you skip the par step and install the service without packing?

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1209982]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 08:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found