You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ne...@apache.org on 2017/03/08 23:15:47 UTC
[3/7] incubator-trafficcontrol git commit: Check connection to
database
Check connection to database
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/6316bb33
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/6316bb33
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/6316bb33
Branch: refs/heads/master
Commit: 6316bb33586b7b5e240bfc86ee307c076aec5023
Parents: 9729d23
Author: PeterRyder <pe...@gmail.com>
Authored: Mon Feb 6 17:06:13 2017 -0500
Committer: Dave Neuman <ne...@apache.org>
Committed: Wed Mar 8 16:15:20 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/6316bb33/traffic_ops/install/bin/postinstall
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall b/traffic_ops/install/bin/postinstall
index 0c1d51b..ecffe08 100755
--- a/traffic_ops/install/bin/postinstall
+++ b/traffic_ops/install/bin/postinstall
@@ -22,6 +22,7 @@ use strict;
use warnings;
use Safe;
+use DBI;
use POSIX;
use File::Basename qw{dirname};
use File::Path qw{make_path};
@@ -558,6 +559,9 @@ sub setupDatabase {
my $todbconf = shift;
my $opensslconf = shift;
my $setupMaxmind = shift;
+ my $databaseConfFile = shift;
+
+ my $dbconf = InstallUtils::readJson( $databaseConfFile );
InstallUtils::logger( "Setting up database", "info" );
chdir("/opt/traffic_ops/app");
@@ -570,6 +574,18 @@ sub setupDatabase {
InstallUtils::logger( "Database initialization succeeded", "info" );
}
+ my $dsn = sprintf( "DBI:mysql:%s:%s:%s", "mysql", $dbconf->{"hostname"}, $dbconf->{"port"} );
+ my $dbh = DBI->connect( $dsn, $todbconf->{"dbAdminUser"}, $todbconf->{"dbAdminPw"} );
+ if ($dbh) {
+ InstallUtils::logger("Database connection succeeded", "info");
+ # Success!
+ $dbh->disconnect();
+ }
+ else {
+ InstallUtils::logger("Error connecting to database", "error");
+ exit(-1)
+ }
+
if ( $setupMaxmind =~ /^y(?:es)?/ ) {
InstallUtils::logger( "Downloading Maxmind data", "info" );
chdir("/opt/traffic_ops/app/public/routing");
@@ -750,7 +766,7 @@ sub main {
# if reconfigure is set then setup the database
if ($reconfigure) {
- setupDatabase( $todbconf, $opensslconf, $todbconf->{"maxmind"} );
+ setupDatabase( $todbconf, $opensslconf, $todbconf->{"maxmind"}, $databaseConfFile );
}
InstallUtils::logger( "Starting Traffic Ops", "info" );