I want to create and install a service which should run in background until it should not pause or stop from services.
So I created the following test script :
use Win32::Daemon;
my $ServicePath = 'C:\Strawberry\perl\bin\perl.exe';
my $ServiceParams = 'C:\ila\bin\ilad.pl';
my %service_info = (
name => 'ilad',
display => 'intelligent Lightweight Agent (ilad)',
path => $ServicePath,
description => 'ilad',
parameters => $ServiceParams,
service_type => SERVICE_WIN32_OWN_PROCESS,
start_type => SERVICE_AUTO_START);
## create ilad service ##
if(Win32::Daemon::CreateService( \%service_info))
{
print "successfully added \n";
}
else
{
print "failed to add service: " . Win32::FormatMessage( Win32::Daemon::GetLastError());
}
# Tell the OS to start processing the service...
Win32::Daemon::StartService(\%service_info))
print "Waiting...\n";
# Wait until the service manager is ready for us to continue...
print "SERVICE_NOT_READY " . SERVICE_NOT_READY . "\n";
print "SERVICE_STOPPED " . SERVICE_STOPPED . "\n";
print "SERVICE_RUNNING " . SERVICE_RUNNING . "\n";
print "SERVICE_PAUSED " . SERVICE_PAUSED . "\n";
print "SERVICE_START_PENDING " . SERVICE_START_PENDING . "\n";
print "SERVICE_STOP_PENDING " . SERVICE_STOP_PENDING . "\n";
print "SERVICE_CONTINUE_PENDING " . SERVICE_CONTINUE_PENDING . "\n";
print "SERVICE_PAUSE_PENDING " . SERVICE_PAUSE_PENDING . "\n";
while( SERVICE_START_PENDING != Win32::Daemon::State() )
{
sleep( 1 );
print Win32::Daemon::State() . "\n";
}
print "Running...\n";
# Now let the service manager know that we are running...
Win32::Daemon::State( SERVICE_RUNNING );
# Okay, go ahead and process stuff...
unlink( glob( "c:\\temp\\*.tmp" ) );
# Tell the OS that the service is terminating...
Win32::Daemon::StopService();
and I have this:
successfully added
Waiting...
SERVICE_NOT_READY 0
SERVICE_STOPPED 1
SERVICE_RUNNING 4
SERVICE_PAUSED 7
SERVICE_START_PENDING 2
SERVICE_STOP_PENDING 3
SERVICE_CONTINUE_PENDING 5
SERVICE_PAUSE_PENDING 6
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
Terminating on signal SIGINT(2)
So it never reaches the SERVICE_RUNNING state and getting integer value and not getting current status of service.
I am using Strawberry perl. So anyone is having any idea?