You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2017/01/27 16:53:36 UTC
[15/36] incubator-trafficcontrol git commit: Many minor tweaks -
better logging, gzip logs, and comments
Many minor tweaks - better logging, gzip logs, and comments
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/c2657439
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/c2657439
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/c2657439
Branch: refs/heads/master
Commit: c2657439c833ff898f286ba5e3219e329a8942f6
Parents: bae4375
Author: peryder <pe...@cisco.com>
Authored: Fri Dec 2 13:51:43 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/input.json | 8 +-
.../install/bin/postinstall-new-integrated | 147 ++++++++++---------
traffic_ops/install/lib/InstallUtils.pm | 5 +-
traffic_ops/install/lib/ProfileCleanup.pm | 2 +
4 files changed, 86 insertions(+), 76 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c2657439/traffic_ops/install/bin/input.json
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/input.json b/traffic_ops/install/bin/input.json
index fd9f0e6..f5ca7b6 100644
--- a/traffic_ops/install/bin/input.json
+++ b/traffic_ops/install/bin/input.json
@@ -1,9 +1,9 @@
{
"/opt/traffic_ops/app/conf/production/database.conf": [
- {
- "Database type": "mysql",
- "config_var": "type"
- },
+ {
+ "Database type": "mysql",
+ "config_var": "type"
+ },
{
"Database name": "traffic_ops_db",
"config_var": "dbname"
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c2657439/traffic_ops/install/bin/postinstall-new-integrated
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new-integrated b/traffic_ops/install/bin/postinstall-new-integrated
index 529cce8..3bfb712 100755
--- a/traffic_ops/install/bin/postinstall-new-integrated
+++ b/traffic_ops/install/bin/postinstall-new-integrated
@@ -38,8 +38,13 @@ our $reconfigure_defaults = "/opt/traffic_ops/.reconfigure_defaults";
our $parameters;
+# old way of reconfiguring postinstall - only here to check for file and let user know it is deprecated
my $reconfigure_file = "/opt/traffic_ops/.reconfigure";
+
+# whether or not to reconfigure traffic ops
my $reconfigure;
+
+# whether to create a config file with default values
my $dumpDefaults;
# log file for the installer
@@ -76,6 +81,7 @@ sub getConfigQuestion {
# question: The question given in the config file
# config_answer: The answer given in the config file - if no config file given will be defaultInput
+# hidden: Whether or not the answer should be hidden from the terminal and logs, ex. passwords
#
# Determines if the script is being run in complete interactive mode and prompts user - otherwise
# returns answer to question in config or defaults
@@ -87,6 +93,8 @@ sub getField {
# if there is no config file and not in automatic mode prompt for all questions with default answers
if ( !$::inputFile && !$::automatic ) {
+
+ # if hidden then dont show password in terminal
if ($hidden) {
return promptPasswordVerify($question);
}
@@ -117,11 +125,9 @@ sub getConfig {
logger( "===========$fileName===========", "info" );
foreach my $var ( @{ $userInput->{$fileName} } ) {
-
my $question = getConfigQuestion($var);
my $hidden = $var->{"hidden"} if ( exists $var->{"hidden"} );
- my $answer = $config{ $var->{"config_var"} } =
- getField( $question, $var->{$question}, $hidden );
+ my $answer = $config{ $var->{"config_var"} } = getField( $question, $var->{$question}, $hidden );
$config{ $var->{"config_var"} } = $answer;
if ( !$hidden ) {
@@ -152,8 +158,7 @@ sub generateDbConf {
my %todbconf = getConfig( $userInput, $toDBFileName );
# No YAML library installed, but this is a simple file..
- open( my $fh, '>', $toDBFileName )
- or errorOut("Can't write to $toDBFileName!");
+ open( my $fh, '>', $toDBFileName ) or errorOut("Can't write to $toDBFileName!");
print $fh "version: 1.0\n";
print $fh "name: dbconf.yml\n\n";
print $fh "production:\n";
@@ -178,16 +183,13 @@ sub generateCdnConf {
# First, read existing one -- already loaded with a bunch of stuff
my $cdnConf;
if ( -f $fileName ) {
- $cdnConf = Safe->new->rdo($fileName)
- or errorOut("Error loading $fileName: $@");
+ $cdnConf = Safe->new->rdo($fileName) or errorOut("Error loading $fileName: $@");
}
if ( lc $cdnConfiguration{genSecret} =~ /^y(?:es)?/ ) {
my @secrets = @{ $cdnConf->{secrets} };
my $newSecret = randomWord();
unshift @secrets, randomWord();
- if ( $cdnConfiguration{keepSecrets} > 0
- && $#secrets > $cdnConfiguration{keepSecrets} - 1 )
- {
+ if ( $cdnConfiguration{keepSecrets} > 0 && $#secrets > $cdnConfiguration{keepSecrets} - 1 ) {
# Shorten the array to requested length
$#secrets = $cdnConfiguration{keepSecrets} - 1;
@@ -247,6 +249,8 @@ sub generateOpenSSLConf {
if ( !defined $userInput->{$fileName} ) {
logger( "No OpenSSL Configuration - questions will be asked", "info" );
+
+ # write an empty config so openssl does not use an old file
writeJson( $fileName, my %emptyConfig );
return;
}
@@ -273,7 +277,7 @@ sub sanityCheckDefaults {
if ( !defined $defaultValue->{"config_var"}
|| $defaultValue->{"config_var"} eq "" )
{
- errorOut( "Question \'$question\' in file \'$file\' has no config_var" );
+ errorOut("Question '$question' in file '$file' has no config_var");
}
}
}
@@ -293,7 +297,7 @@ sub sanityCheckConfig {
foreach my $file ( ( keys $::defaultInputs ) ) {
if ( !defined $userInput->{$file} ) {
- logger( "File \'$file\' found in defaults but not config file", "warn" );
+ logger( "File '$file' found in defaults but not config file", "warn" );
$userInput->{$file} = [];
}
@@ -308,44 +312,39 @@ sub sanityCheckConfig {
# if the question is not found in the config file add it from defaults
if ( !$found ) {
- logger( "Value " . Dumper($defaultValue) . "found in defaults but not in \'$file\'", "warn" );
-
my $question = getConfigQuestion($defaultValue);
+ logger( "Question '$question' found in defaults but not in '$file'", "warn" );
my %temp;
+ my $answer;
+ my $hidden = exists $defaultValue->{"hidden"} && $defaultValue->{"hidden"} ? 1 : 0;
# in automatic mode add the missing question with default answer
if ($::automatic) {
- logger( "Adding question \'$question\' with default answer \'$defaultValue->{$question}\'", "info" );
-
- %temp = (
- "config_var" => $defaultValue->{"config_var"},
- $question => $defaultValue->{$question}
- );
+ logger( "Adding question '$question' with default answer " . ( $defaultValue->{"hidden"} ? "" : "'$defaultValue->{$question}'" ), "info" );
+ $answer = $defaultValue->{$question};
}
# in interactive mode prompt the user for answer to missing question
else {
logger( "Prompting user for answer", "info" );
- my $answer;
- if ( exists $defaultValue->{"hidden"}
- && $defaultValue->{"hidden"} )
- {
+ if ($hidden) {
$answer = promptPasswordVerify($question);
- %temp = (
- "config_var" => $defaultValue->{"config_var"},
- $question => $answer,
- "hidden" => "true"
- );
}
else {
$answer = promptUser( $question, $defaultValue->{$question} );
- %temp = (
- "config_var" => $defaultValue->{"config_var"},
- $question => $answer
- );
}
}
+
+ %temp = (
+ "config_var" => $defaultValue->{"config_var"},
+ $question => $answer
+ );
+
+ if ($hidden) {
+ $temp{"hidden"} .= "true";
+ }
+
push $userInput->{$file}, \%temp;
$diffs++;
@@ -353,10 +352,7 @@ sub sanityCheckConfig {
}
}
- logger( "File sanity check complete - found $diffs differences", "info" )
- if ( $::debug && $diffs == 0 );
- logger( "File sanity check complete - found $diffs difference(s)", "info" )
- if ( $diffs > 0 );
+ logger( "File sanity check complete - found $diffs difference" . ( $diffs == 1 ? "" : "s" ), "info" );
}
# A function which returns the default inputs data structure. These questions and answers will be used if there is no
@@ -367,15 +363,15 @@ sub getDefaults {
$::databaseConfFile => [
{
"Database type" => "mysql",
- "config_var" => "type",
+ "config_var" => "type"
},
{
"Database name" => "traffic_ops",
- "config_var" => "dbname",
+ "config_var" => "dbname"
},
{
"Database server hostname IP or FQDN" => "localhost",
- "config_var" => "hostname",
+ "config_var" => "hostname"
},
{
"Database port number" => "3306",
@@ -478,7 +474,7 @@ sub getDefaults {
"hidden" => "true"
}
],
- $::paramConfFile = [
+ $::paramConfFile => [
{
"Traffic Ops url" => "https://localhost",
"config_var" => "tm.url"
@@ -528,6 +524,11 @@ sub getDefaults {
};
}
+# carried over from old postinstall
+#
+# todbconf: The database configuration to be used
+# opensslconf: The openssl configuration if any
+
sub setupDatabase {
my $todbconf = shift;
my $opensslconf = shift;
@@ -559,7 +560,7 @@ sub setupDatabase {
logger( "Downloading MaxMind data", "info" );
chdir("/opt/traffic_ops/app/public/routing");
- $result = execCommand( "/usr/bin/wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz" );
+ $result = execCommand("/usr/bin/wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz");
if ( $result != 0 ) {
logger( "Failed to download MaxMind data", "error" );
}
@@ -589,12 +590,14 @@ sub setupDatabase {
}
-# -d - Debug Mode: More output to the terminal
-# -a - Automatic mode: If there are questions in the config file which do not have answers, the script
-# will look to the defaults for the answer. If the answer is not in the defaults
-# the script will exit
-# -h - Help: Basic command line help menu
-# -cfile - Input File: The input config file used to ask and answer questions
+# -cfile - Input File: The input config file used to ask and answer questions
+# -a - Automatic mode: If there are questions in the config file which do not have answers, the script
+# will look to the defaults for the answer. If the answer is not in the defaults
+# the script will exit
+# -r - Reconfigure: Whether or not to reconfigure the database and check perl dependencies - This will rereate the database
+# -defaults - Defaults: Writes out a configuration file with defaults which can be used as input
+# -debug - Debug Mode: More output to the terminal
+# -h - Help: Basic command line help menu
sub main {
our $inputFile = "";
@@ -602,7 +605,7 @@ sub main {
our $debug = 0;
my $help = 0;
- my $usageString = "Usage: postinstall [-a] [-d] -cfile=[config_file]\n";
+ my $usageString = "Usage: postinstall [-a] [-debug] [-defaults] [-r] -cfile=[config_file]\n";
GetOptions(
"cfile=s" => \$inputFile,
@@ -621,37 +624,37 @@ sub main {
exit(0);
}
+ # check if the user running postinstall is root
if ( $ENV{USER} ne "root" ) {
errorOut("You must run this script as the root user");
}
+ if ( -f "$logFile.gz" ) {
+ execCommand( "/bin/gunzip", "$logFile.gz" );
+ }
+
logger( "Starting postinstall", "info" );
- if ($::debug) {
- logger( "Debug is on", "info" );
- }
+ logger( "Debug is on", "info" );
if ($::automatic) {
logger( "Running in automatic mode", "info" );
}
+ # check if the reconfigure_file is present on the system - if it is let the user know its deprecated
+ # and exit with an error
if ( -f $reconfigure_file ) {
logger( "$reconfigure_file file is reprecated - please remove and rerun postinstall", "error" );
- exit(-1);
+ return;
}
if ($dumpDefaults) {
logger( "Writing default configuration file to $outputConfigFile", "info" );
writeJson( $outputConfigFile, $::defaultInputs );
- exit(0);
+ return;
}
- if ($reconfigure) {
- logger( "Postinstall is in reconfigure mode", "info" );
- }
- else {
- logger( "Postinstall not in reconfigure mode", "info" );
- }
+ logger( "Postinstall " . ( defined $reconfigure ? "in" : "not" ) . " in reconfigure mode", "info" );
# check if the user has root access
if ( $ENV{USER} ne "root" ) {
@@ -677,7 +680,7 @@ sub main {
logger( "Using input file $::inputFile", "info" );
# check if the input file exists
- errorOut("File \'$::inputFile\' not found") if ( !-f $::inputFile );
+ errorOut("File '$::inputFile' not found") if ( !-f $::inputFile );
# read and store the input file
$userInput = readJson($::inputFile);
@@ -695,21 +698,21 @@ sub main {
if ( -f $reconfigure_file || $reconfigure ) {
my $rc = BuildPerlDeps::build(1);
if ( $rc != 0 ) {
- errorOut( "Failed to install perl dependencies, check the console output and rerun postinstall once you've resolved the error" );
+ errorOut("Failed to install perl dependencies, check the console output and rerun postinstall once you've resolved the error");
}
$rc = execCommand( "./download_web_deps", "-i" );
if ( $rc != 0 ) {
- errorOut( "Failed to install Traffic Ops Web dependencies, check the console output and rerun postinstall once you've resolved the error" );
+ errorOut("Failed to install Traffic Ops Web dependencies, check the console output and rerun postinstall once you've resolved the error");
}
}
else {
my $rc = BuildPerlDeps::build();
if ( $rc != 0 ) {
- errorOut( "Failed to install perl dependencies, check the console output and rerun postinstall once you've resolved the error" );
+ errorOut("Failed to install perl dependencies, check the console output and rerun postinstall once you've resolved the error");
}
$rc = execCommand( "./download_web_deps", "-i" );
if ( $rc != 0 ) {
- errorOut( "Failed to install Traffic Ops Web dependencies, check the console output and rerun postinstall once you've resolved the error" );
+ errorOut("Failed to install Traffic Ops Web dependencies, check the console output and rerun postinstall once you've resolved the error");
}
}
@@ -746,18 +749,20 @@ sub main {
logger( "Waiting for Traffic Ops to start", "info" );
if ( !profiles_exist( $adminconf, $paramconf->{"tm.url"} ) ) {
- print "Creating default profiles...\n";
- replace_profile_templates( $paramconf, $paramconf->{"tm.url"} );
+ logger( "Creating default profiles...", "info" );
+ replace_profile_templates($paramconf);
import_profiles($adminconf);
- profiles_exist($adminconf); # call again to create $reconfigure_defaults file if import was successful
+ profiles_exist( $adminconf, $paramconf->{"tm.url"} ); # call again to create $reconfigure_defaults file if import was successful
}
else {
- print "Not creating default profiles.\n";
+ logger( "Not creating default profiles", "info" );
}
+
+ logger("Postinstall complete");
+
+ execCommand( "/bin/gzip", "$logFile" );
}
main;
-logger( "Postinstall complete\n", "info" );
-
# vi:syntax=perl
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c2657439/traffic_ops/install/lib/InstallUtils.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/InstallUtils.pm b/traffic_ops/install/lib/InstallUtils.pm
index 72665d1..a30042f 100644
--- a/traffic_ops/install/lib/InstallUtils.pm
+++ b/traffic_ops/install/lib/InstallUtils.pm
@@ -39,7 +39,8 @@ sub execCommand {
my $customLog = "";
# find log file in args and remove if found
- # TODO: More documentation here
+ # if there is a string in the list of args which starts with 'pi_custom_log=' then remove it from the parameters and use
+ # it as the log file for the exec
foreach my $var (@args) {
if ( index($var, "pi_custom_log=") != -1 ) {
$customLog = (split(/=/, $var))[1];
@@ -69,6 +70,7 @@ sub execCommand {
}
}
+# log the error and then kill the process
sub errorOut {
logger( @_, "error" );
die;
@@ -139,6 +141,7 @@ sub randomWord {
return $secret;
}
+# deprecated
sub promptUser {
my ( $promptString, $defaultValue, $noEcho ) = @_;
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c2657439/traffic_ops/install/lib/ProfileCleanup.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/ProfileCleanup.pm b/traffic_ops/install/lib/ProfileCleanup.pm
index 3606002..0baecb7 100644
--- a/traffic_ops/install/lib/ProfileCleanup.pm
+++ b/traffic_ops/install/lib/ProfileCleanup.pm
@@ -145,6 +145,8 @@ sub profiles_exist {
$::parameters->{'tm.url'} = $tmurl;
+ logger("Checking profiles at $tmurl using username " . $config->{"username"}, "info");
+
my $uri = $::parameters->{'tm.url'};
my $toCookie = get_traffic_ops_cookie( $::parameters->{'tm.url'}, $config->{"username"}, $config->{"password"} );