Fix kill thread db
This commit is contained in:
@@ -52,14 +52,15 @@ while ( $ref = $sts->fetchrow_hashref ) {
|
|||||||
my $port = $$ref{'port'};
|
my $port = $$ref{'port'};
|
||||||
my $nome = $$ref{'nome'};
|
my $nome = $$ref{'nome'};
|
||||||
$proc{$nome} = threads->create(\&conntrack, $id, $ip, $port);
|
$proc{$nome} = threads->create(\&conntrack, $id, $ip, $port);
|
||||||
|
print "Attivato processo $nome\n" if ($verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
sleep 30;
|
sleep 30;
|
||||||
while (($variabile, $puntatore) = each %proc) {
|
while (my ($variabile, $puntatore) = each %proc) {
|
||||||
if(!$puntatore or !$puntatore->is_running ) {
|
if(!$puntatore or !$puntatore->is_running ) {
|
||||||
print "Rilevato termine processo $variabile, riavvio" if ($verbose);
|
print "Rilevato termine processo $variabile\n" if ($verbose);
|
||||||
$puntatore->detach();
|
#$puntatore->detach();
|
||||||
|
|
||||||
if ($variabile eq "database") {
|
if ($variabile eq "database") {
|
||||||
$proc{'database'} = threads->create(\&database);
|
$proc{'database'} = threads->create(\&database);
|
||||||
@@ -75,7 +76,6 @@ while (1) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
@@ -151,18 +151,30 @@ sub conntrack {
|
|||||||
sub database {
|
sub database {
|
||||||
print "Attivato thread DB\n" if ($verbose);
|
print "Attivato thread DB\n" if ($verbose);
|
||||||
|
|
||||||
my $dbmysql = DBI->connect("DBI:mysql:;host=$DBhost", $DBuser, $DBpass) or die ($DBI::errstr);
|
$dbmysql = DBConn ();
|
||||||
$sts = $dbmysql->prepare("use $DBname");
|
|
||||||
$sts->execute ();
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
print "DB in attesa\n" if ($verbose > 1);
|
print "DB in attesa\n" if ($verbose > 1);
|
||||||
$sem2->down();
|
$sem2->down();
|
||||||
print "Query arrivata\n" if ($verbose > 1);
|
print "Query arrivata\n" if ($verbose > 1);
|
||||||
|
|
||||||
|
if ( not $dbmysql->ping ) {
|
||||||
|
$dbmysql = DBConn ();
|
||||||
|
}
|
||||||
|
|
||||||
my $sts = $dbmysql->prepare($queryDB);
|
my $sts = $dbmysql->prepare($queryDB);
|
||||||
$sts->execute () || die;
|
$sts->execute ();
|
||||||
$sts->finish;
|
$sts->finish;
|
||||||
$sem1->up();
|
$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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user