|
|
|
|
|
|
| Author |
Message |
harvar007@yahoo.com *nix forums beginner
Joined: 13 Jul 2006
Posts: 3
|
Posted: Thu Jul 13, 2006 7:01 pm Post subject:
Windows services in PERL
|
|
|
Hi
I am trying to create a win32 service using the module win32:deamon. I
wrote a simple code and tried to get that running before I went to the
actual one. I am actually able to successfully create the service and
see the same in the Management Console, but when I try to right click
and say Start I get "error :1053 the service did not respond or start
to the control request in a timely fashion"
Can any one please, let me know what might be wrong in this scenario?
Here is my sample code which I was trying to get installed!
use Win32::Daemon;
Win32::Daemon::StartService();
while( SERVICE_START_PENDING != Win32::Daemon::State() )
{
sleep( 1 );
}
Win32::Daemon::State( SERVICE_RUNNING );
unlink( glob( "c:\\temp\\*.tmp" ) );
Win32::Daemon::StopService();
Thanks
Harini |
|
| Back to top |
|
 |
harryfmudd [AT] comcast [ *nix forums addict
Joined: 15 Oct 2005
Posts: 82
|
Posted: Fri Jul 14, 2006 3:48 pm Post subject:
Re: Windows services in PERL
|
|
|
harvar007@yahoo.com wrote:
| Quote: | Hi
I am trying to create a win32 service using the module win32:deamon. I
wrote a simple code and tried to get that running before I went to the
actual one. I am actually able to successfully create the service and
see the same in the Management Console, but when I try to right click
and say Start I get "error :1053 the service did not respond or start
to the control request in a timely fashion"
Can any one please, let me know what might be wrong in this scenario?
Here is my sample code which I was trying to get installed!
use Win32::Daemon;
Win32::Daemon::StartService();
while( SERVICE_START_PENDING != Win32::Daemon::State() )
{
sleep( 1 );
}
Win32::Daemon::State( SERVICE_RUNNING );
unlink( glob( "c:\\temp\\*.tmp" ) );
Win32::Daemon::StopService();
Thanks
Harini
|
It has been a while, but ...
The first suggestion I have is to check the success of
Win32::Daemon::StartService (), with something like
Win32::Daemon::StartService () or do {
my $err = "Failed to start service\n" .
Win32::FormatMessage (
Win32::Daemon::GetLastError ());
# Log the error somewhere, then
die $err;
};
The second is that you probably want to handle the SERVICE_NOT_READY
state by going to state SERVICE_START_PENDING. In fact, the more I think
about it, the more I think this may be your problem. Maybe your event
loop should be something like
while (1)
{
my $state = Win32::Daemon::State ();
if ($state == SERVICE_NOT_READY)
{
Win32::Daemon::State (SERVICE_START_PENDING);
} elsif ($state == SERVICE_START_PENDING)
{
last;
}
sleep (1); # or Win32::Sleep (1000);
}
Less likely, but possible:
* You might need to set the state to SERVICE_RUNNING in response to the
SERVICE_CONTINUE_PENDING state, in addition to the SERVICE_START_PENDING
state.
* Jenda's code (see below) sets the state to SERVICE_RUNNING in response
to state 0x0080. You might want to try the same, in addition to the others.
* You _might_ also need to respond to the OS messages you get from
calling Win32::Daemon::QueryLastMessage -- at least to
SERVICE_CONTROL_INTERROGATE (respond with the state you believe the
service to be in) in your event loop. If your event loop ran
indefinitely you might want to respond to SERVICE_CONTROL_SHUTDOWN
(system shutdown) by setting your service to SERVICE_STOP_PENDING and
cleaning up.
Better than all this, though, is a trick I picked up from Jenda
Krynicky's Win32::Daemon::Simple (see http://jenda.krynicky.cz/). I did
not use this module itself because it required replacing ActiveState's
Win32::Registry with an incompatible version from Jenda, and I didn't
want to do that because it made an otherwise-straightforward maintenance
situation complicated. Of course, the trade-off was that an otherwise
simple daemon became complicated.
The trick allows you to run your service interactively (i.e. not as a
service, but so that you actually see the output), and the essence of
the trick is the following:
# After you have successfully called Win32::Daemon::StartService:
my $save_state = SERVICE_NOT_READY; # in case interactive.
# Wherever you query the service state, code
service_state ();
# Wherever you set the service state, code
service_state ($whatever_the_new_state_is);
# As a special case of the above, if you are responding to
# SERVICE_CONTROL_INTERROGATE (see above), code
service_state ($save_state);
###############################
#
# With your other internal subroutines:
# Return true if running from the command line, false otherwise.
BEGIN {
my $cmdlin = Win32::Console::_GetConsoleTitle () ? 1 : 0;
sub CMDLINE {$cmdlin}
}
# Wrap Win32::Daemon::State so we can run interactively.
sub service_state {
return CMDLINE () ? $save_state : Win32::Daemon::State ()
unless @_;
push @_, 25000 # Milliseconds
if $_[0] == SERVICE_STOP_PENDING && @_ == 1;
Win32::Daemon::State (@_) unless CMDLINE ();
$save_state = shift;
return $save_state;
}
One last thought: You might think about logging to a file, so you can
tell what your service is doing.
Tom Wyant |
|
| Back to top |
|
 |
harvar007@yahoo.com *nix forums beginner
Joined: 13 Jul 2006
Posts: 3
|
Posted: Fri Jul 14, 2006 4:15 pm Post subject:
Re: Windows services in PERL
|
|
|
Hi Tom,
Thanks a ton for the eloborate suggestions! Will try them and let you
know my outcome...
Harini
harryfmudd [AT] comcast [DOT] net wrote:
| Quote: | harvar007@yahoo.com wrote:
Hi
I am trying to create a win32 service using the module win32:deamon. I
wrote a simple code and tried to get that running before I went to the
actual one. I am actually able to successfully create the service and
see the same in the Management Console, but when I try to right click
and say Start I get "error :1053 the service did not respond or start
to the control request in a timely fashion"
Can any one please, let me know what might be wrong in this scenario?
Here is my sample code which I was trying to get installed!
use Win32::Daemon;
Win32::Daemon::StartService();
while( SERVICE_START_PENDING != Win32::Daemon::State() )
{
sleep( 1 );
}
Win32::Daemon::State( SERVICE_RUNNING );
unlink( glob( "c:\\temp\\*.tmp" ) );
Win32::Daemon::StopService();
Thanks
Harini
It has been a while, but ...
The first suggestion I have is to check the success of
Win32::Daemon::StartService (), with something like
Win32::Daemon::StartService () or do {
my $err = "Failed to start service\n" .
Win32::FormatMessage (
Win32::Daemon::GetLastError ());
# Log the error somewhere, then
die $err;
};
The second is that you probably want to handle the SERVICE_NOT_READY
state by going to state SERVICE_START_PENDING. In fact, the more I think
about it, the more I think this may be your problem. Maybe your event
loop should be something like
while (1)
{
my $state = Win32::Daemon::State ();
if ($state == SERVICE_NOT_READY)
{
Win32::Daemon::State (SERVICE_START_PENDING);
} elsif ($state == SERVICE_START_PENDING)
{
last;
}
sleep (1); # or Win32::Sleep (1000);
}
Less likely, but possible:
* You might need to set the state to SERVICE_RUNNING in response to the
SERVICE_CONTINUE_PENDING state, in addition to the SERVICE_START_PENDING
state.
* Jenda's code (see below) sets the state to SERVICE_RUNNING in response
to state 0x0080. You might want to try the same, in addition to the others.
* You _might_ also need to respond to the OS messages you get from
calling Win32::Daemon::QueryLastMessage -- at least to
SERVICE_CONTROL_INTERROGATE (respond with the state you believe the
service to be in) in your event loop. If your event loop ran
indefinitely you might want to respond to SERVICE_CONTROL_SHUTDOWN
(system shutdown) by setting your service to SERVICE_STOP_PENDING and
cleaning up.
Better than all this, though, is a trick I picked up from Jenda
Krynicky's Win32::Daemon::Simple (see http://jenda.krynicky.cz/). I did
not use this module itself because it required replacing ActiveState's
Win32::Registry with an incompatible version from Jenda, and I didn't
want to do that because it made an otherwise-straightforward maintenance
situation complicated. Of course, the trade-off was that an otherwise
simple daemon became complicated.
The trick allows you to run your service interactively (i.e. not as a
service, but so that you actually see the output), and the essence of
the trick is the following:
# After you have successfully called Win32::Daemon::StartService:
my $save_state = SERVICE_NOT_READY; # in case interactive.
# Wherever you query the service state, code
service_state ();
# Wherever you set the service state, code
service_state ($whatever_the_new_state_is);
# As a special case of the above, if you are responding to
# SERVICE_CONTROL_INTERROGATE (see above), code
service_state ($save_state);
###############################
#
# With your other internal subroutines:
# Return true if running from the command line, false otherwise.
BEGIN {
my $cmdlin = Win32::Console::_GetConsoleTitle () ? 1 : 0;
sub CMDLINE {$cmdlin}
}
# Wrap Win32::Daemon::State so we can run interactively.
sub service_state {
return CMDLINE () ? $save_state : Win32::Daemon::State ()
unless @_;
push @_, 25000 # Milliseconds
if $_[0] == SERVICE_STOP_PENDING && @_ == 1;
Win32::Daemon::State (@_) unless CMDLINE ();
$save_state = shift;
return $save_state;
}
One last thought: You might think about logging to a file, so you can
tell what your service is doing.
Tom Wyant |
|
|
| Back to top |
|
 |
harini.gopi@gmail.com *nix forums beginner
Joined: 27 Jun 2006
Posts: 2
|
Posted: Fri Jul 14, 2006 7:30 pm Post subject:
Re: Windows services in PERL
|
|
|
that didnt work either!
so i downloaded an utility called "srvany.exe" which apparently seems
to have fixed the problem! am not sure though why it couldnt start in
the normal manner...
Harini
harryfmudd [AT] comcast [DOT] net wrote:
| Quote: | harvar007@yahoo.com wrote:
Hi
I am trying to create a win32 service using the module win32:deamon. I
wrote a simple code and tried to get that running before I went to the
actual one. I am actually able to successfully create the service and
see the same in the Management Console, but when I try to right click
and say Start I get "error :1053 the service did not respond or start
to the control request in a timely fashion"
Can any one please, let me know what might be wrong in this scenario?
Here is my sample code which I was trying to get installed!
use Win32::Daemon;
Win32::Daemon::StartService();
while( SERVICE_START_PENDING != Win32::Daemon::State() )
{
sleep( 1 );
}
Win32::Daemon::State( SERVICE_RUNNING );
unlink( glob( "c:\\temp\\*.tmp" ) );
Win32::Daemon::StopService();
Thanks
Harini
It has been a while, but ...
The first suggestion I have is to check the success of
Win32::Daemon::StartService (), with something like
Win32::Daemon::StartService () or do {
my $err = "Failed to start service\n" .
Win32::FormatMessage (
Win32::Daemon::GetLastError ());
# Log the error somewhere, then
die $err;
};
The second is that you probably want to handle the SERVICE_NOT_READY
state by going to state SERVICE_START_PENDING. In fact, the more I think
about it, the more I think this may be your problem. Maybe your event
loop should be something like
while (1)
{
my $state = Win32::Daemon::State ();
if ($state == SERVICE_NOT_READY)
{
Win32::Daemon::State (SERVICE_START_PENDING);
} elsif ($state == SERVICE_START_PENDING)
{
last;
}
sleep (1); # or Win32::Sleep (1000);
}
Less likely, but possible:
* You might need to set the state to SERVICE_RUNNING in response to the
SERVICE_CONTINUE_PENDING state, in addition to the SERVICE_START_PENDING
state.
* Jenda's code (see below) sets the state to SERVICE_RUNNING in response
to state 0x0080. You might want to try the same, in addition to the others.
* You _might_ also need to respond to the OS messages you get from
calling Win32::Daemon::QueryLastMessage -- at least to
SERVICE_CONTROL_INTERROGATE (respond with the state you believe the
service to be in) in your event loop. If your event loop ran
indefinitely you might want to respond to SERVICE_CONTROL_SHUTDOWN
(system shutdown) by setting your service to SERVICE_STOP_PENDING and
cleaning up.
Better than all this, though, is a trick I picked up from Jenda
Krynicky's Win32::Daemon::Simple (see http://jenda.krynicky.cz/). I did
not use this module itself because it required replacing ActiveState's
Win32::Registry with an incompatible version from Jenda, and I didn't
want to do that because it made an otherwise-straightforward maintenance
situation complicated. Of course, the trade-off was that an otherwise
simple daemon became complicated.
The trick allows you to run your service interactively (i.e. not as a
service, but so that you actually see the output), and the essence of
the trick is the following:
# After you have successfully called Win32::Daemon::StartService:
my $save_state = SERVICE_NOT_READY; # in case interactive.
# Wherever you query the service state, code
service_state ();
# Wherever you set the service state, code
service_state ($whatever_the_new_state_is);
# As a special case of the above, if you are responding to
# SERVICE_CONTROL_INTERROGATE (see above), code
service_state ($save_state);
###############################
#
# With your other internal subroutines:
# Return true if running from the command line, false otherwise.
BEGIN {
my $cmdlin = Win32::Console::_GetConsoleTitle () ? 1 : 0;
sub CMDLINE {$cmdlin}
}
# Wrap Win32::Daemon::State so we can run interactively.
sub service_state {
return CMDLINE () ? $save_state : Win32::Daemon::State ()
unless @_;
push @_, 25000 # Milliseconds
if $_[0] == SERVICE_STOP_PENDING && @_ == 1;
Win32::Daemon::State (@_) unless CMDLINE ();
$save_state = shift;
return $save_state;
}
One last thought: You might think about logging to a file, so you can
tell what your service is doing.
Tom Wyant |
|
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Sun Nov 23, 2008 11:50 am | All times are GMT
|
|
Secured Loans | Free Advertising | Mortgage Calculator | Loans | Mortgage Calculator
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|