Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Win32 daemon in POE

by Random_Walk (Prior)
on Mar 11, 2009 at 16:40 UTC ( #749947=note: print w/replies, xml ) Need Help??

in reply to Win32 daemon in POE

Do I understand right that you are running a program based on POE::Wheel::Run::Win32 and this is spawning children that use POE::Component::Daemon::Win32 to become services?

Do you have a limited code example we can look at? Perhaps you could just keep the parent running or start the Deamon some other way. Do you tell the SCM that you have started up OK? Can you run your Deamon directly without calling it from POE::Wheel::Run::Win32 ?


Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re^2: Win32 daemon in POE
by wl2776 (Novice) on Mar 11, 2009 at 17:32 UTC

    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 )
    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__

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://749947]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2017-04-23 08:27 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (430 votes). Check out past polls.