Opposite.
I am running a program, based on POE::Component::Daemon::Win32,it is a service. It is spawning children with POE::Wheel::Run::Win32.
Yes, I tell SCM that I have started OK.
And yes, everything works fine, when started from the command line ( c:> perl service.pl )
Moreover, the spawned child runs OK and returns. And after it returns, the system calls my STOP_PENDING callback. I see that message in the log.
I also tried using POE::Wheel::Run (without Win32) - same thing.
Here is the exclications from my code. I will try not to include anything that is not needed.
use Win32;
use Win32::SqlServer;
use Win32::Daemon;
use POE::Component::JobQueue;
use POE::Component::Log4perl;
use POE::Component::Daemon::Win32;
use POE qw( Wheel::Run::Win32 Filter::Line);
sub _start {
my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
chdir $workdir;
POE::Component::Log4perl->spawn(
Alias => 'logger',
Category => 'default',
ConfigFile => $config
);
POE::Component::Daemon::Win32->spawn (
Callback => {
not_ready => \&service_default_callback,
start_pending => \&service_start_pending,
running => \&service_running,
pause_pending => \&service_default_callback,
paused => \&service_default_callback,
continue_pending=> \&service_default_callback,
stop_pending => \&service_stop_pending,
stoppped => \&service_stopped,
shutdown => \&service_shutdown
}
);
POE::Component::JobQueue->spawn
( Alias => 'queue',
WorkerLimit => $max_jobs,
Worker => \&make_a_worker,
Active => { PollInterval => $poll_interval }
);
}
sub _stop {
POE::Kernel->call('logger'=>info=>"service stopped");
}
sub service_stop_pending {
POE::Kernel->post('logger'=>debug=>"call to stop_pending");
POE::Kernel->yield('next_state');
}
sub service_running{
POE::Kernel->yield('next_state');
}
#### other callbacks are similar, all yield('next_state')
sub make_a_worker {
my $meta_postback = shift;
my $file_name = shift @file_queue;
POE::Session->create(
inline_states => {
_start => \&worker_start,
_stop => sub { },
worker_child_stdout => \&worker_child_stdout,
worker_closed_ffmpeg=> \&worker_closed_ffmpeg,
worker_closed_asr => \&worker_closed_asr,
sig_child => \&sig_child
},
args => [ $postback, $file_name ]
);
}
sub worker_start
{
my ($kernel, $session, $heap, @args ) = @_[KERNEL, SESSION, HEAP,
+ARG0 .. $#_];
$heap->{postback} = $args[0];
$heap->{cmdline} = POE::Wheel::Run::Win32->new(
Program => $ffmpeg,
ProgramArgs => \@ffmpeg_args,
StdoutEvent => "worker_child_stdout",
StderrEvent => "worker_child_stdout",
CloseEvent => "worker_closed_ffmpeg",
StdioFilter => POE::Filter::Line->new(), # Child speaks in
+ lines.
StderrFilter => POE::Filter::Line->new(), # Child speaks in
+ lines.
);
$kernel->sig_child($heap->{cmdline}->PID, "sig_child");
POE::Kernel->post('logger'=>info=>"session ".$session->ID." start
+ffmpeg ".join(' ',@ffmpeg_args));
}
sub worker_child_stdout ### processes the output of the ffmpeg and pu
+ts the lines to the log, I can see - ffmpeg is running.
sub sig_child
{
my ( $heap, $sig, $pid, $exit_val ) = @_[ HEAP, ARG0, ARG1, ARG2 ]
+;
my $d = delete $heap->{cmdline} if $exit_val;
POE::Kernel->post('logger'=>debug=>"session ".$heap->{SessionID}."
+ sig_child: sig=$sig, pid=$pid, exit_val=$exit_val");
print "sig_child: sig=$sig, pid=$pid, exit_val=$exit_val\n";
return 0;
}
my @handlers = qw(
_start _stop
);
POE::Session->create( package_states => [ main => \@handlers ] );
POE::Kernel->run();
POE::Kernel->call( 'queue' => 'stop' );
exit 0;
__END__
|