in reply to Win32::Daemon installed service fails to start
punkish, It seemed to work for me. I used sc to do the install. Here is the script I registered along with a transcript of what I did after the __END__:
use Win32::Daemon; # print LOG "hello\n"; BEGIN { open( STDERR, ">>myservicelog.err" ) or die "invisible error"; warn "$0 started ".localtime().$/; } open LOG, ">>mylogfile.txt" or die; # Start the service control loop Win32::Daemon::StartService(); while( SERVICE_STOPPED != ( $State = Win32::Daemon::State() ) ){ if( SERVICE_STARTING == $State ) { # some service startup code # ...... Win32::Daemon::State( SERVICE_RUNNING ); } elsif( SERVICE_PAUSE_PENDING == $State ) { Win32::Daemon::State( SERVICE_PAUSED ); next; } elsif( SERVICE_CONTINUE_PENDING == $State ) { Win32::Daemon::State( SERVICE_RUNNING ); next; } elsif( SERVICE_STOP_PENDING == $State ) { # some service shutdown code # ............ Win32::Daemon::State( SERVICE_STOPPED ); next; } elsif( SERVICE_CONTROL_SHUTDOWN == $State ) { # Request x seconds to shutdown... Win32::Daemon::State( SERVICE_STOP_PENDING, 45 ); # .............. Win32::Daemon::State( SERVICE_STOPPED ); next; } elsif( SERVICE_RUNNING == $State ) { doMyStuff(); print LOG "DONE!\n"; sleep 3; } else { # Un-handled control messages Win32::Daemon::State( SERVICE_RUNNING ); } sleep 5; } Win32::Daemon::StopService(); sub doMyStuff { print LOG "hello\n"; } __END__ c:\>sc create perlservice binPath= "c:\mtapps\perl\580\delta\bin\perl +c:\tmp\ntperlservice.pl" DisplayName= perlservice [SC] CreateService SUCCESS c:\>sc query perlservice SERVICE_NAME: perlservice TYPE : 10 WIN32_OWN_PROCESS STATE : 1 STOPPED (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SH +UTDOWN) WIN32_EXIT_CODE : 1077 (0x435) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 C:\tmp>sc start perlservice SERVICE_NAME: perlservice TYPE : 10 WIN32_OWN_PROCESS STATE : 2 START_PENDING (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SH +UTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x7d0 PID : 5348 FLAGS : C:\tmp>sc query perlservice SERVICE_NAME: perlservice TYPE : 10 WIN32_OWN_PROCESS STATE : 2 START_PENDING (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SH +UTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x7d0 C:\tmp>sc query perlservice SERVICE_NAME: perlservice TYPE : 10 WIN32_OWN_PROCESS STATE : 4 RUNNING (STOPPABLE,PAUSABLE,ACCEPTS_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 C:\tmp>cat c:\winnt\system32\myservicelog.err c:\tmp\ntperlservice.pl started Tue Dec 28 09:03:32 2004 C:\tmp>cat c:\winnt\system32\mylogfile.txt C:\tmp>sc stop perlservice SERVICE_NAME: perlservice TYPE : 10 WIN32_OWN_PROCESS STATE : 3 STOP_PENDING (STOPPABLE,PAUSABLE,ACCEPTS_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 C:\tmp>sc query perlservice SERVICE_NAME: perlservice TYPE : 10 WIN32_OWN_PROCESS STATE : 1 STOPPED (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SH +UTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 C:\tmp>cat c:\winnt\system32\mylogfile.txt hello DONE! hello DONE! hello DONE! hello ....
As I suspected, LOG is being buffered. So it didn't show up until after I stopped the service.
Hope this helps.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Win32::Daemon installed service fails to start
by punkish (Priest) on Dec 29, 2004 at 21:00 UTC | |
by osunderdog (Deacon) on Dec 29, 2004 at 21:31 UTC |