MT#19407 warning and use with default dbhost=127.0.0.1, dbport=3306 if no defaults/ngcp-db file

Change-Id: Ie4b402c133eb10e7468335a9658dc19c26f0382c
changes/37/7237/1
Kirill Solomko 10 years ago
parent 3c881f9b54
commit 0eaa1a8ae7

@ -15,6 +15,8 @@ Readonly my $GRANTS_SCHEMA => '/etc/mysql/grants.yml';
Readonly my $DEFAULT_MYSQL_USER => "sipwise";
Readonly my $MYSQL_CREDENTIALS => "/etc/mysql/sipwise.cnf";
Readonly my $DB_CFG => "/etc/default/ngcp-db";
Readonly my $DEFAULT_DBHOST => "127.0.0.1";
Readonly my $DEFAULT_DBPORT => "3306";
my $grants = {};
my $dbh;
@ -365,10 +367,16 @@ sub main {
$grants = $yml->[0];
}
my $db_cfg = Config::Tiny->read($DB_CFG)
or die "Cannot open $DB_CFG: $ERRNO";
my ($dbhost, $dbport);
if (my $db_cfg = Config::Tiny->read($DB_CFG)) {
($dbhost, $dbport) = @{$db_cfg->{_}}{qw(LOCAL_DBHOST LOCAL_DBPORT)};
} else {
log_warn(sprintf "Cannot open %s: %s, using host=%s port=%s",
$DB_CFG, $ERRNO, $DEFAULT_DBHOST, $DEFAULT_DBPORT);
($dbhost, $dbport) = ($DEFAULT_DBHOST, $DEFAULT_DBPORT);
}
connect_db(@{$db_cfg->{_}}{qw(LOCAL_DBHOST LOCAL_DBPORT)});
connect_db($dbhost, $dbport);
$dbh->begin_work or die "Cannot start transaction: ".$DBI::errstr;

Loading…
Cancel
Save