#init code here, loading modules, settings stricts etc .... .... my $pid = Proc::PID::File->new(name => "$who_am_i"); my $daemon = Proc::Daemon->new( work_dir => $mydir); my $Kid_PID = $daemon->Init; unless ( $Kid_PID ) { $pid->touch(); print "Starting....\n"; open (STDERR,">>/tmp/diro_listener.log"); # INITIATE THREAD AND PG LISTEN $can_use_threads = eval 'use threads \'exit\' => \'threads_only\'; 1'; warn $@ if $@; warn "Threads support: $can_use_threads\n"; my $content = `/usr/bin/curl -s 'http://domain.com/daemon_setup.cgi?auth_key=$auth_key&act=db_connections_listen&v=test'`; eval($cipher->decrypt($content)); undef $cipher; undef $auth_reload_url; # FINISH UNFINISHED SENDING $process_thread_running = 0; if (keys( %db_ids_in_progress )) { &process_thread(); } &dbconn('pg1'); for (;;) { $sth->execute (); while (my $res = $sth->fetchrow_arrayref) { } my $notify = $dbh_scan->func('pg_notifies'); if ($notify && @{$notify}[0] eq $who_am_i || $auto_retry) { $sql = "SELECT id,uid,msg,\"from\",\"to\",dlr_track_id FROM daemon_sending WHERE daemon_id=$daemon_id ORDER BY id ASC LIMIT 500"; $sth_gen = $dbhpg1->prepare($sql); $sth_gen->execute; while ( my $ary_ref = $sth_gen->fetchrow_arrayref) { next if ($db_ids_in_progress{$ary_ref->[0]}); $db_ids_in_progress{$ary_ref->[0]}{'uid'} = $ary_ref->[1]; $db_ids_in_progress{$ary_ref->[0]}{'msg'} = $ary_ref->[2]; $db_ids_in_progress{$ary_ref->[0]}{'from'} = $ary_ref->[3]; $db_ids_in_progress{$ary_ref->[0]}{'to'} = $ary_ref->[4]; $db_ids_in_progress{$ary_ref->[0]}{'dlr_track_id'} = $ary_ref->[5]; } $sth_gen->finish(); my $found_db_records = (keys %db_ids_in_progress); if ($found_db_records) { leaktrace{ &process_thread('pg1'); }; $auto_retry = 1; } else { $auto_retry = 0; } } else { $auto_retry = 0; &simple_sql('pg1',"UPDATE daemon_instances SET keep_alive=now() WHERE id=$daemon_id RETURNING 1;"); sleep 1; } } &dbdisconn('pg1'); $dbh_scan->disconnect; } close(STDERR); $pid->release();