use strict; use Daemon::Simple; use Log; use DBIx::DWIW; use Mail::Sender; use Data::Dumper; if ($ARGV[0] eq 'start') { start(); } elsif ($ARGV[0] eq 'stop') { stop(); } #### S T O P PROGRAM #### sub stop { $Log->log_it ("info", "$prog_name exiting..."); ## Initialize Daemon ## my $homedir = '/'; my $pidfile = "/var/run/$prog_name.$service_name.pid"; my $command = 'stop'; Daemon::Simple::init($command,$homedir,$pidfile); } #### S T A R T PROGRAM #### sub start { $Log->log_it ("info", "$prog_name started."); $DB = DBIx::DWIW->Connect (@dbpref) || $Log->error("No Database-Connection!!"); ## Initialize Daemon ## my $homedir = '/'; my $pidfile = "/var/run/$prog_name.$service_name.pid"; my $command = 'start'; # Daemon::Simple::init($command,$homedir,$pidfile); loop(); } sub loop { ## Daemon Loop ## while (1) { $Log->debug('loop started...'); @tasks_processed = (); my @entries = get_new_entries; # $Log->debug('entries: '.Dumper (@entries)); # prepare SQL my $sthErrMsg = $DB->Prepare ("UPDATE tasks SET task_errormsg = ?, task_done = '1' WHERE task_id = ?"); for (@entries) { # doing some stuff with @entries # .... # update DB $sthErrMsg->Execute($status, $task_id) or $Log->error("DB Error: $@"); # here it hangs forever when Daemonized # some other stuff } } # end while } # end loop ()