Fix kill thread db

This commit is contained in:
cmaffio
2016-04-07 10:52:22 +02:00
parent 9bc76f2e18
commit e6e4b5d15b

View File

@@ -52,14 +52,15 @@ while ( $ref = $sts->fetchrow_hashref ) {
my $port = $$ref{'port'};
my $nome = $$ref{'nome'};
$proc{$nome} = threads->create(\&conntrack, $id, $ip, $port);
print "Attivato processo $nome\n" if ($verbose);
}
while (1) {
sleep 30;
while (($variabile, $puntatore) = each %proc) {
while (my ($variabile, $puntatore) = each %proc) {
if(!$puntatore or !$puntatore->is_running ) {
print "Rilevato termine processo $variabile, riavvio" if ($verbose);
$puntatore->detach();
print "Rilevato termine processo $variabile\n" if ($verbose);
#$puntatore->detach();
if ($variabile eq "database") {
$proc{'database'} = threads->create(\&database);
@@ -75,7 +76,6 @@ while (1) {
}
}
}
}
exit;
@@ -151,18 +151,30 @@ sub conntrack {
sub database {
print "Attivato thread DB\n" if ($verbose);
my $dbmysql = DBI->connect("DBI:mysql:;host=$DBhost", $DBuser, $DBpass) or die ($DBI::errstr);
$sts = $dbmysql->prepare("use $DBname");
$sts->execute ();
$dbmysql = DBConn ();
while (1) {
print "DB in attesa\n" if ($verbose > 1);
$sem2->down();
print "Query arrivata\n" if ($verbose > 1);
if ( not $dbmysql->ping ) {
$dbmysql = DBConn ();
}
my $sts = $dbmysql->prepare($queryDB);
$sts->execute () || die;
$sts->execute ();
$sts->finish;
$sem1->up();
}
}
sub DBConn {
print "Connessione DB\n" if ($verbose > 1);
my $dbmysql = DBI->connect("DBI:mysql:;host=$DBhost", $DBuser, $DBpass, {PrintError => 0, RaiseError => 0, AutoCommit =>1, mysql_auto_reconnect=>1} ) or die ($DBI::errstr);
$sts = $dbmysql->prepare("use $DBname");
$sts->execute ();
return $dbmysql;
}