in reply to Perl script as windows service
I do not think you need to remove the DOS box. This is not the issue. You use your script to install the service, I understand. You start the service within the win32 SERVICES dialog. I think.
Problem is, that your script actually has neither a start hook nor a run hook!
Initialize the daemon with something like
Win32::Daemon::RegisterCallbacks( { start => \&startService, stop => \&stopService, pause => \&pauseService, continue => \&continueService, running => \&runService, } );
Next, define some callbacks.
sub startService { # start the win32 service daemon # ------------------------------ my ($event, $context) = @_; $context -> { last_state } = SERVICE_RUNNING; Win32::Daemon::State( SERVICE_START_PENDING, 30000 ); # do what need to be done # exit Win32::Daemon::State( SERVICE_RUNNING ); } # ==================================================================== +========== sub stopService { # stop the win32 service daemon # ----------------------------- my ($event, $context) = @_; $context -> { last_state } = SERVICE_STOPPED; Win32::Daemon::State( SERVICE_STOP_PENDING, 30000 ); # do what needs to be done # exit Win32::Daemon::State( SERVICE_STOPPED ); Win32::Daemon::StopService(); } # ==================================================================== +========== sub pauseService { # let the win32 service daemon make a pause # ----------------------------------------- my ($event, $context) = @_; $context -> { last_state } = SERVICE_PAUSED; # do what needs to be done # exit Win32::Daemon::State( SERVICE_PAUSED ); } # ==================================================================== +========== sub continueService { # let the win32 service daemon exit a pause # ----------------------------------------- my ($event, $context) = @_; $context -> { last_state } = SERVICE_RUNNING; # do what needs to be done # exit Win32::Daemon::State( SERVICE_RUNNING ); } # ==================================================================== +========== sub runService { # this is the callback of by the win32 service daemon # --------------------------------------------------- my ($event, $context) = @_; if ( Win32::Daemon::State() == SERVICE_RUNNING ) { # count the number of calls (I do not know why) $context -> { count }++; } }
Regarding your error message I add the following comment. Your service did not respond to the start method, because there is none. If there is a start method, you need to be careful to inform the win32 service manager, how long your startup will take. See this Win32::Daemon::State( SERVICE_STOP_PENDING, 30000 ); statement.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl script as windows service
by holli (Abbot) on Mar 02, 2005 at 08:54 UTC | |
by m-rau (Scribe) on Mar 02, 2005 at 09:11 UTC | |
by rockets12345 (Novice) on Mar 09, 2005 at 20:30 UTC | |
by m-rau (Scribe) on Mar 10, 2005 at 12:21 UTC | |
by polettix (Vicar) on Oct 11, 2005 at 17:07 UTC | |
by rockets12345 (Novice) on Mar 09, 2005 at 07:58 UTC | |
by m-rau (Scribe) on Mar 09, 2005 at 13:17 UTC |