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:22 UTC
[01/36] incubator-trafficcontrol git commit: Misc fixes for maxmind
location in config and generating a cert without input parameters
Repository: incubator-trafficcontrol
Updated Branches:
refs/heads/master 5be5a7c9c -> aac8a858c
Misc fixes for maxmind location in config and generating a cert without input parameters
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/aac8a858
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/aac8a858
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/aac8a858
Branch: refs/heads/master
Commit: aac8a858c3de4129bef5e34da5cf3f065f8fb19c
Parents: f1f9af0
Author: peter.w.ryder <pe...@gmail.com>
Authored: Fri Jan 27 11:41:47 2017 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/input.json | 12 ++++++------
traffic_ops/install/bin/postinstall | 15 +++++++++------
traffic_ops/install/lib/GenerateCert.pm | 23 +++++++++++++++++------
3 files changed, 32 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/aac8a858/traffic_ops/install/bin/input.json
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/input.json b/traffic_ops/install/bin/input.json
index 136dfa7..85c4d03 100644
--- a/traffic_ops/install/bin/input.json
+++ b/traffic_ops/install/bin/input.json
@@ -24,10 +24,6 @@
"Traffic Ops database password":"default",
"config_var":"password",
"hidden":"1"
- },
- {
- "Download Maxmind Database?":"yes",
- "config_var":"maxmind"
}
],
"/opt/traffic_ops/app/db/dbconf.yml":[
@@ -39,6 +35,10 @@
"Database server admin password":"default",
"config_var":"dbAdminPw",
"hidden":"1"
+ },
+ {
+ "Download Maxmind Database?":"yes",
+ "config_var":"maxmind"
}
],
"/opt/traffic_ops/app/conf/cdn.conf":[
@@ -164,7 +164,7 @@
"config_var":"health_thresh_load_avg"
},
{
- "Health Threshold Available Bandwidth in Kbps":">1750000",
+ "Health Threshold Available Bandwidth in Kbps":"1750000",
"config_var":"health_thresh_kbps"
},
{
@@ -172,4 +172,4 @@
"config_var":"health_connect_timeout"
}
]
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/aac8a858/traffic_ops/install/bin/postinstall
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall b/traffic_ops/install/bin/postinstall
index fbff253..97f5028 100755
--- a/traffic_ops/install/bin/postinstall
+++ b/traffic_ops/install/bin/postinstall
@@ -407,11 +407,8 @@ sub getDefaults {
"Password for Traffic Ops database user" => "",
"config_var" => "password",
"hidden" => "true"
- },
- {
- "Download Maxmind Database?" => "yes",
- "config_var" => "maxmind"
}
+
],
$dbConfFile => [
{
@@ -422,6 +419,10 @@ sub getDefaults {
"Password for database server admin" => "",
"config_var" => "dbAdminPw",
"hidden" => "true"
+ },
+ {
+ "Download Maxmind Database?" => "yes",
+ "config_var" => "maxmind"
}
],
$cdnConfFile => [
@@ -754,7 +755,9 @@ sub main {
my $opensslconf = generateOpenSSLConf( $userInput, $opensslConfFile );
my $paramconf = generateParamConf( $userInput, $paramConfFile );
- InstallUtils::writeJson( $post_install_cfg, $paramconf );
+ if ( !-f $post_install_cfg ) {
+ InstallUtils::writeJson( $post_install_cfg, {} );
+ }
# if reconfigure is set then setup the database
if ($reconfigure) {
@@ -762,7 +765,7 @@ sub main {
setupDatabase( $todbconf, $opensslConfFile, $opensslconf->{"genCert"}, $todbconf->{"maxmind"} );
}
else {
- setupDatabase( $todbconf, 0, $opensslconf->{"genCert"} );
+ setupDatabase( $todbconf, 0, $opensslconf->{"genCert"}, $todbconf->{"maxmind"} );
}
}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/aac8a858/traffic_ops/install/lib/GenerateCert.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/GenerateCert.pm b/traffic_ops/install/lib/GenerateCert.pm
index ef2bb46..644e482 100644
--- a/traffic_ops/install/lib/GenerateCert.pm
+++ b/traffic_ops/install/lib/GenerateCert.pm
@@ -142,18 +142,21 @@ sub createCert {
}
}
- if ( execOpenssl( "Generating an RSA Private Server Key", "genrsa", "-des3", "-out", "server.key", "-passout", "pass:$passphrase", "1024" ) != 0 ) {
- exit 1;
- }
InstallUtils::logger( "The server key has been generated", "info" );
if ($params) {
+ if ( execOpenssl( "Generating an RSA Private Server Key", "genrsa", "-des3", "-out", "server.key", "-passout", "pass:$passphrase", "1024" ) != 0 ) {
+ exit 1;
+ }
if ( execOpenssl( "Creating a Certificate Signing Request (CSR)", "req", "-new", "-key", "server.key", "-out", "server.csr", "-passin", "pass:$passphrase", "-subj", $params ) != 0 ) {
exit 1;
}
}
else {
- if ( execOpenssl( "Creating a Certificate Signing Request (CSR)", "req", "-new", "-key", "server.key", "-out", "server.csr", "-passin", "pass:$passphrase" ) != 0 ) {
+ if ( execOpenssl( "Generating an RSA Private Server Key", "genrsa", "-des3", "-out", "server.key", "1024" ) != 0 ) {
+ exit 1;
+ }
+ if ( execOpenssl( "Creating a Certificate Signing Request (CSR)", "req", "-new", "-key", "server.key", "-out", "server.csr") != 0 ) {
exit 1;
}
}
@@ -162,9 +165,17 @@ sub createCert {
InstallUtils::execCommand( "/bin/mv", "server.key", "server.key.orig" );
- if ( execOpenssl( "Removing the pass phrase from the server key", "rsa", "-in", "server.key.orig", "-out", "server.key", "-passin", "pass:$passphrase" ) != 0 ) {
- exit 1;
+ if ($params) {
+ if ( execOpenssl( "Removing the pass phrase from the server key", "rsa", "-in", "server.key.orig", "-out", "server.key", "-passin", "pass:$passphrase" ) != 0 ) {
+ exit 1;
+ }
}
+ else {
+ if ( execOpenssl( "Removing the pass phrase from the server key", "rsa", "-in", "server.key.orig", "-out", "server.key") != 0 ) {
+ exit 1;
+ }
+ }
+
InstallUtils::logger( "The pass phrase has been removed from the server key", "info" );
if ( execOpenssl( "Generating a Self-signed certificate", "x509", "-req", "-days", "365", "-in", "server.csr", "-signkey", "server.key", "-out", "server.crt" ) != 0 ) {
[27/36] incubator-trafficcontrol git commit: Removed creation of
reconfigure file
Posted by da...@apache.org.
Removed creation of reconfigure file
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/19d760ab
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/19d760ab
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/19d760ab
Branch: refs/heads/master
Commit: 19d760ab56ab42e85ef4edbe63393dc280b0a3af
Parents: a3433b0
Author: peryder <pe...@cisco.com>
Authored: Thu Dec 8 16:21:27 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/build/traffic_ops.spec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/19d760ab/traffic_ops/build/traffic_ops.spec
----------------------------------------------------------------------
diff --git a/traffic_ops/build/traffic_ops.spec b/traffic_ops/build/traffic_ops.spec
index b1ca3f6..4483aa2 100644
--- a/traffic_ops/build/traffic_ops.spec
+++ b/traffic_ops/build/traffic_ops.spec
@@ -109,7 +109,7 @@ Built: %(date) by %{getenv: USER}
# install
if [ "$1" = "1" ]; then
# see postinstall, the .reconfigure file triggers init().
- /bin/touch %{PACKAGEDIR}/.reconfigure
+ #/bin/touch %{PACKAGEDIR}/.reconfigure
echo -e "\nRun /opt/traffic_ops/install/bin/postinstall from the root home directory to complete the install.\n"
fi
[20/36] incubator-trafficcontrol git commit: Reset
build_trafficops_perl_library
Posted by da...@apache.org.
Reset build_trafficops_perl_library
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/832a50f3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/832a50f3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/832a50f3
Branch: refs/heads/master
Commit: 832a50f3320cf18c50b4f186683b138d2324a167
Parents: 5bcd2be
Author: peryder <pe...@cisco.com>
Authored: Wed Dec 7 10:09:39 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
.../install/bin/build_trafficops_perl_library | 138 ++++++++-----------
1 file changed, 60 insertions(+), 78 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/832a50f3/traffic_ops/install/bin/build_trafficops_perl_library
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/build_trafficops_perl_library b/traffic_ops/install/bin/build_trafficops_perl_library
index 0bca5e9..684916d 100755
--- a/traffic_ops/install/bin/build_trafficops_perl_library
+++ b/traffic_ops/install/bin/build_trafficops_perl_library
@@ -1,13 +1,12 @@
#!/usr/bin/perl
#
-# Copyright 2015 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,13 +17,15 @@
use strict;
use warnings;
use Getopt::Std;
+use InstallUtils;
our ($opt_i);
-my @dependencies = ("expat-devel","mod_ssl","mkisofs","libpcap","libpcap-devel",
- "libcurl","libcurl-devel","mysql-server","mysql-devel",
- "openssl","openssl-devel","cpan","gcc","make","pkgconfig","automake","autoconf",
- "libtool","gettext","libidn-devel");
+my @dependencies = (
+ "expat-devel", "mod_ssl", "mkisofs", "libpcap", "libpcap-devel", "libcurl",
+ "libcurl-devel", "mysql-server", "mysql-devel", "openssl", "cpan", "gcc",
+ "make", "pkgconfig", "automake", "autoconf", "libtool", "gettext"
+);
my $msg = << 'EOF';
This script will build and package the required Traffic Ops perl modules.
@@ -33,55 +34,36 @@ compiler will be installed on this machine.
EOF
-sub execCommand {
- my ($command, @args) = @_;
- my $pid = fork ();
- my $result = 0;
+sub promptUser {
+ my ( $promptString, $defaultValue, $noEcho ) = @_;
- if ($pid == 0) {
- exec ($command, @args);
- exit 0;
+ if ($defaultValue) {
+ print $promptString, " [", $defaultValue, "]: ";
}
else {
- wait;
- $result = $?;
- if ($result != 0) {
- print "ERROR executing: $command, args: " . join (' ', @args) . "\n";
+ print $promptString, ": ";
+ }
+
+ if ( defined $noEcho && $noEcho ) {
+ my $response = read_password('');
+ if ( ( !defined $response || $response eq '' ) && ( defined $defaultValue && $defaultValue ne '' ) ) {
+ $response = $defaultValue;
}
+ return $response;
}
- return $result;
-}
+ else {
+ $| = 1;
+ $_ = <STDIN>;
+ chomp;
-sub promptUser {
- my ($promptString, $defaultValue, $noEcho) = @_;
-
- if ($defaultValue) {
- print $promptString, " [", $defaultValue, "]: ";
- }
- else {
- print $promptString, ": ";
- }
-
- if (defined $noEcho && $noEcho) {
- my $response = read_password('');
- if ((!defined $response || $response eq '') && (defined $defaultValue && $defaultValue ne '')) {
- $response = $defaultValue;
- }
- return $response
- }
- else {
- $| = 1;
- $_ = <STDIN>;
- chomp;
-
- if ("$defaultValue") {
- return $_ ? $_ : $defaultValue;
- }
- else {
- return $_;
- }
- return $_;
- }
+ if ("$defaultValue") {
+ return $_ ? $_ : $defaultValue;
+ }
+ else {
+ return $_;
+ }
+ return $_;
+ }
}
sub trim {
@@ -99,69 +81,69 @@ my $result;
## MAIN ##
#################################
-$ENV{PERL_MM_USE_DEFAULT}=1;
-$ENV{PERL_MM_NONINTERACTIVE}=1;
-$ENV{AUTOMATED_TESTING}=1;
+$ENV{PERL_MM_USE_DEFAULT} = 1;
+$ENV{PERL_MM_NONINTERACTIVE} = 1;
+$ENV{AUTOMATED_TESTING} = 1;
-getopts ('i');
+getopts('i');
-execCommand ("/usr/bin/tput","clear");
+InstallUtils::execCommand( "/usr/bin/tput", "clear" );
-if ($ENV{USER} ne "root") {
+if ( $ENV{USER} ne "root" ) {
print "WARNING: You must run this script as the root user.\n";
exit 0;
}
print $msg;
-promptUser ("Hit ENTER to continue","");
+promptUser( "Hit ENTER to continue", "" );
-chdir ("/opt/traffic_ops/app");
+chdir("/opt/traffic_ops/app");
-if (defined $opt_i && $opt_i == 1) {
- if (! -x "/usr/bin/yum") {
+if ( defined $opt_i && $opt_i == 1 ) {
+ if ( !-x "/usr/bin/yum" ) {
print "WARNING: You must install 'yum'.\n";
exit 0;
}
print "\nInstalling dependencies.\n";
- $result = execCommand ("/usr/bin/yum", "install", @dependencies);
- if ($result != 0) {
+ $result = InstallUtils::execCommand( "/usr/bin/yum", "install", @dependencies );
+ if ( $result != 0 ) {
print "WARNING: dependency installation failed, look through the output and correct the problem.\n";
exit 0;
}
print "\nBuilding perl modules\n";
- $result = execCommand ("/opt/traffic_ops/install/bin/cpan.sh", "/opt/traffic_ops/install/bin/yaml.txt");
- if ($result != 0) {
+ $result = InstallUtils::execCommand( "/usr/bin/cpan", "-if", "YAML" );
+ if ( $result != 0 ) {
print "WARNING: Failed to install YAML, look through the output and correct the problem.\n";
exit 0;
}
- $result = execCommand ("/opt/traffic_ops/install/bin/cpan.sh", "/opt/traffic_ops/install/bin/carton.txt");
- if ($result != 0) {
+ $result = InstallUtils::execCommand( "/usr/bin/cpan", "-if", "MIYAGAWA/Carton-v1.0.15.tar.gz" );
+ if ( $result != 0 ) {
print "WARNING: Failed to install Carton, look through the output and correct the problem.\n";
exit 0;
}
}
-$result = execCommand ("/usr/local/bin/carton","install","--deployment","--cached");
-if ($result != 0) {
+$result = InstallUtils::execCommand( "/usr/local/bin/carton", "install" );
+if ( $result != 0 ) {
print "WARNING: Failure to build required perl modules, check the output and correct the problem.\n";
exit 0;
}
-if (! -s "/opt/traffic_ops/lib/perl5") {
- print "Linking perl libraries...\n";
- if (! -d "/opt/traffic_ops/lib") {
- mkdir ("/opt/traffic_ops/lib");
- }
- symlink ("/opt/traffic_ops/app/local/lib/perl5","/opt/traffic_ops/lib/perl5");
- execCommand ("/bin/chown","-R","trafops:trafops","/opt/traffic_ops/lib");
+if ( !-s "/opt/traffic_ops/lib/perl5" ) {
+ print "Linking perl libraries...\n";
+ if ( !-d "/opt/traffic_ops/lib" ) {
+ mkdir("/opt/traffic_ops/lib");
+ }
+ symlink( "/opt/traffic_ops/app/local/lib/perl5", "/opt/traffic_ops/lib/perl5" );
+ InstallUtils::execCommand( "/bin/chown", "-R", "trafops:trafops", "/opt/traffic_ops/lib" );
}
print "Installing perl scripts\n";
-chdir ("/opt/traffic_ops/app/local/bin");
-my $rc = execCommand ("/bin/cp","-R",".","/opt/traffic_ops/app/bin");
-if ($rc != 0) {
- print "WARNING: Failed to copy perl scripts to /opt/traffic_ops/app/bin.\n";
+chdir("/opt/traffic_ops/app/local/bin");
+my $rc = InstallUtils::execCommand( "/bin/cp", "-R", ".", "/opt/traffic_ops/app/bin" );
+if ( $rc != 0 ) {
+ print "WARNING: Failed to copy perl scripts to /opt/traffic_ops/app/bin.\n";
}
[35/36] incubator-trafficcontrol git commit: Change default answer to
pg in postinstall
Posted by da...@apache.org.
Change default answer to pg in postinstall
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/f1f9af06
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/f1f9af06
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/f1f9af06
Branch: refs/heads/master
Commit: f1f9af06907fa1cd13a0273ef0728e66e5d5f8ec
Parents: 2f73509
Author: peter.w.ryder <pe...@gmail.com>
Authored: Fri Jan 20 09:53:20 2017 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/f1f9af06/traffic_ops/install/bin/postinstall
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall b/traffic_ops/install/bin/postinstall
index f1aa23f..fbff253 100755
--- a/traffic_ops/install/bin/postinstall
+++ b/traffic_ops/install/bin/postinstall
@@ -384,7 +384,7 @@ sub getDefaults {
return {
$databaseConfFile => [
{
- "Database type" => "mysql",
+ "Database type" => "pg",
"config_var" => "type"
},
{
@@ -410,7 +410,7 @@ sub getDefaults {
},
{
"Download Maxmind Database?" => "yes",
- "config_var" => "maxmind"
+ "config_var" => "maxmind"
}
],
$dbConfFile => [
@@ -470,11 +470,11 @@ sub getDefaults {
],
$profilesConfFile => [
{
- "Add custom profiles?" =>"no",
- "config_var" => "custom_profiles"
+ "Add custom profiles?" => "no",
+ "config_var" => "custom_profiles"
}
],
- $opensslConfFile => [
+ $opensslConfFile => [
{
"Do you want to generate a certificate?" => "yes",
"config_var" => "genCert"
@@ -565,9 +565,9 @@ sub getDefaults {
# opensslconf: The openssl configuration if any
sub setupDatabase {
- my $todbconf = shift;
- my $opensslconf = shift;
- my $genCert = shift;
+ my $todbconf = shift;
+ my $opensslconf = shift;
+ my $genCert = shift;
my $setupMaxmind = shift;
InstallUtils::logger( "Setting up database", "info" );
@@ -581,7 +581,7 @@ sub setupDatabase {
InstallUtils::logger( "Database initialization succeeded", "info" );
}
- if ($setupMaxmind =~ /^y(?:es)?/) {
+ if ( $setupMaxmind =~ /^y(?:es)?/ ) {
InstallUtils::logger( "Downloading Maxmind data", "info" );
chdir("/opt/traffic_ops/app/public/routing");
$result = InstallUtils::execCommand("/usr/bin/wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz");
[28/36] incubator-trafficcontrol git commit: Added option to bypass
certificate generation
Posted by da...@apache.org.
Added option to bypass certificate generation
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/be8df01b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/be8df01b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/be8df01b
Branch: refs/heads/master
Commit: be8df01b7214036e898dfd1821d718cc978e65b8
Parents: 19d760a
Author: peryder <pe...@cisco.com>
Authored: Tue Dec 13 15:18:31 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall-new | 37 +++++++++++++++-------------
1 file changed, 20 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/be8df01b/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
index c5ffeef..155651c 100755
--- a/traffic_ops/install/bin/postinstall-new
+++ b/traffic_ops/install/bin/postinstall-new
@@ -44,9 +44,6 @@ our $profilesConfFile = "/opt/traffic_ops/install/data/profiles/";
our $opensslConfFile = "/opt/traffic_ops/install/bin/openssl_configuration.json";
our $paramConfFile = "/opt/traffic_ops/install/data/json/profiles.json";
-our $profile_dir = "/opt/traffic_ops/install/data/profiles/";
-our $post_install_cfg = "/opt/traffic_ops/install/data/json/post_install.json";
-
our $reconfigure_defaults = "/opt/traffic_ops/.reconfigure_defaults";
our $parameters;
@@ -278,6 +275,7 @@ sub generateParamConf {
my $fileName = shift;
my %config = getConfig( $userInput, $fileName );
+ writeJson( $fileName, \%config );
return \%config;
}
@@ -300,9 +298,6 @@ sub sanityCheckDefaults {
#
# Checks the input config file against the default inputs. If there is a question located in the default inputs which
# is not located in the input config file it will output a warning message.
-#
-# This does not check the other way meaning questions which are present in defaults but not present in the input config
-# file will not be checked
sub sanityCheckConfig {
my $userInput = shift;
@@ -458,6 +453,10 @@ sub getDefaults {
$::profilesConfFile => [],
$::opensslConfFile => [
{
+ "Do you want to generate a certificate?" => "yes",
+ "config_var" => "genCert"
+ },
+ {
"Country Name (2 letter code)" => "XX",
"config_var" => "country"
},
@@ -478,7 +477,7 @@ sub getDefaults {
"config_var" => "org_unit"
},
{
- "Common Name (eg, your name or your server's hostname)" => "cisco.com",
+ "Common Name (eg, your name or your server's hostname)" => "example.com",
"config_var" => "common_name"
},
{
@@ -584,23 +583,27 @@ sub setupDatabase {
logger( "Failed to copy coverage zone file", "error" );
}
- if ( -x "/usr/bin/openssl" ) {
- logger( "Installing SSL Certificates", "info" );
- $result = GenerateCert::createCert($opensslconf);
+ if ( lc $opensslconf->{genCert} =~ /^y(?:es)?/ ) {
+ if ( -x "/usr/bin/openssl" ) {
+ logger( "Installing SSL Certificates", "info" );
+ $result = GenerateCert::createCert($opensslconf);
- if ( $result != 0 ) {
- errorOut("SSL Certificate Installation failed");
+ if ( $result != 0 ) {
+ errorOut("SSL Certificate Installation failed");
+ }
+ else {
+ logger( "SSL Certificates have been installed", "info" );
+ }
}
else {
- logger( "SSL Certificates have been installed", "info" );
+ logger( "Unable to install SSL certificates as openssl is not installed", "error" );
+ logger( "Install openssl and then run /opt/traffic_ops/install/bin/generateCert to install SSL certificates", "error" );
+ exit 4;
}
}
else {
- logger( "Unable to install SSL certificates as openssl is not installed", "error" );
- logger( "Install openssl and then run /opt/traffic_ops/install/bin/generateCert to install SSL certificates", "error" );
- exit 4;
+ logger("Not generating openssl certification", "info");
}
-
}
# -cfile - Input File: The input config file used to ask and answer questions
[03/36] incubator-trafficcontrol git commit: -Removed reconfigure
line -Removed trailing spaces in input.json -Renamed postinstall-new to
postinstall for easier diff
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/64f49e3f/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
deleted file mode 100755
index 1092338..0000000
--- a/traffic_ops/install/bin/postinstall-new
+++ /dev/null
@@ -1,781 +0,0 @@
-#!/usr/bin/perl
-
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
-$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
-$ENV{PERL5LIB} = "/opt/traffic_ops/install/lib:/opt/traffic_ops/install/lib/perl5:/opt/traffic_ops/app/local/lib/perl5:/opt/traffic_ops/app/lib";
-
-use strict;
-use warnings;
-
-use Safe;
-use POSIX;
-use File::Basename qw{dirname};
-use File::Path qw{make_path};
-use InstallUtils qw{ :all };
-use BuildPerlDeps qw{ :all };
-use GenerateCert qw{ :all };
-use ProfileCleanup qw { :all };
-use Digest::SHA1 qw(sha1_hex);
-use Data::Dumper qw(Dumper);
-use Scalar::Util qw(looks_like_number);
-use Getopt::Long;
-
-# paths of the output configuration files
-our $databaseConfFile = "/opt/traffic_ops/app/conf/production/database.conf";
-our $dbConfFile = "/opt/traffic_ops/app/db/dbconf.yml";
-our $cdnConfFile = "/opt/traffic_ops/app/conf/cdn.conf";
-our $ldapConfFile = "/opt/traffic_ops/app/conf/ldap.conf";
-our $usersConfFile = "/opt/traffic_ops/install/data/json/users.json";
-our $profilesConfFile = "/opt/traffic_ops/install/data/profiles/";
-our $opensslConfFile = "/opt/traffic_ops/install/data/json/openssl_configuration.json";
-our $paramConfFile = "/opt/traffic_ops/install/data/json/profiles.json";
-
-our $profile_dir = "/opt/traffic_ops/install/data/profiles/";
-our $post_install_cfg = "/opt/traffic_ops/install/data/json/post_install.json";
-
-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
-our $logFile = "/var/log/traffic_ops/postinstall.log";
-
-# maximum size the uncompressed log file should be before rotating it - rotating it copies the current log
-# file to the same name appended with .bkp replacing the old backup if any is there
-my $maxLogSize = 1000000; #bytes
-
-# log file for cpan - this log becomes large and is rotated every install
-our $cpanLogFile = "/var/log/traffic_ops/cpan.log";
-
-# configuration file output with answers which can be used as input to postinstall
-our $outputConfigFile = "/var/log/traffic_ops/configuration_file.json";
-
-sub getDbDriver {
- return "mymysql";
-}
-
-sub getInstallPath {
- my $relPath = shift;
- return join( '/', "/tmp/traffic_ops", $relPath );
-}
-
-# given a var to the hash of config_var and question, will return the question
-sub getConfigQuestion {
- my $var = shift;
- foreach my $key ( keys $var ) {
- if ( $key ne "hidden" && $key ne "config_var" ) {
- return $key;
- }
- }
-}
-
-# 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
-
-sub getField {
- my $question = shift;
- my $config_answer = shift;
- my $hidden = shift;
-
- # 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);
- }
- else {
- return promptUser( $question, $config_answer );
- }
- }
-
- return $config_answer;
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-# fileName: The name of the output config file given by the input config file
-#
-# Loops through an input config file and determines answers to each question using getField
-# and returns the hash of answers
-
-sub getConfig {
- my $userInput = shift;
- my $fileName = shift;
-
- my %config;
-
- if ( !defined $userInput->{$fileName} ) {
- logger( "No $fileName found in config", "error" );
- }
-
- 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 );
-
- $config{ $var->{"config_var"} } = $answer;
- if ( !$hidden ) {
- logger( "$question: $answer", "info" );
- }
- }
- return %config;
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-# dbFileName: The filename of the output config file for the database
-# toDBFileName: The filename of the output config file for the Traffic Ops database
-#
-# Generates a config file for the database based on the questions and answers in the input config file
-
-sub generateDbConf {
- my $userInput = shift;
- my $dbFileName = shift;
- my $toDBFileName = shift;
-
- my %dbconf = getConfig( $userInput, $dbFileName );
- $dbconf{"description"} = "$dbconf{type} database on $dbconf{hostname}:$dbconf{port}";
- make_path( dirname($dbFileName), { mode => 0755 } );
- writeJson( $dbFileName, \%dbconf );
- logger( "Database configuration has been saved", "info" );
-
- # broken out into separate file/config area
- 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!");
- print $fh "production:\n";
- print $fh " driver: ", getDbDriver() . "\n";
- print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{user}/$dbconf{password}\n";
- close $fh;
-
- return \%todbconf;
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-# fileName: The filename of the output config file
-#
-# Generates a config file for the CDN
-
-sub generateCdnConf {
- my $userInput = shift;
- my $fileName = shift;
-
- my %cdnConfiguration = getConfig( $userInput, $fileName );
-
- # 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: $@");
- }
- if ( lc $cdnConfiguration{genSecret} =~ /^y(?:es)?/ ) {
- my @secrets = @{ $cdnConf->{secrets} };
- my $newSecret = randomWord();
- unshift @secrets, randomWord();
- if ( $cdnConfiguration{keepSecrets} > 0 && $#secrets > $cdnConfiguration{keepSecrets} - 1 ) {
-
- # Shorten the array to requested length
- $#secrets = $cdnConfiguration{keepSecrets} - 1;
- }
- }
- writePerl( $fileName, $cdnConf );
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-# fileName: The filename of the output config file
-#
-# Generates an LDAP config file
-
-sub generateLdapConf {
- my $userInput = shift;
- my $fileName = shift;
-
- my $useLdap = $userInput->{$fileName}[0]->{"Do you want to set up LDAP?"};
-
- if ( !lc $useLdap =~ /^y(?:es)?/ ) {
- logger( "Not setting up ldap", "info" );
- return;
- }
-
- my %ldapConf = getConfig( $userInput, $fileName );
-
- make_path( dirname($fileName), { mode => 0755 } );
- writeJson( $fileName, \%ldapConf );
-}
-
-sub generateUsersConf {
- my $userInput = shift;
- my $fileName = shift;
-
- my %user = ();
- my %config = getConfig( $userInput, $fileName );
-
- $user{username} = $config{tmAdminUser};
- $user{password} = sha1_hex( $config{tmAdminPw} );
-
- writeJson( $fileName, \%user );
- $user{password} = $config{tmAdminPw};
- return \%user;
-}
-
-sub generateProfilesDir {
- my $userInput = shift;
- my $fileName = shift;
-
- my $userIn = $userInput->{$fileName};
-}
-
-sub generateOpenSSLConf {
- my $userInput = shift;
- my $fileName = shift;
-
- 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;
- }
-
- my %config = getConfig( $userInput, $fileName );
-
- writeJson( $fileName, \%config );
- return \%config;
-}
-
-sub generateParamConf {
- my $userInput = shift;
- my $fileName = shift;
-
- my %config = getConfig( $userInput, $fileName );
- writeJson( $fileName, \%config );
- return \%config;
-}
-
-# check default values for missing config_var parameter
-sub sanityCheckDefaults {
- foreach my $file ( ( keys $::defaultInputs ) ) {
- foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
- my $question = getConfigQuestion($defaultValue);
-
- if ( !defined $defaultValue->{"config_var"}
- || $defaultValue->{"config_var"} eq "" )
- {
- errorOut("Question '$question' in file '$file' has no config_var");
- }
- }
- }
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-#
-# Checks the input config file against the default inputs. If there is a question located in the default inputs which
-# is not located in the input config file it will output a warning message.
-
-sub sanityCheckConfig {
- my $userInput = shift;
- my $diffs = 0;
-
- foreach my $file ( ( keys $::defaultInputs ) ) {
- if ( !defined $userInput->{$file} ) {
- logger( "File '$file' found in defaults but not config file", "warn" );
- $userInput->{$file} = [];
- }
-
- foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
-
- my $found = 0;
- foreach my $configValue ( @{ $userInput->{$file} } ) {
- if ( $defaultValue->{"config_var"} eq $configValue->{"config_var"} ) {
- $found = 1;
- }
- }
-
- # if the question is not found in the config file add it from defaults
- if ( !$found ) {
- 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) {
- $answer = $defaultValue->{$question};
- logger( "Adding question '$question' with default answer " . ( $hidden ? "" : "'$answer'" ), "info" );
- }
-
- # in interactive mode prompt the user for answer to missing question
- else {
- logger( "Prompting user for answer", "info" );
- if ($hidden) {
- $answer = promptPasswordVerify($question);
- }
- else {
- $answer = promptUser( $question, $defaultValue->{$question} );
- }
- }
-
- %temp = (
- "config_var" => $defaultValue->{"config_var"},
- $question => $answer
- );
-
- if ($hidden) {
- $temp{"hidden"} .= "true";
- }
-
- push $userInput->{$file}, \%temp;
-
- $diffs++;
- }
- }
- }
-
- 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
-# user input config file or if there are questions in the input config file which do not have answers
-
-sub getDefaults {
- return {
- $::databaseConfFile => [
- {
- "Database type" => "mysql",
- "config_var" => "type"
- },
- {
- "Database name" => "traffic_ops",
- "config_var" => "dbname"
- },
- {
- "Database server hostname IP or FQDN" => "localhost",
- "config_var" => "hostname"
- },
- {
- "Database port number" => "3306",
- "config_var" => "port"
- },
- {
- "Traffic Ops database user" => "traffic_ops",
- "config_var" => "user"
- },
- {
- "Password for Traffic Ops database user" => "",
- "config_var" => "password",
- "hidden" => "true"
- }
- ],
- $::dbConfFile => [
- {
- "Database server root (admin) user" => "root",
- "config_var" => "dbAdminUser"
- },
- {
- "Password for database server admin" => "",
- "config_var" => "dbAdminPw",
- "hidden" => "true"
- }
- ],
- $::cdnConfFile => [
- {
- "Generate a new secret?" => "yes",
- "config_var" => "genSecret"
- },
- {
- "Number of secrets to keep?" => "10",
- "config_var" => "keepSecrets"
- }
- ],
- $::ldapConfFile => [
- {
- "Do you want to set up LDAP?" => "no",
- "config_var" => "setupLdap"
- },
- {
- "LDAP server hostname" => "",
- "config_var" => "hostname"
- },
- {
- "LDAP Admin DN" => "",
- "config_var" => "admin_dn"
- },
- {
- "LDAP Admin Password" => "",
- "config_var" => "password",
- "hidden" => "true"
- },
- {
- "LDAP Search Base" => "",
- "config_var" => "search_base"
- }
- ],
- $::usersConfFile => [
- {
- "Administration username for Traffic Ops" => "admin",
- "config_var" => "tmAdminUser"
- },
- {
- "Password for the admin user" => "",
- "config_var" => "tmAdminPw",
- "hidden" => "true"
- }
- ],
- $::profilesConfFile => [],
- $::opensslConfFile => [
- {
- "Do you want to generate a certificate?" => "yes",
- "config_var" => "genCert"
- },
- {
- "Country Name (2 letter code)" => "XX",
- "config_var" => "country"
- },
- {
- "State or Province Name (full name)" => "San Jose",
- "config_var" => "state"
- },
- {
- "Locality Name (eg, city)" => "Default City",
- "config_var" => "locality"
- },
- {
- "Organization Name (eg, company)" => "Default Company Ltd",
- "config_var" => "company"
- },
- {
- "Organizational Unit Name (eg, section)" => "",
- "config_var" => "org_unit"
- },
- {
- "Common Name (eg, your name or your server's hostname)" => "example.com",
- "config_var" => "common_name"
- },
- {
- "RSA Passphrase" => "",
- "config_var" => "rsaPassword",
- "hidden" => "true"
- }
- ],
- $::paramConfFile => [
- {
- "Traffic Ops url" => "https://localhost",
- "config_var" => "tm.url"
- },
- {
- "Human-readable CDN Name. (No whitespace, please)" => "kabletown_cdn",
- "config_var" => "cdn_name"
- },
- {
- "Health Polling Interval (milliseconds)" => "8000",
- "config_var" => "health_polling_int"
- },
- {
- "DNS sub-domain for which your CDN is authoritative" => "cdn1.kabletown.net",
- "config_var" => "dns_subdomain"
- },
- {
- "TLD SOA admin" => "traffic_ops",
- "config_var" => "soa_admin"
- },
- {
- "TrafficServer Drive Prefix" => "/dev/sd",
- "config_var" => "driver_prefix"
- },
- {
- "TrafficServer RAM Drive Prefix" => "/dev/ram",
- "config_var" => "ram_drive_prefix"
- },
- {
- "TrafficServer RAM Drive Letters (comma separated)" => "0,1,2,3,4,5,6,7",
- "config_var" => "ram_drive_letters"
- },
- {
- "Health Threshold Load Average" => "25",
- "config_var" => "health_thresh_load_avg"
- },
- {
- "Health Threshold Available Bandwidth in Kbps" => "1750000",
- "config_var" => "health_thresh_kbps"
- },
- {
- "Traffic Server Health Connection Timeout (milliseconds)" => "2000",
- "config_var" => "health_connect_timeout"
- }
-
- ]
- };
-}
-
-# 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;
- my $genCert = shift;
-
- #
- # Call mysql initialization script.
- #
- logger( "Creating database with user: $todbconf->{dbAdminUser}", "info" );
- my $result = execCommand( "/opt/traffic_ops/install/bin/create_db", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
- if ( $result != 0 ) {
- errorOut("Failed to create the database");
- }
-
- logger( "Setting up database", "info" );
- chdir("/opt/traffic_ops/app");
- $result = execCommand( "/usr/bin/perl", "db/admin.pl", "--env=production", "setup" );
-
- if ( $result != 0 ) {
- errorOut("Database initialization failed");
- }
- else {
- logger( "Database initialization succeeded", "info" );
- }
-
- $result = execCommand( "/opt/traffic_ops/install/bin/dataload", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
- if ( $result != 0 ) {
- logger( "Failed to load seed data", "error" );
- }
-
- 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");
- if ( $result != 0 ) {
- logger( "Failed to download MaxMind data", "error" );
- }
-
- logger( "Copying coverage zone file to public dir", "info" );
- $result = execCommand("/bin/mv /opt/traffic_ops/app/public/coverage-zone.json .");
- if ( $result != 0 ) {
- logger( "Failed to copy coverage zone file", "error" );
- }
-
- if ( lc $genCert =~ /^y(?:es)?/ ) {
- if ( -x "/usr/bin/openssl" ) {
- logger( "Installing SSL Certificates", "info" );
- $result = GenerateCert::createCert($opensslconf);
-
- if ( $result != 0 ) {
- errorOut("SSL Certificate Installation failed");
- }
- else {
- logger( "SSL Certificates have been installed", "info" );
- }
- }
- else {
- logger( "Unable to install SSL certificates as openssl is not installed", "error" );
- logger( "Install openssl and then run /opt/traffic_ops/install/bin/generateCert to install SSL certificates", "error" );
- exit 4;
- }
- }
- else {
- logger("Not generating openssl certification", "info");
- }
-}
-
-# -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 = "";
- our $automatic = 0;
- our $debug = 0;
- my $help = 0;
-
- my $usageString = "Usage: postinstall [-a] [-debug] [-defaults] [-r] -cfile=[config_file]\n";
-
- GetOptions(
- "cfile=s" => \$inputFile,
- "automatic" => \$automatic,
- "reconfigure" => \$reconfigure,
- "defaults" => \$dumpDefaults,
- "debug" => \$debug,
- "help" => \$help
- ) or die($usageString);
-
- # stores the default questions and answers
- our $defaultInputs = getDefaults();
-
- if ($help) {
- print $usageString;
- 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" );
-
- 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" );
- return;
- }
-
- if ($dumpDefaults) {
- logger( "Writing default configuration file to $outputConfigFile", "info" );
- writeJson( $outputConfigFile, $::defaultInputs );
- return;
- }
-
- logger( "Postinstall " . ( defined $reconfigure ? "in" : "not" ) . " in reconfigure mode", "info" );
-
- rotateLog($cpanLogFile);
-
- if ( -s $::logFile > $maxLogSize ) {
- logger( "Postinstall log above max size of $maxLogSize bytes - rotating", "info" );
- rotateLog($logFile);
- }
-
- # used to store the questions and answers provided by the user
- my $userInput;
-
- # if no input file provided use the defaults
- if ( $::inputFile eq "" ) {
- logger( "No input file given - using defaults", "info" );
- $userInput = $::defaultInputs;
- }
- else {
- logger( "Using input file $::inputFile", "info" );
-
- # check if the input file exists
- errorOut("File '$::inputFile' not found") if ( !-f $::inputFile );
-
- # read and store the input file
- $userInput = readJson($::inputFile);
- }
-
- # sanity check the defaults if running them automatically
- sanityCheckDefaults();
-
- # check the input config file against the defaults to check for missing questions
- sanityCheckConfig($userInput) if ( $inputFile ne "" );
-
- chdir("/opt/traffic_ops/install/bin");
-
- # if the reconfigure file exists or reconfigure is set then rebuild the perl deps
- 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");
- }
- $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");
- }
- }
- 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");
- }
- $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");
- }
- }
-
- # The generator functions handle checking input/default/automatic mode
-
- # todbconf will be used later when setting up the database
- my $todbconf = generateDbConf( $userInput, $::databaseConfFile, $::dbConfFile );
- generateCdnConf( $userInput, $::cdnConfFile );
- generateLdapConf( $userInput, $::ldapConfFile );
- my $adminconf = generateUsersConf( $userInput, $::usersConfFile );
- generateProfilesDir( $userInput, $::profilesConfFile );
- my $opensslconf = generateOpenSSLConf( $userInput, $::opensslConfFile );
- my $paramconf = generateParamConf( $userInput, $::paramConfFile );
-
- # if the reconfigure file exists or the reconfigure command line arg is set then setup the database
- if ( -f $reconfigure_file || $reconfigure ) {
- if ($::automatic) {
- setupDatabase( $todbconf, $::opensslConfFile, $opensslconf->{genCert} );
- }
- else {
- setupDatabase( $todbconf, 0, $opensslconf->{genCert} );
- }
- }
-
- # remove the reconfigure file if it exists
- if ( -f $reconfigure_file ) {
- logger( "Removing reconfigure file", "info" );
- unlink($reconfigure_file);
- }
-
- logger( "Starting Traffic Ops", "info" );
- execCommand("/sbin/service traffic_ops start");
-
- logger( "Waiting for Traffic Ops to start", "info" );
-
- if ( !profiles_exist( $adminconf, $paramconf->{"tm.url"} ) ) {
- logger( "Creating default profiles...", "info" );
- replace_profile_templates($paramconf);
- import_profiles($adminconf);
- profiles_exist( $adminconf, $paramconf->{"tm.url"} ); # call again to create $reconfigure_defaults file if import was successful
- }
- else {
- logger( "Not creating default profiles", "info" );
- }
-
- logger("Postinstall complete");
-
- execCommand( "/bin/gzip", "$logFile" );
-}
-
-main;
-
-# vi:syntax=perl
[04/36] incubator-trafficcontrol git commit: -Removed reconfigure
line -Removed trailing spaces in input.json -Renamed postinstall-new to
postinstall for easier diff
Posted by da...@apache.org.
-Removed reconfigure line
-Removed trailing spaces in input.json
-Renamed postinstall-new to postinstall for easier diff
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/64f49e3f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/64f49e3f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/64f49e3f
Branch: refs/heads/master
Commit: 64f49e3f747d6d5d40926a5f4fcec9902fa70140
Parents: ed58286
Author: peryder <pe...@cisco.com>
Authored: Mon Jan 9 09:24:43 2017 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/build/traffic_ops.spec | 1 -
traffic_ops/install/bin/input.json | 142 +--
traffic_ops/install/bin/postinstall | 1385 ++++++++++++++------------
traffic_ops/install/bin/postinstall-new | 781 ---------------
4 files changed, 747 insertions(+), 1562 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/64f49e3f/traffic_ops/build/traffic_ops.spec
----------------------------------------------------------------------
diff --git a/traffic_ops/build/traffic_ops.spec b/traffic_ops/build/traffic_ops.spec
index 4483aa2..35cc608 100644
--- a/traffic_ops/build/traffic_ops.spec
+++ b/traffic_ops/build/traffic_ops.spec
@@ -109,7 +109,6 @@ Built: %(date) by %{getenv: USER}
# install
if [ "$1" = "1" ]; then
# see postinstall, the .reconfigure file triggers init().
- #/bin/touch %{PACKAGEDIR}/.reconfigure
echo -e "\nRun /opt/traffic_ops/install/bin/postinstall from the root home directory to complete the install.\n"
fi
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/64f49e3f/traffic_ops/install/bin/input.json
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/input.json b/traffic_ops/install/bin/input.json
index 76720f6..b1adce2 100644
--- a/traffic_ops/install/bin/input.json
+++ b/traffic_ops/install/bin/input.json
@@ -1,169 +1,71 @@
-{
- "/opt/traffic_ops/app/conf/production/database.conf":[
- {
+{
+ "/opt/traffic_ops/app/conf/production/database.conf":[
+ {
"Database type":"mysql",
"config_var":"type"
},
- {
+ {
"Database name":"traffic_ops_db",
"config_var":"dbname"
},
- {
+ {
"Database server hostname IP or FQDN":"localhost",
"config_var":"hostname"
},
- {
+ {
"Database port number":"3306",
"config_var":"port"
},
- {
+ {
"Traffic Ops database user":"traffic_ops",
"config_var":"user"
},
- {
+ {
"Traffic Ops database password":"default",
"config_var":"password",
"hidden":"1"
}
],
- "/opt/traffic_ops/app/db/dbconf.yml":[
- {
+ "/opt/traffic_ops/app/db/dbconf.yml":[
+ {
"Database server root (admin) username":"root",
"config_var":"dbAdminUser"
},
- {
+ {
"Database server admin password":"default",
"config_var":"dbAdminPw",
"hidden":"1"
}
],
- "/opt/traffic_ops/app/conf/cdn.conf":[
- {
+ "/opt/traffic_ops/app/conf/cdn.conf":[
+ {
"Generate a new secret?":"yes",
"config_var":"genSecret"
},
- {
+ {
"Number of secrets to keep?":"10",
"config_var":"keepSecrets"
}
],
- "/opt/traffic_ops/app/conf/ldap.conf":[
- {
+ "/opt/traffic_ops/app/conf/ldap.conf":[
+ {
"Do you want to set up LDAP?":"no",
"config_var":"setupLdap"
},
- {
+ {
"LDAP server hostname":"",
"config_var":"hostname"
},
- {
+ {
"LDAP Admin DN":"",
"config_var":"admin_dn"
},
- {
+ {
"LDAP Admin Password":"",
"config_var":"password",
"hidden":"1"
},
- {
+ {
"LDAP Search Base":"",
- "config_var":"search_base"
- }
- ],
- "/opt/traffic_ops/install/data/json/users.json":[
- {
- "Administration username for Traffic Ops":"root",
- "config_var":"tmAdminUser"
- },
- {
- "Password for the admin user":"default",
- "config_var":"tmAdminPw",
- "hidden":"1"
- }
- ],
- "/opt/traffic_ops/install/data/profiles/":[
-
- ],
- "/opt/traffic_ops/install/data/json/openssl_configuration.json":[
- {
- "Do you want to generate a certificate?":"yes",
- "config_var":"genCert"
- },
- {
- "Country Name (2 letter code)":"XX",
- "config_var":"country"
- },
- {
- "State or Province Name (full name)":"Default State",
- "config_var":"state"
- },
- {
- "Locality Name (eg, city)":"Default City",
- "config_var":"locality"
- },
- {
- "Organization Name (eg, company)":"Default Company Ltd",
- "config_var":"company"
- },
- {
- "Organizational Unit Name (eg, section)":"",
- "config_var":"org_unit"
- },
- {
- "Common Name (eg, your name or your server's hostname)":"example.com",
- "config_var":"common_name"
- },
- {
- "RSA Passphrase":"password",
- "config_var":"rsaPassword",
- "hidden":"1"
- }
- ],
- "/opt/traffic_ops/install/data/json/profiles.json":[
- {
- "Traffic Ops url":"https://localhost",
- "config_var":"tm.url"
- },
- {
- "Human-readable CDN Name. (No whitespace, please)":"kabletown_cdn",
- "config_var":"cdn_name"
- },
- {
- "Health Polling Interval (milliseconds)":"8000",
- "config_var":"health_polling_int"
- },
- {
- "DNS sub-domain for which your CDN is authoritative":"cdn1.kabletown.net",
- "config_var":"dns_subdomain"
- },
- {
- "TLD SOA admin":"traffic_ops",
- "config_var":"soa_admin"
- },
- {
- "TrafficServer Drive Prefix":"/dev/sd",
- "config_var":"driver_prefix"
- },
- {
- "TrafficServer RAM Drive Prefix":"/dev/ram",
- "config_var":"ram_drive_prefix"
- },
- {
- "TrafficServer RAM Drive Letters (comma separated)":"0,1,2,3,4,5,6,7",
- "config_var":"ram_drive_letters"
- },
- {
- "Health Threshold Load Average":"25",
- "config_var":"health_thresh_load_avg"
- },
- {
- "Health Threshold Available Bandwidth in Kbps":">1750000",
- "config_var":"health_thresh_kbps"
- },
- {
- "Traffic Server Health Connection Timeout (milliseconds)":"2000",
- "config_var":"health_connect_timeout"
- }
- ]
-}
-
+ "input.json" 169 L,
+ 4044 C
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/64f49e3f/traffic_ops/install/bin/postinstall
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall b/traffic_ops/install/bin/postinstall
index 6a747da..1092338 100755
--- a/traffic_ops/install/bin/postinstall
+++ b/traffic_ops/install/bin/postinstall
@@ -1,7 +1,6 @@
#!/usr/bin/perl
#
-#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@@ -15,702 +14,768 @@
# limitations under the License.
#
-use strict;
-use warnings;
-
use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
$ENV{PERL5LIB} = "/opt/traffic_ops/install/lib:/opt/traffic_ops/install/lib/perl5:/opt/traffic_ops/app/local/lib/perl5:/opt/traffic_ops/app/lib";
-use DBI;
-use JSON;
+use strict;
+use warnings;
+
+use Safe;
+use POSIX;
+use File::Basename qw{dirname};
+use File::Path qw{make_path};
use InstallUtils qw{ :all };
+use BuildPerlDeps qw{ :all };
+use GenerateCert qw{ :all };
+use ProfileCleanup qw { :all };
use Digest::SHA1 qw(sha1_hex);
-use Data::Dumper;
-use File::Temp;
-use WWW::Curl::Easy;
-use LWP::UserAgent;
-use File::Copy;
-
-my $database_conf = "/opt/traffic_ops/app/conf/production/database.conf";
-my $ldap_conf = "/opt/traffic_ops/app/conf/ldap.conf";
-my $cdn_conf = "/opt/traffic_ops/app/conf/cdn.conf";
-my $migrations_dbconf = "/opt/traffic_ops/app/db/dbconf.yml";
-my $post_install_cfg = "/opt/traffic_ops/install/data/json/post_install.json";
-my $users_file = "/opt/traffic_ops/install/data/json/users.json";
-my $profile_dir = "/opt/traffic_ops/install/data/profiles/";
-my %dbdriver = ( mysql => "mymysql", );
-
-my $reconfigure = "/opt/traffic_ops/.reconfigure";
-my $reconfigure_defaults = "/opt/traffic_ops/.reconfigure_defaults";
-my $tmAdminUser = "";
-my $tmAdminPw = "";
-my $parameters;
-
-my $installMsg = << 'EOF';
-
-This script will initialize the Traffic Ops database.
-Please enter the following information in order to completely
-configure the Traffic Ops mysql database.
-
-EOF
-
-sub readJson {
- my $file = shift;
- open( my $fh, '<', $file ) or return;
- local $/; # slurp mode
- my $text = <$fh>;
- undef $fh;
- return JSON->new->utf8->decode($text);
+use Data::Dumper qw(Dumper);
+use Scalar::Util qw(looks_like_number);
+use Getopt::Long;
+
+# paths of the output configuration files
+our $databaseConfFile = "/opt/traffic_ops/app/conf/production/database.conf";
+our $dbConfFile = "/opt/traffic_ops/app/db/dbconf.yml";
+our $cdnConfFile = "/opt/traffic_ops/app/conf/cdn.conf";
+our $ldapConfFile = "/opt/traffic_ops/app/conf/ldap.conf";
+our $usersConfFile = "/opt/traffic_ops/install/data/json/users.json";
+our $profilesConfFile = "/opt/traffic_ops/install/data/profiles/";
+our $opensslConfFile = "/opt/traffic_ops/install/data/json/openssl_configuration.json";
+our $paramConfFile = "/opt/traffic_ops/install/data/json/profiles.json";
+
+our $profile_dir = "/opt/traffic_ops/install/data/profiles/";
+our $post_install_cfg = "/opt/traffic_ops/install/data/json/post_install.json";
+
+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
+our $logFile = "/var/log/traffic_ops/postinstall.log";
+
+# maximum size the uncompressed log file should be before rotating it - rotating it copies the current log
+# file to the same name appended with .bkp replacing the old backup if any is there
+my $maxLogSize = 1000000; #bytes
+
+# log file for cpan - this log becomes large and is rotated every install
+our $cpanLogFile = "/var/log/traffic_ops/cpan.log";
+
+# configuration file output with answers which can be used as input to postinstall
+our $outputConfigFile = "/var/log/traffic_ops/configuration_file.json";
+
+sub getDbDriver {
+ return "mymysql";
}
-sub writeJson {
- my $file = shift;
- open( my $fh, '>', $file ) or die("open(): $!");
- foreach my $data (@_) {
- my $json_text = JSON->new->utf8->encode($data);
- print $fh $json_text, "\n";
- }
- close $fh;
+sub getInstallPath {
+ my $relPath = shift;
+ return join( '/', "/tmp/traffic_ops", $relPath );
}
-sub writeYamlToFH {
- my $fh = shift;
- my $data = shift;
- my $level = shift || 0;
- my $prefix = shift || '';
-
- my $type = ref($data);
- my $indent = ' ' x $level;
- if ( $type eq '' ) {
-
- # scalar
- print $fh "$indent$prefix$data\n";
- }
- elsif ( $type eq 'HASH' ) {
- foreach my $key ( keys %$data ) {
- my $value = $data->{$key};
- if ( ref($value) eq '' ) {
- print $fh "$indent$key: $value\n";
- }
- else {
- print $fh "$indent$key:\n";
- writeYamlToFH( $fh, $data->{$key}, $level + 1 );
- }
- }
- }
- elsif ( $type eq 'ARRAY' ) {
- foreach my $d (@$data) {
- writeYamlToFH( $fh, $d, $level + 1, '- ' );
- }
- }
+# given a var to the hash of config_var and question, will return the question
+sub getConfigQuestion {
+ my $var = shift;
+ foreach my $key ( keys $var ) {
+ if ( $key ne "hidden" && $key ne "config_var" ) {
+ return $key;
+ }
+ }
}
-sub writeYaml {
- my $file = shift;
- my $data = shift;
- open my $fh, '>', $file or die "open(): $!";
- writeYamlToFH( $fh, $data );
+# 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
+
+sub getField {
+ my $question = shift;
+ my $config_answer = shift;
+ my $hidden = shift;
+
+ # 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);
+ }
+ else {
+ return promptUser( $question, $config_answer );
+ }
+ }
+
+ return $config_answer;
}
-# Init.
-sub init () {
- my $c = readJson($database_conf);
- my %dbconf = %$c;
- my $dbAdminUser;
- my $dbAdminPw;
-
- # loop exits on successful db connect
- while (1) {
- execCommand( "/usr/bin/tput", "clear" );
-
- if ($DBI::errstr) {
- print "Error connecting to database using the supplied information: $DBI::errstr\n";
- }
-
- print "\n$installMsg\n";
-
- $dbconf{type} = promptUser( "Database type", $dbconf{type} || "mysql" );
- $dbconf{dbname} = promptUser( "Database name", $dbconf{dbname} || "traffic_ops_db" );
- $dbconf{hostname} = promptUser( "Database server hostname IP or FQDN", $dbconf{hostname} || "localhost" );
- $dbconf{port} = promptUser( "Database port number", $dbconf{port} || "3306" );
- $dbconf{user} = promptUser( "Traffic Ops database user", $dbconf{user} || "traffic_ops" );
- $dbconf{password} = promptPasswordVerify("Password for $dbconf{user}");
- $dbconf{description} = "$dbconf{type} database on $dbconf{hostname}:$dbconf{port}";
- print "\n";
- $dbAdminUser = promptUser( "Database server root (admin) user name", "root" );
- $dbAdminPw = promptPassword("Database server $dbAdminUser password");
-
- print "Database Type: $dbconf{type}\n";
- print "Database Name: $dbconf{dbname}\n";
- print "Hostname: $dbconf{hostname}\n";
- print "Port: $dbconf{port}\n";
- print "Database User: $dbconf{user}\n";
- my $ans = promptUser( "Is the above information correct (y/n)", "n" );
-
- if ( $ans eq "y" ) {
- my $dsn = sprintf( "DBI:mysql:%s:%s:%s", "mysql", $dbconf{hostname}, $dbconf{port} );
- my $dbh = DBI->connect( $dsn, $dbAdminUser, $dbAdminPw );
- if ($dbh) {
-
- # Success!
- $dbh->disconnect();
- last;
- }
- }
- }
-
- writeJson( $database_conf, \%dbconf );
- print "\nThe database properties have been saved to $database_conf\n";
-
- # migrations dbconf is in YAML
- my $driver = $dbdriver{ $dbconf{type} };
- my %migrations = ( production => { driver => $driver, open => "tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{user}/$dbconf{password}" } );
- writeYaml( $migrations_dbconf, \%migrations );
-
- my $msg = << 'EOF';
-
- The database configuration has been saved. Now we need to set some custom
- fields that are necessary for the CDN to function correctly.
-
-EOF
-
- print $msg, "\n";
- while (1) {
-
- my $tmurl = promptUser( "Traffic Ops url", $parameters->{"tm.url"} || "https://localhost" );
- $parameters->{"tm.url"} = $tmurl;
- $parameters->{"tm.infourl"} = "$tmurl/info";
-
- $parameters->{cdnname} = promptUser( "Human-readable CDN Name. (No whitespace, please)", $parameters->{cdnname} || "kabletown_cdn" );
- $parameters->{domainname} = promptUser( "DNS sub-domain for which your CDN is authoritative", $parameters->{domainname} || "cdn1.kabletown.net" );
-
- my $geolocationUrl = "$tmurl/routing/GeoIP2-City.mmdb.gz";
- $parameters->{"geolocation.polling.url"} = $geolocationUrl;
-
- my $coverageZoneUrl = "$tmurl/routing/coverage-zone.json";
- $parameters->{"coveragezone.polling.url"} = $coverageZoneUrl;
-
- my $centosTarballFqn = '';
- my $skip;
- while (1) {
- $centosTarballFqn = promptUser( "Fully qualified name of your CentOS ISO kickstart tarball, or 'na' to skip and add files later",
- "/var/cache/centos72.tgz" );
- if ( $centosTarballFqn eq 'na' ) {
- $skip = 1;
- last;
- }
- if ( -f $centosTarballFqn ) {
- last;
- }
- print "\nNo file named $centosTarballFqn found.\n\n";
- }
-
- my $kickstartFilesFqn = promptUser( "Fully qualified location to store your ISO kickstart files", "/var/www/files" );
- my $parametersJson = "/opt/traffic_ops/install/data/json/parameter.json";
-
- ## Replace parameter with $kickstartFilesFqn
- open( my $json_fh, "<:encoding(UTF-8)", $parametersJson )
- or die("Can't open \$filename\": $!\n");
-
- my $json = JSON->new;
- my @json_obj;
- while ( my $json_text = <$json_fh> ) {
- my $data = $json->decode($json_text);
-
- if ( $data->{"name"} eq "kickstart.files.location" ) {
- $data->{"value"} = $kickstartFilesFqn;
- }
- push @json_obj, $data;
- }
- writeJson( $parametersJson, @json_obj );
-
- execCommand( "/bin/cp", "/opt/traffic_ops/install/data/perl/osversions.cfg", $kickstartFilesFqn );
-
- if ( !$skip ) {
- print "\nUncompressing CentOS ISO kickstart tarball.\n";
- print "\nFirst creating $kickstartFilesFqn.\n";
- execCommand( "/bin/mkdir", "-p", $kickstartFilesFqn );
- print "\nUncompressing $centosTarballFqn.\n";
- execCommand( "/bin/tar", "-xzf", $centosTarballFqn, "-C", $kickstartFilesFqn );
- }
-
- print "\nTraffic Ops URL: $parameters->{'tm.url'}\n";
- print "Traffic Ops Info URL: $parameters->{'tm.infourl'}\n";
- print "Domainname: $parameters->{domainname}\n";
- print "CDN Name: $parameters->{cdnname}\n";
- print "GeoLocation Polling URL: $parameters->{'geolocation.polling.url'}\n";
- print "CoverageZone Polling URL: $parameters->{'coveragezone.polling.url'}\n\n";
- my $ans = promptUser( "Is the above information correct (y/n)", "n" );
- if ( $ans eq 'y' ) {
- last;
- }
- }
- writeJson( $post_install_cfg, $parameters );
- print "Install information has been saved to $post_install_cfg\n\n";
-
- print "\nAdding an administration user to the Traffic Ops database.\n\n";
- my %user = ();
- $tmAdminUser = promptUser( "Administration username for Traffic Ops", 'admin' );
- $user{username} = $tmAdminUser;
- $tmAdminPw = promptPasswordVerify("Password for the admin user $tmAdminUser");
- $user{password} = sha1_hex($tmAdminPw);
-
- writeJson( $users_file, \%user );
-
- my $ans = promptUser( "Do you wish to create an ldap configuration for access to traffic ops [y/n] ?", "n" );
- if ( $ans eq "y" ) {
- my %ldapconf = readJson($ldap_conf);
- while (1) {
- $ldapconf{host} = promptUser( "LDAP server hostname", $ldapconf{host} || "ldap.foobar.com" );
- $ldapconf{admin_dn} = promptUser( "LDAP Admin DN", $ldapconf{admin_dn} || 'admin@foobar.com' );
- $ldapconf{admin_pass} = promptPasswordVerify("LDAP Admin Password");
- $ldapconf{search_base} = promptUser( "LDAP Search Base", "dc=foobar,dc=com" );
- my $correct = promptUser( "Are the above values correct [y/n]?", "y" );
- if ( $correct eq 'y' ) {
- last;
- }
- }
- writeJson( $ldap_conf, \%ldapconf );
- print "The ldap configuration has been saved.\n\n";
- }
-
- # Prompt for new secret
- writeSecret($cdn_conf);
-
- #
- # Call mysql initialization script.
- #
- print "Creating database\n";
- my $result = execCommand( "/opt/traffic_ops/install/bin/create_db", $dbAdminUser, $dbAdminPw );
- if ( $result != 0 ) {
- print "failed to create the database.\n";
- exit 1;
- }
-
- print "Setting up database\n";
- chdir("/opt/traffic_ops/app");
- $result = execCommand( "/usr/bin/perl", "db/admin.pl", "--env=production", "setup" );
-
- if ( $result != 0 ) {
- print "Database initialization failed.\n";
- exit 2;
- }
- else {
- print "Database initialization succeeded.\n";
- }
-
- $result = execCommand( "/opt/traffic_ops/install/bin/dataload", $dbAdminUser, $dbAdminPw );
- if ( $result != 0 ) {
- print "failed to load seed data.\n";
- exit 1;
- }
-
- print "Downloading MaxMind data.\n";
- chdir("/opt/traffic_ops/app/public/routing");
- $result = execCommand("/usr/bin/wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz");
- if ( $result != 0 ) {
- print "failed to download MaxMind data.\n";
-
- # exit 1;
- }
-
- print "Copying coverage zone file to public dir.\n";
- $result = execCommand("/bin/mv /opt/traffic_ops/app/public/coverage-zone.json .");
- if ( $result != 0 ) {
- print "failed to copy coverage zone file.\n";
-
- # exit 1;
- }
-
- if ( -x "/usr/bin/openssl" ) {
- print "\nInstalling SSL Certificates.\n\n";
- $result = execCommand("/opt/traffic_ops/install/bin/generateCert");
-
- if ( $result != 0 ) {
- print "\nSSL Certificate Installation failed.\n";
- exit 3;
- }
- else {
- print "\nSSL Certificates have been installed.\n";
- }
- }
- else {
- print "Unable to install SSL certificates as openssl is not installed.\n";
- print "Install openssl and then run /opt/traffic_ops/install/bin/generateCert to install SSL certificates.\n";
- exit 4;
- }
-} # end of Init
-
-sub writeSecret {
- print "\n\nTraffic Ops requires a secret key to generate authentication cookies.\n\n";
-
- # read conf file -- see if secrets already there
- my $cdnh = do $cdn_conf;
- unless ( ref($cdnh) eq 'HASH' ) {
- my $err = $@ || $! || ' -- not a HASH';
- if ($err) {
- print "Could not load $cdn_conf $err";
- exit 4;
- }
- }
-
- # newSecret
- my $secrets = $cdnh->{secrets};
- if ( ( ref $secrets eq 'ARRAY' ) && scalar @$secrets > 0 ) {
- print "One or more secrets found in $cdn_conf.\n";
- my $ans = promptUser( " Do want to add a new one (only 2 will be kept) [y/n] ?", "y" );
- if ( $ans eq "n" ) {
-
- # nothing further to do...
- return;
- }
- }
- my $new_secret = "";
- while ( length $new_secret == 0 ) {
- print "Adding a new secret.\n";
- my $ans = promptUser( " Do you want one generated for you [y/n] ?", "y" );
- if ( $ans eq "n" ) {
- $new_secret = promptUser( "Secret key:", "" );
- }
- else {
-
- # create random word 12 chars long
- $new_secret = randomWord(12);
- }
- }
-
- # keep 2 at most..
- unshift( @$secrets, $new_secret );
- if ( scalar @$secrets > 2 ) {
- $#{$secrets} = 1;
- }
-
- # dump conf data in compact but readable form
- my $dumper = Data::Dumper->new( [$cdnh] );
- $dumper->Indent(1)->Terse(1)->Quotekeys(0);
-
- # write whole config to temp file in pwd (keeps in same filesystem)
- my $tmpfile = File::Temp->new(DIR => '.');
- print $tmpfile $dumper->Dump();
- close $tmpfile;
-
- # rename current config file to something unique so it's not lost
- my $backup_num = 0;
- my $backup_name;
- do {
- $backup_num++;
- $backup_name = "$cdn_conf.backup$backup_num";
- } while ( -e $backup_name );
- rename( $cdn_conf, $backup_name ) or die("rename(): $!");
-
- # rename temp file to cdn.conf and set ownership/permissions same as backup
- my @stats = stat($backup_name);
- my ( $uid, $gid, $perm ) = @stats[ 4, 5, 2 ];
- rename( $tmpfile, $cdn_conf ) or die("rename(): $!");
-
- chown $uid, $gid, $cdn_conf;
- chmod $perm, $cdn_conf;
+# userInput: The entire input config file which is either user input or the defaults
+# fileName: The name of the output config file given by the input config file
+#
+# Loops through an input config file and determines answers to each question using getField
+# and returns the hash of answers
+
+sub getConfig {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %config;
+
+ if ( !defined $userInput->{$fileName} ) {
+ logger( "No $fileName found in config", "error" );
+ }
+
+ 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 );
+
+ $config{ $var->{"config_var"} } = $answer;
+ if ( !$hidden ) {
+ logger( "$question: $answer", "info" );
+ }
+ }
+ return %config;
}
-chdir("/opt/traffic_ops/install/bin");
-
-$parameters = readJson($post_install_cfg);
-if ( -f $reconfigure ) {
- my $rc = execCommand( "/opt/traffic_ops/install/bin/build_trafficops_perl_library", "-i" );
- if ( $rc != 0 ) {
- print "ERROR: failed to install perl dependencies, check the console output and rerun postinstall once you've resolved the error.\n";
- exit 5;
- }
- $rc = execCommand( "./download_web_deps", "-i" );
- if ( $rc != 0 ) {
- print "ERROR: failed to install Traffic Ops Web dependencies, check the console output and rerun postinstall once you've resolved the error.\n";
- }
- init();
- unlink($reconfigure);
+# userInput: The entire input config file which is either user input or the defaults
+# dbFileName: The filename of the output config file for the database
+# toDBFileName: The filename of the output config file for the Traffic Ops database
+#
+# Generates a config file for the database based on the questions and answers in the input config file
+
+sub generateDbConf {
+ my $userInput = shift;
+ my $dbFileName = shift;
+ my $toDBFileName = shift;
+
+ my %dbconf = getConfig( $userInput, $dbFileName );
+ $dbconf{"description"} = "$dbconf{type} database on $dbconf{hostname}:$dbconf{port}";
+ make_path( dirname($dbFileName), { mode => 0755 } );
+ writeJson( $dbFileName, \%dbconf );
+ logger( "Database configuration has been saved", "info" );
+
+ # broken out into separate file/config area
+ 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!");
+ print $fh "production:\n";
+ print $fh " driver: ", getDbDriver() . "\n";
+ print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{user}/$dbconf{password}\n";
+ close $fh;
+
+ return \%todbconf;
}
-else {
- my $rc = execCommand("/opt/traffic_ops/install/bin/build_trafficops_perl_library");
- if ( $rc != 0 ) {
- print "ERROR: failed to install perl dependencies, check the console output and rerun postinstall once you've resolved the error.\n";
- exit 6;
- }
- $rc = execCommand( "./download_web_deps", "-i" );
- if ( $rc != 0 ) {
- print "ERROR: failed to install Traffic Ops Web dependencies, check the console output and rerun postinstall once you've resolved the error.\n";
- }
+
+# userInput: The entire input config file which is either user input or the defaults
+# fileName: The filename of the output config file
+#
+# Generates a config file for the CDN
+
+sub generateCdnConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %cdnConfiguration = getConfig( $userInput, $fileName );
+
+ # 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: $@");
+ }
+ if ( lc $cdnConfiguration{genSecret} =~ /^y(?:es)?/ ) {
+ my @secrets = @{ $cdnConf->{secrets} };
+ my $newSecret = randomWord();
+ unshift @secrets, randomWord();
+ if ( $cdnConfiguration{keepSecrets} > 0 && $#secrets > $cdnConfiguration{keepSecrets} - 1 ) {
+
+ # Shorten the array to requested length
+ $#secrets = $cdnConfiguration{keepSecrets} - 1;
+ }
+ }
+ writePerl( $fileName, $cdnConf );
}
-sub profile_replace {
- my($profile) = @_;
- my $profile_bak = $profile . ".bak";
- rename($profile, $profile_bak) or die("rename(): $!");
- open(my $fh, '<', $profile_bak) or die("open(): $!");
- open(my $ofh, '>', $profile) or die("open(): $!");
- while (<$fh>) {
- s/{{.TmUrl}}/$parameters->{'tm.url'}/g;
- s/{{.TmInfoUrl}}/$parameters->{"tminfo.url"}/g;
- s/{{.TmInstanceName}}/$parameters->{"cdnname"}/g;
- s/{{.GeolocationPollingUrl}}/$parameters->{"geolocation.polling.url"}/g;
- s/{{.Geolocation6PollingUrl}}/$parameters->{"geolocation6.polling.url"}/g;
- s/{{.TmUrl}}/$parameters->{'tm.url'}/g;
- s/{{.TmToolName}}/Traffic Ops/g;
- s/{{.HealthPollingInterval}}/$parameters->{"health.polling.interval"}/g;
- s/{{.CoveragezonePollingUrl}}/$parameters->{"coveragezone.polling.url"}/g;
- s/{{.DomainName}}/$parameters->{"domainname"}/g;
- s/{{.TldSoaAdmin}}/$parameters->{"tld.soa.admin"}/g;
- s/{{.DrivePrefix}}/$parameters->{"Drive_Prefix"}/g;
- s/{{.HealthThresholdLoadavg}}/$parameters->{"health.threshold.loadavg"}/g;
- s/{{.HealthThresholdAvailableBandwidthInKbps}}/$parameters->{"health.threshold.availableBandwidthInKbps"}/g;
- s/{{.RAMDrivePrefix}}/$parameters->{"RAM_Drive_Prefix"}/g;
- s/{{.RAMDriveLetters}}/$parameters->{"RAM_Drive_Letters"}/g;
- s/{{.HealthConnectionTimeout}}/$parameters->{"health.connection.timeout"}/g;
- s#{{.CronOrtSyncds}}#*/15 * * * * root /opt/ort/traffic_ops_ort.pl syncds warn $parameters->{'tm.url'} $tmAdminUser:$tmAdminPw > /tmp/ort/syncds.log 2>&1#g;
- print $ofh $_;
- }
- close $fh;
- close $ofh;
- unlink $profile_bak;
+# userInput: The entire input config file which is either user input or the defaults
+# fileName: The filename of the output config file
+#
+# Generates an LDAP config file
+
+sub generateLdapConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my $useLdap = $userInput->{$fileName}[0]->{"Do you want to set up LDAP?"};
+
+ if ( !lc $useLdap =~ /^y(?:es)?/ ) {
+ logger( "Not setting up ldap", "info" );
+ return;
+ }
+
+ my %ldapConf = getConfig( $userInput, $fileName );
+
+ make_path( dirname($fileName), { mode => 0755 } );
+ writeJson( $fileName, \%ldapConf );
}
-sub replace_profile_templates() {
- while (!defined $parameters->{'tm.url'} || $parameters->{'tm.url'} eq "") {
- $parameters->{'tm.url'} = InstallUtils::promptUser ("Traffic Ops url", "https://localhost");
- }
- while (!defined $parameters->{"tminfo.url"} || $parameters->{"tminfo.url"} eq "") {
- $parameters->{"tminfo.url"} = "$parameters->{'tm.url'}/info"
- }
- while (!defined $parameters->{"cdnname"} || $parameters->{"cdnname"} eq "") {
- $parameters->{"cdnname"} = InstallUtils::promptUser ("Human-readable CDN Name. (No whitespace, please)", "kabletown_cdn");
- }
- while (!defined $parameters->{"geolocation.polling.url"} || $parameters->{"geolocation.polling.url"} eq "") {
- $parameters->{"geolocation.polling.url"} = "$parameters->{'tm.url'}/routing/GeoIP2-City.mmdb.gz";
- }
- while (!defined $parameters->{"geolocation6.polling.url"} || $parameters->{"geolocation6.polling.url"} eq "") {
- $parameters->{"geolocation6.polling.url"} = "$parameters->{'tm.url'}/routing/GeoIP2-Cityv6.mmdb.gz";
- }
- while (!defined $parameters->{"health.polling.interval"} || $parameters->{"health.polling.interval"} eq "") {
- $parameters->{"health.polling.interval"} = InstallUtils::promptUser ("Health Polling Interval (milliseconds)", "8000");
- }
- while (!defined $parameters->{"coveragezone.polling.url"} || $parameters->{"coveragezone.polling.url"} eq "") {
- $parameters->{"coveragezone.polling.url"} = "$parameters->{'tm.url'}/routing/coverage-zone.json"
- }
- while (!defined $parameters->{"domainname"} || $parameters->{"domainname"} eq "") {
- $parameters->{"domainname"} = InstallUtils::promptUser ("DNS sub-domain for which your CDN is authoritative", "cdn1.kabletown.net");
- }
- while (!defined $parameters->{"tld.soa.admin"} || $parameters->{"tld.soa.admin"} eq "") {
- $parameters->{"tld.soa.admin"} = InstallUtils::promptUser ("TLD SOA admin", "traffic_ops");
- }
- while (!defined $parameters->{"Drive_Prefix"} || $parameters->{"Drive_Prefix"} eq "") {
- $parameters->{"Drive_Prefix"} = InstallUtils::promptUser ("TrafficServer Drive Prefix", "/dev/sd");
- }
- while (!defined $parameters->{"RAM_Drive_Prefix"} || $parameters->{"RAM_Drive_Prefix"} eq "") {
- $parameters->{"RAM_Drive_Prefix"} = InstallUtils::promptUser ("TrafficServer RAM Drive Prefix", "/dev/ram");
- }
- while (!defined $parameters->{"RAM_Drive_Letters"} || $parameters->{"RAM_Drive_Letters"} eq "") {
- $parameters->{"RAM_Drive_Letters"} = InstallUtils::promptUser ("TrafficServer RAM Drive Letters (comma separated)", "0,1,2,3,4,5,6,7");
- }
- while (!defined $parameters->{"health.threshold.loadavg"} || $parameters->{"health.threshold.loadavg"} eq "") {
- $parameters->{"health.threshold.loadavg"} = InstallUtils::promptUser ("Health Threshold Load Average", "25");
- }
- while (!defined $parameters->{"health.threshold.availableBandwidthInKbps"} || $parameters->{"health.threshold.availableBandwidthInKbps"} eq "" || $parameters->{"health.threshold.availableBandwidthInKbps"} eq ">") {
- $parameters->{"health.threshold.availableBandwidthInKbps"} = ">" . InstallUtils::promptUser ("Health Threshold Available Bandwidth in Kbps", "1750000");
- }
- while (!defined $parameters->{"health.connection.timeout"} || $parameters->{"health.connection.timeout"} eq "") {
- $parameters->{"health.connection.timeout"} = InstallUtils::promptUser ("Traffic Server Health Connection Timeout (milliseconds)", "2000");
- }
-
- profile_replace($profile_dir . "profile.global.traffic_ops");
- profile_replace($profile_dir . "profile.traffic_monitor.traffic_ops");
- profile_replace($profile_dir . "profile.traffic_router.traffic_ops");
- profile_replace($profile_dir . "profile.trafficserver_edge.traffic_ops");
- profile_replace($profile_dir . "profile.trafficserver_mid.traffic_ops");
- writeJson( $post_install_cfg, $parameters );
+sub generateUsersConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %user = ();
+ my %config = getConfig( $userInput, $fileName );
+
+ $user{username} = $config{tmAdminUser};
+ $user{password} = sha1_hex( $config{tmAdminPw} );
+
+ writeJson( $fileName, \%user );
+ $user{password} = $config{tmAdminPw};
+ return \%user;
}
-# Takes the Traffic Ops URI, user, and password.
-# Returns the cookie, or the empty string on error
-sub get_traffic_ops_cookie {
- my($uri, $user, $pass) = @_;
-
- my $loginUri = "/api/1.2/user/login";
-
- my $curl = WWW::Curl::Easy->new;
- my $response_body = "";
- open(my $fileb, ">", \$response_body);
- my $loginData = JSON::encode_json({ u => $user, p => $pass});
- $curl->setopt(WWW::Curl::Easy::CURLOPT_URL, $uri . $loginUri);
- $curl->setopt(WWW::Curl::Easy::CURLOPT_SSL_VERIFYPEER, 0);
- $curl->setopt(WWW::Curl::Easy::CURLOPT_HEADER, 1); # include header in response
- $curl->setopt(WWW::Curl::Easy::CURLOPT_NOBODY, 1); # disclude body in response
- $curl->setopt(WWW::Curl::Easy::CURLOPT_POST, 1);
- $curl->setopt(WWW::Curl::Easy::CURLOPT_POSTFIELDS, $loginData);
- $curl->setopt(WWW::Curl::Easy::CURLOPT_WRITEDATA, $fileb); # put response in this var
- $curl->perform();
-
- my $cookie = $response_body;
- if($cookie =~ /mojolicious=(.*); expires/)
- {
- $cookie = $1;
- }
- else
- {
- $cookie = ""
- }
- return $cookie;
+sub generateProfilesDir {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my $userIn = $userInput->{$fileName};
}
-# Takes the filename of a Traffic Ops (TO) profile to import, the TO URI, and the TO login cookie
-sub profile_import_single {
- my($profileFilename, $uri, $trafficOpsCookie) = @_;
- print "Importing Profiles with: " . "curl -v -k -X POST -H \"Cookie: mojolicious=$trafficOpsCookie\" -F \"filename=$profileFilename\" -F \"profile_to_import=\@$profileFilename\" $uri/profile/doI\
-mport";
- my $rc = execCommand("curl -v -k -X POST -H \"Cookie: mojolicious=$trafficOpsCookie\" -F \"filename=$profileFilename\" -F \"profile_to_import=\@$profileFilename\" $uri/profile/doImport");
- if ( $rc != 0 ) {
- print "ERROR: failed to import Traffic Ops profile, check the console output and rerun postinstall once you've resolved the error.\n";
+sub generateOpenSSLConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ 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;
}
+
+ my %config = getConfig( $userInput, $fileName );
+
+ writeJson( $fileName, \%config );
+ return \%config;
}
-sub import_profiles() {
- while (length $tmAdminUser == 0) {
- $tmAdminUser = InstallUtils::promptUser ("Administration username for Traffic Ops");
- }
- while ($tmAdminPw eq "") {
- $tmAdminPw = InstallUtils::promptUser ("Password for the admin user $tmAdminUser", "", 1);
- }
- while (!defined $parameters->{'tm.url'} || length $parameters->{'tm.url'} == 0) {
- $parameters->{'tm.url'} = InstallUtils::promptUser ("Traffic Ops url", "https://localhost");
- }
-
- print "Importing profiles...\n";
- # \todo take as params
- my $toUri = $parameters->{'tm.url'};
- my $toUser = $tmAdminUser;
- my $toPass = $tmAdminPw;
-
- my $toCookie = get_traffic_ops_cookie($toUri, $toUser, $toPass);
-
- print "Got cookie: " . $toCookie;
-
- # \todo use an array?
- print "Importing Global profile...\n";
- profile_import_single($profile_dir . "profile.global.traffic_ops", $toUri, $toCookie);
- print "Importing Traffic Monitor profile...\n";
- profile_import_single($profile_dir . "profile.traffic_monitor.traffic_ops", $toUri, $toCookie);
- print "Importing Traffic Router profile...\n";
- profile_import_single($profile_dir . "profile.traffic_router.traffic_ops", $toUri, $toCookie);
- print "Importing TrafficServer Edge profile...\n";
- profile_import_single($profile_dir . "profile.trafficserver_edge.traffic_ops", $toUri, $toCookie);
- print "Importing TrafficServer Mid profile...\n";
- profile_import_single($profile_dir . "profile.trafficserver_mid.traffic_ops", $toUri, $toCookie);
- print "Finished Importing Profiles.\n";
+sub generateParamConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %config = getConfig( $userInput, $fileName );
+ writeJson( $fileName, \%config );
+ return \%config;
}
-print "\nStarting Traffic Ops.\n\n";
-execCommand("/sbin/service traffic_ops start");
-
-print "\nWaiting for Traffic Ops to start.\n\n";
-sleep(5);
-
-sub profiles_exist {
- if ( -f $reconfigure_defaults ) {
- print "Default profiles were previously created. Remove " . $reconfigure_defaults . " to create again.\n";
- return 1;
- }
-
- while ( length $tmAdminUser == 0 ) {
- $tmAdminUser =
- InstallUtils::promptUser("Administration username for Traffic Ops");
- }
- while ( $tmAdminPw eq "" ) {
- $tmAdminPw =
- InstallUtils::promptUser( "Password for the admin user $tmAdminUser",
- "", 1 );
- }
- while ( !defined $parameters->{'tm.url'}
- || length $parameters->{'tm.url'} == 0 )
- {
- $parameters->{'tm.url'} =
- InstallUtils::promptUser( "Traffic Ops url", "https://localhost" );
- }
-
- my $uri = $parameters->{'tm.url'};
- my $toCookie = get_traffic_ops_cookie( $parameters->{'tm.url'},
- $tmAdminUser, $tmAdminPw );
-
- my $profileEndpoint = "/api/1.2/profiles.json";
-
- my $ua = LWP::UserAgent->new;
- $ua->ssl_opts( verify_hostname => 0, SSL_verify_mode => 0x00 );
- my $req = HTTP::Request->new( GET => $uri . $profileEndpoint );
- $req->header( 'Cookie' => "mojolicious=" . $toCookie );
- my $resp = $ua->request($req);
-
- if ( !$resp->is_success ) {
- print "Error checking if profiles exist: " . $resp->status_line . "\n";
- return 1; # return true, so we don't attempt to create profiles
- }
- my $message = $resp->decoded_content;
-
- my $profiles = JSON->new->utf8->decode($message);
- if ( ( !defined $profiles->{"response"} )
- || ( ref $profiles->{"response"} ne 'ARRAY' ) )
- {
- print "Error checking if profiles exist: invalid JSON: $message\n";
- return 1; # return true, so we don't attempt to create profiles
- }
-
- my $num_profiles = scalar( @{ $profiles->{"response"} } );
- print "Existing Profile Count: $num_profiles\n";
-
- my %initial_profiles = (
- "INFLUXDB" => 1,
- "RIAK_ALL" => 1,
- "TRAFFIC_STATS" => 1,
- "TRAFFIC_PORTAL" => 1
- );
-
- my $profiles_response = $profiles->{"response"};
- foreach my $profile (@$profiles_response) {
- if ( !exists $initial_profiles{ $profile->{"name"} } ) {
- print "Found existing profile (" . $profile->{"name"} . ")\n";
- open( my $reconfigure_defaults_file, '>', $reconfigure_defaults ) or die("Failed to open() $reconfigure_defaults: $!");
- close( $reconfigure_defaults_file );
- return 1;
- }
- }
- return 0;
+# check default values for missing config_var parameter
+sub sanityCheckDefaults {
+ foreach my $file ( ( keys $::defaultInputs ) ) {
+ foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
+ my $question = getConfigQuestion($defaultValue);
+
+ if ( !defined $defaultValue->{"config_var"}
+ || $defaultValue->{"config_var"} eq "" )
+ {
+ errorOut("Question '$question' in file '$file' has no config_var");
+ }
+ }
+ }
}
-if ( !profiles_exist() ) {
- print "Creating default profiles...\n";
- replace_profile_templates();
- import_profiles();
- profiles_exist(); # call again to create $reconfigure_defaults file if import was successful
+# userInput: The entire input config file which is either user input or the defaults
+#
+# Checks the input config file against the default inputs. If there is a question located in the default inputs which
+# is not located in the input config file it will output a warning message.
+
+sub sanityCheckConfig {
+ my $userInput = shift;
+ my $diffs = 0;
+
+ foreach my $file ( ( keys $::defaultInputs ) ) {
+ if ( !defined $userInput->{$file} ) {
+ logger( "File '$file' found in defaults but not config file", "warn" );
+ $userInput->{$file} = [];
+ }
+
+ foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
+
+ my $found = 0;
+ foreach my $configValue ( @{ $userInput->{$file} } ) {
+ if ( $defaultValue->{"config_var"} eq $configValue->{"config_var"} ) {
+ $found = 1;
+ }
+ }
+
+ # if the question is not found in the config file add it from defaults
+ if ( !$found ) {
+ 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) {
+ $answer = $defaultValue->{$question};
+ logger( "Adding question '$question' with default answer " . ( $hidden ? "" : "'$answer'" ), "info" );
+ }
+
+ # in interactive mode prompt the user for answer to missing question
+ else {
+ logger( "Prompting user for answer", "info" );
+ if ($hidden) {
+ $answer = promptPasswordVerify($question);
+ }
+ else {
+ $answer = promptUser( $question, $defaultValue->{$question} );
+ }
+ }
+
+ %temp = (
+ "config_var" => $defaultValue->{"config_var"},
+ $question => $answer
+ );
+
+ if ($hidden) {
+ $temp{"hidden"} .= "true";
+ }
+
+ push $userInput->{$file}, \%temp;
+
+ $diffs++;
+ }
+ }
+ }
+
+ logger( "File sanity check complete - found $diffs difference" . ( $diffs == 1 ? "" : "s" ), "info" );
}
-else {
- print "Not creating default profiles.\n";
+
+# A function which returns the default inputs data structure. These questions and answers will be used if there is no
+# user input config file or if there are questions in the input config file which do not have answers
+
+sub getDefaults {
+ return {
+ $::databaseConfFile => [
+ {
+ "Database type" => "mysql",
+ "config_var" => "type"
+ },
+ {
+ "Database name" => "traffic_ops",
+ "config_var" => "dbname"
+ },
+ {
+ "Database server hostname IP or FQDN" => "localhost",
+ "config_var" => "hostname"
+ },
+ {
+ "Database port number" => "3306",
+ "config_var" => "port"
+ },
+ {
+ "Traffic Ops database user" => "traffic_ops",
+ "config_var" => "user"
+ },
+ {
+ "Password for Traffic Ops database user" => "",
+ "config_var" => "password",
+ "hidden" => "true"
+ }
+ ],
+ $::dbConfFile => [
+ {
+ "Database server root (admin) user" => "root",
+ "config_var" => "dbAdminUser"
+ },
+ {
+ "Password for database server admin" => "",
+ "config_var" => "dbAdminPw",
+ "hidden" => "true"
+ }
+ ],
+ $::cdnConfFile => [
+ {
+ "Generate a new secret?" => "yes",
+ "config_var" => "genSecret"
+ },
+ {
+ "Number of secrets to keep?" => "10",
+ "config_var" => "keepSecrets"
+ }
+ ],
+ $::ldapConfFile => [
+ {
+ "Do you want to set up LDAP?" => "no",
+ "config_var" => "setupLdap"
+ },
+ {
+ "LDAP server hostname" => "",
+ "config_var" => "hostname"
+ },
+ {
+ "LDAP Admin DN" => "",
+ "config_var" => "admin_dn"
+ },
+ {
+ "LDAP Admin Password" => "",
+ "config_var" => "password",
+ "hidden" => "true"
+ },
+ {
+ "LDAP Search Base" => "",
+ "config_var" => "search_base"
+ }
+ ],
+ $::usersConfFile => [
+ {
+ "Administration username for Traffic Ops" => "admin",
+ "config_var" => "tmAdminUser"
+ },
+ {
+ "Password for the admin user" => "",
+ "config_var" => "tmAdminPw",
+ "hidden" => "true"
+ }
+ ],
+ $::profilesConfFile => [],
+ $::opensslConfFile => [
+ {
+ "Do you want to generate a certificate?" => "yes",
+ "config_var" => "genCert"
+ },
+ {
+ "Country Name (2 letter code)" => "XX",
+ "config_var" => "country"
+ },
+ {
+ "State or Province Name (full name)" => "San Jose",
+ "config_var" => "state"
+ },
+ {
+ "Locality Name (eg, city)" => "Default City",
+ "config_var" => "locality"
+ },
+ {
+ "Organization Name (eg, company)" => "Default Company Ltd",
+ "config_var" => "company"
+ },
+ {
+ "Organizational Unit Name (eg, section)" => "",
+ "config_var" => "org_unit"
+ },
+ {
+ "Common Name (eg, your name or your server's hostname)" => "example.com",
+ "config_var" => "common_name"
+ },
+ {
+ "RSA Passphrase" => "",
+ "config_var" => "rsaPassword",
+ "hidden" => "true"
+ }
+ ],
+ $::paramConfFile => [
+ {
+ "Traffic Ops url" => "https://localhost",
+ "config_var" => "tm.url"
+ },
+ {
+ "Human-readable CDN Name. (No whitespace, please)" => "kabletown_cdn",
+ "config_var" => "cdn_name"
+ },
+ {
+ "Health Polling Interval (milliseconds)" => "8000",
+ "config_var" => "health_polling_int"
+ },
+ {
+ "DNS sub-domain for which your CDN is authoritative" => "cdn1.kabletown.net",
+ "config_var" => "dns_subdomain"
+ },
+ {
+ "TLD SOA admin" => "traffic_ops",
+ "config_var" => "soa_admin"
+ },
+ {
+ "TrafficServer Drive Prefix" => "/dev/sd",
+ "config_var" => "driver_prefix"
+ },
+ {
+ "TrafficServer RAM Drive Prefix" => "/dev/ram",
+ "config_var" => "ram_drive_prefix"
+ },
+ {
+ "TrafficServer RAM Drive Letters (comma separated)" => "0,1,2,3,4,5,6,7",
+ "config_var" => "ram_drive_letters"
+ },
+ {
+ "Health Threshold Load Average" => "25",
+ "config_var" => "health_thresh_load_avg"
+ },
+ {
+ "Health Threshold Available Bandwidth in Kbps" => "1750000",
+ "config_var" => "health_thresh_kbps"
+ },
+ {
+ "Traffic Server Health Connection Timeout (milliseconds)" => "2000",
+ "config_var" => "health_connect_timeout"
+ }
+
+ ]
+ };
}
-#print "\nRunning smoke tests.\n\n";
-#$rc = execCommand ("/opt/traffic_ops/install/bin/systemtest", "localhost", $user{username}, $tmAdminPw, "0");
-{
- my $ans = promptUser( "\nInstall Cron entry to clean install .iso files older than 7 days? [y/n]", "n" );
- if ($ans eq "y" || $ans eq "Y") {
- execCommand( "/bin/echo \"00 04 * * * root /bin/find /opt/traffic_ops/app/public/iso/*.iso -mtime +7 -exec /bin/rm {} \; > /dev/null 2>&1 \" > /etc/cron.d/trafops_clean_isos" );
- }
+# 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;
+ my $genCert = shift;
+
+ #
+ # Call mysql initialization script.
+ #
+ logger( "Creating database with user: $todbconf->{dbAdminUser}", "info" );
+ my $result = execCommand( "/opt/traffic_ops/install/bin/create_db", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
+ if ( $result != 0 ) {
+ errorOut("Failed to create the database");
+ }
+
+ logger( "Setting up database", "info" );
+ chdir("/opt/traffic_ops/app");
+ $result = execCommand( "/usr/bin/perl", "db/admin.pl", "--env=production", "setup" );
+
+ if ( $result != 0 ) {
+ errorOut("Database initialization failed");
+ }
+ else {
+ logger( "Database initialization succeeded", "info" );
+ }
+
+ $result = execCommand( "/opt/traffic_ops/install/bin/dataload", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
+ if ( $result != 0 ) {
+ logger( "Failed to load seed data", "error" );
+ }
+
+ 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");
+ if ( $result != 0 ) {
+ logger( "Failed to download MaxMind data", "error" );
+ }
+
+ logger( "Copying coverage zone file to public dir", "info" );
+ $result = execCommand("/bin/mv /opt/traffic_ops/app/public/coverage-zone.json .");
+ if ( $result != 0 ) {
+ logger( "Failed to copy coverage zone file", "error" );
+ }
+
+ if ( lc $genCert =~ /^y(?:es)?/ ) {
+ if ( -x "/usr/bin/openssl" ) {
+ logger( "Installing SSL Certificates", "info" );
+ $result = GenerateCert::createCert($opensslconf);
+
+ if ( $result != 0 ) {
+ errorOut("SSL Certificate Installation failed");
+ }
+ else {
+ logger( "SSL Certificates have been installed", "info" );
+ }
+ }
+ else {
+ logger( "Unable to install SSL certificates as openssl is not installed", "error" );
+ logger( "Install openssl and then run /opt/traffic_ops/install/bin/generateCert to install SSL certificates", "error" );
+ exit 4;
+ }
+ }
+ else {
+ logger("Not generating openssl certification", "info");
+ }
}
-{
- my $ans = promptUser( "\nShutdown Traffic Ops [y/n]", "n" );
- if ( $ans eq "y" ) {
- print "\nShutting down Traffic Ops.\n\n";
- execCommand( "/sbin/service", "traffic_ops", "stop" );
- }
+# -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 = "";
+ our $automatic = 0;
+ our $debug = 0;
+ my $help = 0;
+
+ my $usageString = "Usage: postinstall [-a] [-debug] [-defaults] [-r] -cfile=[config_file]\n";
+
+ GetOptions(
+ "cfile=s" => \$inputFile,
+ "automatic" => \$automatic,
+ "reconfigure" => \$reconfigure,
+ "defaults" => \$dumpDefaults,
+ "debug" => \$debug,
+ "help" => \$help
+ ) or die($usageString);
+
+ # stores the default questions and answers
+ our $defaultInputs = getDefaults();
+
+ if ($help) {
+ print $usageString;
+ 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" );
+
+ 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" );
+ return;
+ }
+
+ if ($dumpDefaults) {
+ logger( "Writing default configuration file to $outputConfigFile", "info" );
+ writeJson( $outputConfigFile, $::defaultInputs );
+ return;
+ }
+
+ logger( "Postinstall " . ( defined $reconfigure ? "in" : "not" ) . " in reconfigure mode", "info" );
+
+ rotateLog($cpanLogFile);
+
+ if ( -s $::logFile > $maxLogSize ) {
+ logger( "Postinstall log above max size of $maxLogSize bytes - rotating", "info" );
+ rotateLog($logFile);
+ }
+
+ # used to store the questions and answers provided by the user
+ my $userInput;
+
+ # if no input file provided use the defaults
+ if ( $::inputFile eq "" ) {
+ logger( "No input file given - using defaults", "info" );
+ $userInput = $::defaultInputs;
+ }
+ else {
+ logger( "Using input file $::inputFile", "info" );
+
+ # check if the input file exists
+ errorOut("File '$::inputFile' not found") if ( !-f $::inputFile );
+
+ # read and store the input file
+ $userInput = readJson($::inputFile);
+ }
+
+ # sanity check the defaults if running them automatically
+ sanityCheckDefaults();
+
+ # check the input config file against the defaults to check for missing questions
+ sanityCheckConfig($userInput) if ( $inputFile ne "" );
+
+ chdir("/opt/traffic_ops/install/bin");
+
+ # if the reconfigure file exists or reconfigure is set then rebuild the perl deps
+ 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");
+ }
+ $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");
+ }
+ }
+ 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");
+ }
+ $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");
+ }
+ }
+
+ # The generator functions handle checking input/default/automatic mode
+
+ # todbconf will be used later when setting up the database
+ my $todbconf = generateDbConf( $userInput, $::databaseConfFile, $::dbConfFile );
+ generateCdnConf( $userInput, $::cdnConfFile );
+ generateLdapConf( $userInput, $::ldapConfFile );
+ my $adminconf = generateUsersConf( $userInput, $::usersConfFile );
+ generateProfilesDir( $userInput, $::profilesConfFile );
+ my $opensslconf = generateOpenSSLConf( $userInput, $::opensslConfFile );
+ my $paramconf = generateParamConf( $userInput, $::paramConfFile );
+
+ # if the reconfigure file exists or the reconfigure command line arg is set then setup the database
+ if ( -f $reconfigure_file || $reconfigure ) {
+ if ($::automatic) {
+ setupDatabase( $todbconf, $::opensslConfFile, $opensslconf->{genCert} );
+ }
+ else {
+ setupDatabase( $todbconf, 0, $opensslconf->{genCert} );
+ }
+ }
+
+ # remove the reconfigure file if it exists
+ if ( -f $reconfigure_file ) {
+ logger( "Removing reconfigure file", "info" );
+ unlink($reconfigure_file);
+ }
+
+ logger( "Starting Traffic Ops", "info" );
+ execCommand("/sbin/service traffic_ops start");
+
+ logger( "Waiting for Traffic Ops to start", "info" );
+
+ if ( !profiles_exist( $adminconf, $paramconf->{"tm.url"} ) ) {
+ logger( "Creating default profiles...", "info" );
+ replace_profile_templates($paramconf);
+ import_profiles($adminconf);
+ profiles_exist( $adminconf, $paramconf->{"tm.url"} ); # call again to create $reconfigure_defaults file if import was successful
+ }
+ else {
+ logger( "Not creating default profiles", "info" );
+ }
+
+ logger("Postinstall complete");
+
+ execCommand( "/bin/gzip", "$logFile" );
}
-print "\nTo start Traffic Ops: service traffic_ops start\n";
-print "To stop Traffic Ops: service traffic_ops stop\n";
-print "\n";
+main;
-exit 0;
+# vi:syntax=perl
[08/36] incubator-trafficcontrol git commit: Reverted changes not
relevant to new postinstall
Posted by da...@apache.org.
Reverted changes not relevant to new postinstall
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/034a587a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/034a587a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/034a587a
Branch: refs/heads/master
Commit: 034a587a49127c946d2c4a35fb193fdadaf2786e
Parents: c0545f7
Author: peryder <pe...@cisco.com>
Authored: Wed Nov 9 17:10:00 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/build_trafficops_perl_library | 9 ---------
traffic_ops/install/lib/InstallUtils.pm | 9 ---------
2 files changed, 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/034a587a/traffic_ops/install/bin/build_trafficops_perl_library
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/build_trafficops_perl_library b/traffic_ops/install/bin/build_trafficops_perl_library
index 33eda0c..aa3809d 100755
--- a/traffic_ops/install/bin/build_trafficops_perl_library
+++ b/traffic_ops/install/bin/build_trafficops_perl_library
@@ -1,7 +1,5 @@
#!/usr/bin/perl
#
-# Copyright 2015 Comcast Cable Communications Management, LLC
-#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@@ -26,9 +24,6 @@ use InstallUtils;
our ($opt_i);
-my $auto = $ARGV[0];
-print $auto;
-
my @dependencies = (
"expat-devel", "mod_ssl", "mkisofs", "libpcap", "libpcap-devel", "libcurl",
"libcurl-devel", "mysql-server", "mysql-devel", "openssl", "cpan", "gcc",
@@ -72,10 +67,6 @@ if ( $ENV{USER} ne "root" ) {
print $msg;
-if ( !$auto ) {
- InstallUtils::promptUser( "Hit ENTER to continue", "" );
-}
-
chdir("/opt/traffic_ops/app");
if ( defined $opt_i && $opt_i == 1 ) {
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/034a587a/traffic_ops/install/lib/InstallUtils.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/InstallUtils.pm b/traffic_ops/install/lib/InstallUtils.pm
index ddd1c22..4d45e7d 100644
--- a/traffic_ops/install/lib/InstallUtils.pm
+++ b/traffic_ops/install/lib/InstallUtils.pm
@@ -64,10 +64,6 @@ sub promptUser {
}
return $response;
}
- elsif ( $::auto && defined $defaultValue ) {
- print( "$defaultValue\n" );
- return $defaultValue;
- }
else {
$| = 1;
$_ = <STDIN>;
@@ -100,11 +96,6 @@ sub promptPassword {
sub promptPasswordVerify {
my $prompt = shift;
my $pw = shift;
-
- if ( $::auto && defined $pw ) {
- print( "$prompt: $pw\n" );
- return $pw;
- }
while (1) {
$pw = promptPassword($prompt);
[30/36] incubator-trafficcontrol git commit: Fixed issue around
whether or not to generate certificate
Posted by da...@apache.org.
Fixed issue around whether or not to generate certificate
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/c83a26b4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/c83a26b4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/c83a26b4
Branch: refs/heads/master
Commit: c83a26b4d1968d91b40841da7d3a039e52e7b861
Parents: 6e0b916
Author: peryder <pe...@cisco.com>
Authored: Thu Dec 15 16:14:56 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/input.json | 11 ++++++-----
traffic_ops/install/bin/postinstall-new | 18 +++++++++++-------
2 files changed, 17 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c83a26b4/traffic_ops/install/bin/input.json
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/input.json b/traffic_ops/install/bin/input.json
index e613a3a..76720f6 100644
--- a/traffic_ops/install/bin/input.json
+++ b/traffic_ops/install/bin/input.json
@@ -84,10 +84,10 @@
"/opt/traffic_ops/install/data/profiles/":[
],
- "/opt/traffic_ops/install/bin/openssl_configuration.json":[
- {
- "Do you want to generate a certificate?": "yes",
- "config_var": "genCert"
+ "/opt/traffic_ops/install/data/json/openssl_configuration.json":[
+ {
+ "Do you want to generate a certificate?":"yes",
+ "config_var":"genCert"
},
{
"Country Name (2 letter code)":"XX",
@@ -157,7 +157,7 @@
"config_var":"health_thresh_load_avg"
},
{
- "Health Threshold Available Bandwidth in Kbps":"1750000",
+ "Health Threshold Available Bandwidth in Kbps":">1750000",
"config_var":"health_thresh_kbps"
},
{
@@ -166,3 +166,4 @@
}
]
}
+
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c83a26b4/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
index 155651c..d345663 100755
--- a/traffic_ops/install/bin/postinstall-new
+++ b/traffic_ops/install/bin/postinstall-new
@@ -41,9 +41,12 @@ our $cdnConfFile = "/opt/traffic_ops/app/conf/cdn.conf";
our $ldapConfFile = "/opt/traffic_ops/app/conf/ldap.conf";
our $usersConfFile = "/opt/traffic_ops/install/data/json/users.json";
our $profilesConfFile = "/opt/traffic_ops/install/data/profiles/";
-our $opensslConfFile = "/opt/traffic_ops/install/bin/openssl_configuration.json";
+our $opensslConfFile = "/opt/traffic_ops/install/data/json/openssl_configuration.json";
our $paramConfFile = "/opt/traffic_ops/install/data/json/profiles.json";
+our $profile_dir = "/opt/traffic_ops/install/data/profiles/";
+our $post_install_cfg = "/opt/traffic_ops/install/data/json/post_install.json";
+
our $reconfigure_defaults = "/opt/traffic_ops/.reconfigure_defaults";
our $parameters;
@@ -219,9 +222,8 @@ sub generateLdapConf {
my $useLdap = $userInput->{$fileName}[0]->{"Do you want to set up LDAP?"};
- if ( $useLdap eq "no" || $useLdap eq "n" ) {
+ if ( !lc $useLdap =~ /^y(?:es)?/ ) {
logger( "Not setting up ldap", "info" );
-
return;
}
@@ -268,6 +270,7 @@ sub generateOpenSSLConf {
my %config = getConfig( $userInput, $fileName );
writeJson( $fileName, \%config );
+ return \%config;
}
sub generateParamConf {
@@ -544,6 +547,7 @@ sub getDefaults {
sub setupDatabase {
my $todbconf = shift;
my $opensslconf = shift;
+ my $genCert = shift;
#
# Call mysql initialization script.
@@ -583,7 +587,7 @@ sub setupDatabase {
logger( "Failed to copy coverage zone file", "error" );
}
- if ( lc $opensslconf->{genCert} =~ /^y(?:es)?/ ) {
+ if ( lc $genCert =~ /^y(?:es)?/ ) {
if ( -x "/usr/bin/openssl" ) {
logger( "Installing SSL Certificates", "info" );
$result = GenerateCert::createCert($opensslconf);
@@ -735,16 +739,16 @@ sub main {
generateLdapConf( $userInput, $::ldapConfFile );
my $adminconf = generateUsersConf( $userInput, $::usersConfFile );
generateProfilesDir( $userInput, $::profilesConfFile );
- generateOpenSSLConf( $userInput, $::opensslConfFile );
+ my $opensslconf = generateOpenSSLConf( $userInput, $::opensslConfFile );
my $paramconf = generateParamConf( $userInput, $::paramConfFile );
# if the reconfigure file exists or the reconfigure command line arg is set then setup the database
if ( -f $reconfigure_file || $reconfigure ) {
if ($::automatic) {
- setupDatabase( $todbconf, $::opensslConfFile );
+ setupDatabase( $todbconf, $::opensslConfFile, $opensslconf->{genCert} );
}
else {
- setupDatabase( $todbconf, 0 );
+ setupDatabase( $todbconf, 0, $opensslconf->{genCert} );
}
}
[10/36] incubator-trafficcontrol git commit: Changed command line
argument -i to -a and interactive mode is now default mode of operation
Posted by da...@apache.org.
Changed command line argument -i to -a and interactive mode is now default mode of operation
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/7046baa6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/7046baa6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/7046baa6
Branch: refs/heads/master
Commit: 7046baa6c104f2e6b5d7f9d102d4842a2464ffa5
Parents: 9edf9d7
Author: peryder <pe...@cisco.com>
Authored: Tue Nov 15 13:56:52 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall-new | 130 +++++++++++++++++----------
1 file changed, 84 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7046baa6/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
index abd2170..ce5fe9c 100755
--- a/traffic_ops/install/bin/postinstall-new
+++ b/traffic_ops/install/bin/postinstall-new
@@ -1,8 +1,10 @@
#!/usr/bin/perl
-use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
-$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
-$ENV{PERL5LIB} = "/opt/traffic_ops/install/lib:/opt/traffic_ops/install/lib/perl5:/opt/traffic_ops/app/local/lib/perl5:/opt/traffic_ops/app/lib";
+use lib
+ qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
+$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
+$ENV{PERL5LIB} =
+"/opt/traffic_ops/install/lib:/opt/traffic_ops/install/lib/perl5:/opt/traffic_ops/app/local/lib/perl5:/opt/traffic_ops/app/lib";
use strict;
use warnings;
@@ -36,7 +38,7 @@ sub getInstallPath {
# fileName: The name of the output config file given by the input config file
#
# Determines an answer to the questions asked. If an input question and answer pair is given, will return the
-# answer. If a question is given but no answer, it will prompt the user if interactive mode is enabled, but if
+# answer. If a question is given but no answer, it will prompt the user if interactive mode is enabled, but if
# interactive mode is not enabled it will return the default answer to the question. If there is no default answer
# to the question and interactive mode is not enabled it will return an error and quit.
@@ -45,8 +47,8 @@ sub getField {
my $config_answer = shift;
my $fileName = shift;
- # if there is no config file and interactive mode prompt for all questions with default answers
- if ( $::inputFile eq "" && $::interactive ) {
+# if there is no config file and not in automatic mode prompt for all questions with default answers
+ if ( $::inputFile eq "" && !$::automatic ) {
return promptUser( $question, $config_answer );
}
@@ -55,8 +57,8 @@ sub getField {
return $config_answer;
}
else {
- # if no config value and in interactive mode prompt user
- if ($::interactive) {
+ # if no config value and not in automatic mode prompt user
+ if ( !$::automatic ) {
return promptUser($question);
}
@@ -95,9 +97,13 @@ sub getConfig {
}
foreach my $var ( @{ $userInput->{$fileName} } ) {
- my $question = ( ( keys $var )[0] eq "config_var" ? ( keys $var )[1] : ( keys $var )[0] );
+ my $question =
+ ( ( keys $var )[0] eq "config_var"
+ ? ( keys $var )[1]
+ : ( keys $var )[0] );
- my $answer = $config{ $var->{"config_var"} } = getField( $question, $var->{$question}, $fileName );
+ my $answer = $config{ $var->{"config_var"} } =
+ getField( $question, $var->{$question}, $fileName );
$config{ $var->{"config_var"} } = $answer;
if ($::debug) {
@@ -129,12 +135,14 @@ sub generateDbConf {
my %todbconf = getConfig( $userInput, $toDBFileName );
# No YAML library installed, but this is a simple file..
- open( my $fh, '>', $dbAccessFileName ) or errorOut("Can't write to $dbAccessFileName $!");
+ open( my $fh, '>', $dbAccessFileName )
+ or errorOut("Can't write to $dbAccessFileName $!");
print $fh "version: 1.0\n";
print $fh "name: dbconf.yml\n\n";
print $fh "production:\n";
print $fh " driver: ", getDbDriver() . "\n";
- print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{root_user}/$dbconf{root_passwd}\n";
+ print $fh
+" open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{root_user}/$dbconf{root_passwd}\n";
close $fh;
return \%todbconf;
@@ -150,7 +158,8 @@ sub generateCdnConf {
my $fileName = shift;
# First, read existing one -- already loaded with a bunch of stuff
- my $cdnConf = Safe->new->rdo($fileName) or errorOut("Error loading $fileName: $@");
+ my $cdnConf = Safe->new->rdo($fileName)
+ or errorOut("Error loading $fileName: $@");
my %cdnconf = getConfig( $userInput, $fileName );
@@ -162,7 +171,9 @@ sub generateCdnConf {
my @secrets = @{ $cdnConf->{secrets} };
my $newSecret = randomWord();
unshift @secrets, randomWord();
- if ( $cdnconf{keepSecrets} > 0 && $#secrets > $cdnconf{keepSecrets} - 1 ) {
+ if ( $cdnconf{keepSecrets} > 0
+ && $#secrets > $cdnconf{keepSecrets} - 1 )
+ {
# Shorten the array to requested length
$#secrets = $cdnconf{keepSecrets} - 1;
@@ -230,13 +241,24 @@ sub generateProfilesDir {
sub sanityCheckDefaults {
foreach my $file ( ( keys $::defaultInputs ) ) {
foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
- my $question = ( ( keys $defaultValue )[0] eq "config_var" ? ( keys $defaultValue )[1] : ( keys $defaultValue )[0] );
- if ( !defined $defaultValue->{$question} || $defaultValue->{$question} eq "" ) {
- errorOut("Error: question \'$question\' in file \'$file\' has no default answer\n");
+ my $question =
+ ( ( keys $defaultValue )[0] eq "config_var"
+ ? ( keys $defaultValue )[1]
+ : ( keys $defaultValue )[0] );
+ if ( !defined $defaultValue->{$question}
+ || $defaultValue->{$question} eq "" )
+ {
+ errorOut(
+"Error: question \'$question\' in file \'$file\' has no default answer\n"
+ );
}
- if ( !defined $defaultValue->{"config_var"} || $defaultValue->{"config_var"} eq "" ) {
- errorOut("Error: question \'$question\' in file \'$file\' has no config_var");
+ if ( !defined $defaultValue->{"config_var"}
+ || $defaultValue->{"config_var"} eq "" )
+ {
+ errorOut(
+"Error: question \'$question\' in file \'$file\' has no config_var"
+ );
}
}
}
@@ -256,7 +278,8 @@ sub sanityCheckConfig {
foreach my $file ( ( keys $::defaultInputs ) ) {
if ( !defined $userInput->{$file} ) {
- print "Warning: File \'$file\' found in defaults but not config file\n";
+ print
+ "Warning: File \'$file\' found in defaults but not config file\n";
next;
}
@@ -264,27 +287,40 @@ sub sanityCheckConfig {
my $found = 0;
foreach my $configValue ( @{ $userInput->{$file} } ) {
- if ( $defaultValue->{"config_var"} eq $configValue->{"config_var"} ) {
+ if ( $defaultValue->{"config_var"} eq
+ $configValue->{"config_var"} )
+ {
$found = 1;
}
}
- # if the question is not found in the config file add it from defaults
+ # if the question is not found in the config file add it from defaults
if ( !$found ) {
- print "Warning: Value " . Dumper($defaultValue) . "found in defaults but not in \'$file\'\n";
+ print "Warning: Value "
+ . Dumper($defaultValue)
+ . "found in defaults but not in \'$file\'\n";
- my $question = ( ( keys $defaultValue )[0] eq "config_var" ? ( keys $defaultValue )[1] : ( keys $defaultValue )[0] );
+ my $question =
+ ( ( keys $defaultValue )[0] eq "config_var"
+ ? ( keys $defaultValue )[1]
+ : ( keys $defaultValue )[0] );
my %temp;
- # if interactive add the question without default answer
- if ($::interactive) {
- %temp = ( "config_var" => $defaultValue->{"config_var"}, $question => "" );
+ # if not in automatic mode add the question without default answer
+ if ( !$::automatic ) {
+ %temp = (
+ "config_var" => $defaultValue->{"config_var"},
+ $question => ""
+ );
}
- # if not interactive add question with default answer
+ # if in automatic mode add question with default answer
else {
- %temp = ( "config_var" => $defaultValue->{"config_var"}, $question => $defaultValue->{$question} );
+ %temp = (
+ "config_var" => $defaultValue->{"config_var"},
+ $question => $defaultValue->{$question}
+ );
}
push $userInput->{$file}, \%temp;
@@ -392,26 +428,22 @@ sub getDefaults {
}
# -d - Debug Mode: More output to the terminal
-# -i - Interactive mode: Any questions which do not have answersin config file will result in blocking prompts going
-# to the user
+# -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
-# In interactive mode: prompt if no value in cfile
-
-# Not in interactive mode: if answer in cfile, use if. If no answer in cfile, use answer in default.
-# if no answer in default die
-
sub main {
our $inputFile = "";
+ our $automatic = 0;
+ our $debug = 0;
my $help = 0;
- our $interactive = 0;
- our $debug = 0;
GetOptions(
"cfile=s" => \$inputFile,
"c=s" => \$inputFile,
- "i" => \$interactive,
+ "a" => \$automatic,
"d" => \$debug,
"h" => \$help,
"help" => \$help
@@ -421,7 +453,7 @@ sub main {
our $defaultInputs = getDefaults();
if ($help) {
- print "Usage: postinstall [-i] [-d] -cfile=[config_file]\n";
+ print "Usage: postinstall [-a] [-d] -cfile=[config_file]\n";
exit(0);
}
@@ -429,8 +461,8 @@ sub main {
print "Debug is on\n";
}
- if ( $::debug && $::interactive ) {
- print "Running in interactive mode\n";
+ if ( $::debug && $::automatic ) {
+ print "Running in automatic mode\n";
}
# used to store the questions and answers -
@@ -443,11 +475,16 @@ sub main {
}
else {
print "Using input file $::inputFile\n";
+
+ if ( !-e $::inputFile ) {
+ errorOut("Error: file \'$::inputFile\' not found\n");
+ }
+
$userInput = readJson($::inputFile);
}
- # check the defaults
- if ( $::inputFile eq "" && !$::interactive ) {
+ # check the defaults if running them automatically
+ if ( $::inputFile eq "" && $::automatic ) {
sanityCheckDefaults();
}
@@ -457,10 +494,11 @@ sub main {
sanityCheckConfig($userInput);
}
- # The generator functions handle checking input/default/interactive mode
+ # The generator functions handle checking input/default/automatic mode
# todbconf will be used later when setting up the database
- my $todbconf = generateDbConf( $userInput, 'testdb.conf', 'testtodb.conf', 'testdbconf.yml' );
+ my $todbconf = generateDbConf( $userInput, 'testdb.conf', 'testtodb.conf',
+ 'testdbconf.yml' );
generateCdnConf( $userInput, 'testcdn.conf' );
generateLdapConf( $userInput, 'testldap.conf' );
generatePostInstallConf( $userInput, 'testpost_install.json' );
[29/36] incubator-trafficcontrol git commit: Added question for cert
generation to input.json
Posted by da...@apache.org.
Added question for cert generation to input.json
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/6e0b9165
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/6e0b9165
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/6e0b9165
Branch: refs/heads/master
Commit: 6e0b916553520fef1d0a15f35af03679a8bc71a0
Parents: be8df01
Author: peryder <pe...@cisco.com>
Authored: Tue Dec 13 15:21:30 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/input.json | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/6e0b9165/traffic_ops/install/bin/input.json
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/input.json b/traffic_ops/install/bin/input.json
index 9978acb..e613a3a 100644
--- a/traffic_ops/install/bin/input.json
+++ b/traffic_ops/install/bin/input.json
@@ -85,6 +85,10 @@
],
"/opt/traffic_ops/install/bin/openssl_configuration.json":[
+ {
+ "Do you want to generate a certificate?": "yes",
+ "config_var": "genCert"
+ },
{
"Country Name (2 letter code)":"XX",
"config_var":"country"
@@ -161,4 +165,4 @@
"config_var":"health_connect_timeout"
}
]
-}
\ No newline at end of file
+}
[32/36] incubator-trafficcontrol git commit: Fixed input.json
Posted by da...@apache.org.
Fixed input.json
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/d775c033
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/d775c033
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/d775c033
Branch: refs/heads/master
Commit: d775c033b303390b3ef469d382182fd84128e482
Parents: 64f49e3
Author: peryder <pe...@cisco.com>
Authored: Mon Jan 9 09:27:01 2017 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/input.json | 101 +++++++++++++++++++++++++++++++-
1 file changed, 99 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d775c033/traffic_ops/install/bin/input.json
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/input.json b/traffic_ops/install/bin/input.json
index b1adce2..31b126f 100644
--- a/traffic_ops/install/bin/input.json
+++ b/traffic_ops/install/bin/input.json
@@ -67,5 +67,102 @@
},
{
"LDAP Search Base":"",
- "input.json" 169 L,
- 4044 C
\ No newline at end of file
+ "config_var":"search_base"
+ }
+ ],
+ "/opt/traffic_ops/install/data/json/users.json":[
+ {
+ "Administration username for Traffic Ops":"root",
+ "config_var":"tmAdminUser"
+ },
+ {
+ "Password for the admin user":"default",
+ "config_var":"tmAdminPw",
+ "hidden":"1"
+ }
+ ],
+ "/opt/traffic_ops/install/data/profiles/":[
+
+ ],
+ "/opt/traffic_ops/install/data/json/openssl_configuration.json":[
+ {
+ "Do you want to generate a certificate?":"yes",
+ "config_var":"genCert"
+ },
+ {
+ "Country Name (2 letter code)":"XX",
+ "config_var":"country"
+ },
+ {
+ "State or Province Name (full name)":"Default State",
+ "config_var":"state"
+ },
+ {
+ "Locality Name (eg, city)":"Default City",
+ "config_var":"locality"
+ },
+ {
+ "Organization Name (eg, company)":"Default Company Ltd",
+ "config_var":"company"
+ },
+ {
+ "Organizational Unit Name (eg, section)":"",
+ "config_var":"org_unit"
+ },
+ {
+ "Common Name (eg, your name or your server's hostname)":"example.com",
+ "config_var":"common_name"
+ },
+ {
+ "RSA Passphrase":"password",
+ "config_var":"rsaPassword",
+ "hidden":"1"
+ }
+ ],
+ "/opt/traffic_ops/install/data/json/profiles.json":[
+ {
+ "Traffic Ops url":"https://localhost",
+ "config_var":"tm.url"
+ },
+ {
+ "Human-readable CDN Name. (No whitespace, please)":"kabletown_cdn",
+ "config_var":"cdn_name"
+ },
+ {
+ "Health Polling Interval (milliseconds)":"8000",
+ "config_var":"health_polling_int"
+ },
+ {
+ "DNS sub-domain for which your CDN is authoritative":"cdn1.kabletown.net",
+ "config_var":"dns_subdomain"
+ },
+ {
+ "TLD SOA admin":"traffic_ops",
+ "config_var":"soa_admin"
+ },
+ {
+ "TrafficServer Drive Prefix":"/dev/sd",
+ "config_var":"driver_prefix"
+ },
+ {
+ "TrafficServer RAM Drive Prefix":"/dev/ram",
+ "config_var":"ram_drive_prefix"
+ },
+ {
+ "TrafficServer RAM Drive Letters (comma separated)":"0,1,2,3,4,5,6,7",
+ "config_var":"ram_drive_letters"
+ },
+ {
+ "Health Threshold Load Average":"25",
+ "config_var":"health_thresh_load_avg"
+ },
+ {
+ "Health Threshold Available Bandwidth in Kbps":">1750000",
+ "config_var":"health_thresh_kbps"
+ },
+ {
+ "Traffic Server Health Connection Timeout (milliseconds)":"2000",
+ "config_var":"health_connect_timeout"
+ }
+ ]
+}
\ No newline at end of file
[25/36] incubator-trafficcontrol git commit: Removed 2nd check for
root access in postinstall-new
Posted by da...@apache.org.
Removed 2nd check for root access in postinstall-new
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/a3433b05
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/a3433b05
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/a3433b05
Branch: refs/heads/master
Commit: a3433b05d2ddc4683bfedd67f65fc8b83240a5a4
Parents: 62da24d
Author: peryder <pe...@cisco.com>
Authored: Wed Dec 7 12:43:58 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall-new | 5 -----
1 file changed, 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a3433b05/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
index 9972daa..c5ffeef 100755
--- a/traffic_ops/install/bin/postinstall-new
+++ b/traffic_ops/install/bin/postinstall-new
@@ -669,11 +669,6 @@ sub main {
logger( "Postinstall " . ( defined $reconfigure ? "in" : "not" ) . " in reconfigure mode", "info" );
- # check if the user has root access
- if ( $ENV{USER} ne "root" ) {
- errorOut("You must run this script as the root user");
- }
-
rotateLog($cpanLogFile);
if ( -s $::logFile > $maxLogSize ) {
[05/36] incubator-trafficcontrol git commit: Changed params to cpan
to match open source
Posted by da...@apache.org.
Changed params to cpan to match open source
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/62da24d6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/62da24d6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/62da24d6
Branch: refs/heads/master
Commit: 62da24d6f420b156bf79e27eb55aacf3b1516cf0
Parents: 7ba725b
Author: peryder <pe...@cisco.com>
Authored: Wed Dec 7 11:55:50 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/lib/BuildPerlDeps.pm | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/62da24d6/traffic_ops/install/lib/BuildPerlDeps.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/BuildPerlDeps.pm b/traffic_ops/install/lib/BuildPerlDeps.pm
index e127d07..5566b73 100644
--- a/traffic_ops/install/lib/BuildPerlDeps.pm
+++ b/traffic_ops/install/lib/BuildPerlDeps.pm
@@ -62,18 +62,18 @@ EOF
}
logger( "Building perl modules", "info" );
- $result = execCommand( "/opt/traffic_ops/install/bin/cpan.sh", "pi_custom_log=" . $::cpanLogFile, "/opt/traffic_ops/install/bin/yaml.txt" );
+ $result = execCommand( "/usr/bin/cpan", "pi_custom_log=" . $::cpanLogFile, "-if", "YAML" );
if ( $result != 0 ) {
errorOut("Failed to install YAML, look through the output and correct the problem");
}
- $result = execCommand( "/opt/traffic_ops/install/bin/cpan.sh", "pi_custom_log=" . $::cpanLogFile, "/opt/traffic_ops/install/bin/carton.txt" );
+ $result = execCommand( "/usr/bin/cpan", "pi_custom_log=" . $::cpanLogFile, "-if", "MIYAGAWA/Carton-v1.0.15.tar.gz" );
if ( $result != 0 ) {
errorOut("Failed to install Carton, look through the output and correct the problem");
}
}
- $result = execCommand( "/usr/local/bin/carton", "install", "--deployment", "--cached" );
+ $result = execCommand( "/usr/local/bin/carton", "install" );
if ( $result != 0 ) {
errorOut("Failure to build required perl modules, check the output and correct the problem");
}
[14/36] incubator-trafficcontrol git commit: Updated to include full
new postinstall with new perl modules
Posted by da...@apache.org.
Updated to include full new postinstall with new perl modules
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/bae43757
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/bae43757
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/bae43757
Branch: refs/heads/master
Commit: bae4375757ceb18358c4bd2dcf5ce873ec225e02
Parents: 4a2657b
Author: peryder <pe...@cisco.com>
Authored: Thu Dec 1 17:05:28 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/input.json | 138 +++-
traffic_ops/install/bin/postinstall-new | 15 +-
.../install/bin/postinstall-new-integrated | 763 +++++++++++++++++++
traffic_ops/install/lib/BuildPerlDeps.pm | 99 +++
traffic_ops/install/lib/GenerateCert.pm | 232 ++++++
traffic_ops/install/lib/InstallUtils.pm | 268 ++++---
traffic_ops/install/lib/ProfileCleanup.pm | 192 +++++
7 files changed, 1580 insertions(+), 127 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/bae43757/traffic_ops/install/bin/input.json
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/input.json b/traffic_ops/install/bin/input.json
index 8428eec..fd9f0e6 100644
--- a/traffic_ops/install/bin/input.json
+++ b/traffic_ops/install/bin/input.json
@@ -1,11 +1,11 @@
{
- "testdb.conf": [
+ "/opt/traffic_ops/app/conf/production/database.conf": [
{
"Database type": "mysql",
"config_var": "type"
},
{
- "Database name": "traffic_ops",
+ "Database name": "traffic_ops_db",
"config_var": "dbname"
},
{
@@ -16,26 +16,28 @@
"Database port number": "3306",
"config_var": "port"
},
- {
- "Root database user": "root",
- "config_var": "root_user"
- },
- {
- "Root database password": "default",
- "config_var": "root_passwd"
- }
+ {
+ "Traffic Ops database user": "traffic_ops",
+ "config_var": "user"
+ },
+ {
+ "Traffic Ops database password": "default",
+ "config_var": "password",
+ "hidden": "1"
+ }
],
- "testtodb.conf": [
- {
- "Traffic Ops database user": "root",
- "config_var": "dbAdminUser"
- },
+ "/opt/traffic_ops/app/db/dbconf.yml": [
+ {
+ "Database server root (admin) username": "root",
+ "config_var": "dbAdminUser"
+ },
{
- "Password for Traffic Ops database user": "default",
- "config_var": "dbAdminPw"
- }
+ "Database server admin password": "default",
+ "config_var": "dbAdminPw",
+ "hidden": "1"
+ }
],
- "testcdn.conf": [
+ "/opt/traffic_ops/app/conf/cdn.conf": [
{
"Generate a new secret?": "yes",
"config_var": "genSecret"
@@ -45,7 +47,7 @@
"config_var": "keepSecrets"
}
],
- "testldap.conf": [
+ "/opt/traffic_ops/app/conf/ldap.conf": [
{
"Do you want to set up LDAP?": "no",
"config_var": "setupLdap"
@@ -60,23 +62,101 @@
},
{
"LDAP Admin Password": "",
- "config_var": "password"
+ "config_var": "password",
+ "hidden": "1"
},
{
"LDAP Search Base": "",
"config_var": "search_base"
}
],
- "testpost_install.json": [],
- "testusers.json": [
+ "/opt/traffic_ops/install/data/json/users.json": [
+ {
+ "Administration username for Traffic Ops": "root",
+ "config_var": "tmAdminUser"
+ },
+ {
+ "Password for the admin user": "default",
+ "config_var": "tmAdminPw",
+ "hidden": "1"
+ }
+ ],
+ "/opt/traffic_ops/install/data/profiles/": [],
+ "/opt/traffic_ops/install/bin/openssl_configuration.json": [
{
- "Administration username for Traffic Ops": "admin",
- "config_var": "tmAdminUser"
+ "Country Name (2 letter code)": "XX",
+ "config_var": "country"
},
{
- "Password for the admin user": "default",
- "config_var": "tmAdminPw"
- }
+ "State or Province Name (full name)": "Default State",
+ "config_var": "state"
+ },
+ {
+ "Locality Name (eg, city)": "Default City",
+ "config_var": "locality"
+ },
+ {
+ "Organization Name (eg, company)": "Default Company Ltd",
+ "config_var": "company"
+ },
+ {
+ "Organizational Unit Name (eg, section)": "",
+ "config_var": "org_unit"
+ },
+ {
+ "Common Name (eg, your name or your server's hostname)": "example.com",
+ "config_var": "common_name"
+ },
+ {
+ "RSA Passphrase": "password",
+ "config_var": "rsaPassword",
+ "hidden": "1"
+ }
],
- "testprofiles/": []
+ "/opt/traffic_ops/install/data/json/profiles.json": [
+ {
+ "Traffic Ops url": "https://localhost",
+ "config_var": "tm.url"
+ },
+ {
+ "Human-readable CDN Name. (No whitespace, please)": "kabletown_cdn",
+ "config_var": "cdn_name"
+ },
+ {
+ "Health Polling Interval (milliseconds)": "8000",
+ "config_var": "health_polling_int"
+ },
+ {
+ "DNS sub-domain for which your CDN is authoritative": "cdn1.kabletown.net",
+ "config_var": "dns_subdomain"
+ },
+ {
+ "TLD SOA admin": "traffic_ops",
+ "config_var": "soa_admin"
+ },
+ {
+ "TrafficServer Drive Prefix": "/dev/sd",
+ "config_var": "driver_prefix"
+ },
+ {
+ "TrafficServer RAM Drive Prefix": "/dev/ram",
+ "config_var": "ram_drive_prefix"
+ },
+ {
+ "TrafficServer RAM Drive Letters (comma separated)": "0,1,2,3,4,5,6,7",
+ "config_var": "ram_drive_letters"
+ },
+ {
+ "Health Threshold Load Average": "25",
+ "config_var": "health_thresh_load_avg"
+ },
+ {
+ "Health Threshold Available Bandwidth in Kbps": "1750000",
+ "config_var": "health_thresh_kbps"
+ },
+ {
+ "Traffic Server Health Connection Timeout (milliseconds)": "2000",
+ "config_var": "health_connect_timeout"
+ }
+ ]
}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/bae43757/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
index b97d58d..cb4cc56 100755
--- a/traffic_ops/install/bin/postinstall-new
+++ b/traffic_ops/install/bin/postinstall-new
@@ -39,6 +39,7 @@ sub errorOut {
}
# outputs logging messages to terminal and log file
+# TODO: move to InstallUtils
sub logger {
my $output = shift;
my $type = shift;
@@ -247,7 +248,8 @@ sub sanityCheckDefaults {
# userInput: The entire input config file which is either user input or the defaults
#
# Checks the input config file against the default inputs. If there is a question located in the default inputs which
-# is not located in the input config file it will output a warning message.
+# is not located in the input config file it will output a warning message. If in auto mode the default answer will be
+# used. If in interactive mode the user will be prompted with the default question missing from the config file
#
# This does not check the other way meaning questions which are present in defaults but not present in the input config
# file will not be checked
@@ -259,9 +261,8 @@ sub sanityCheckConfig {
foreach my $file ( ( keys $::defaultInputs ) ) {
if ( !defined $userInput->{$file} ) {
logger( "File \'$file\' found in defaults but not config file", "warn" );
- next;
- }
-
+ $userInput->{$file} = [];
+ }
foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
my $found = 0;
@@ -308,10 +309,6 @@ sub sanityCheckConfig {
logger( "File sanity check complete - found $diffs difference(s)", "info" ) if ( $diffs > 0 );
}
-sub writeOutputConf {
- writeJson( $::outputConfigFile, \%::outputConf );
-}
-
# A function which returns the default inputs data structure. These questions and answers will be used if there is no
# user input config file or if there are questions in the input config file which do not have answers
@@ -331,7 +328,7 @@ sub getDefaults {
"config_var" => "hostname",
},
{
- "Database port number" => 3306,
+ "Database port number" => "3306",
"config_var" => "port"
},
{
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/bae43757/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
new file mode 100755
index 0000000..529cce8
--- /dev/null
+++ b/traffic_ops/install/bin/postinstall-new-integrated
@@ -0,0 +1,763 @@
+#!/usr/bin/perl
+
+use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
+$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
+$ENV{PERL5LIB} = "/opt/traffic_ops/install/lib:/opt/traffic_ops/install/lib/perl5:/opt/traffic_ops/app/local/lib/perl5:/opt/traffic_ops/app/lib";
+
+use strict;
+use warnings;
+
+use Safe;
+use POSIX;
+use File::Basename qw{dirname};
+use File::Path qw{make_path};
+use InstallUtils qw{ :all };
+use BuildPerlDeps qw{ :all };
+use GenerateCert qw{ :all };
+use ProfileCleanup qw { :all };
+use Digest::SHA1 qw(sha1_hex);
+use Data::Dumper qw(Dumper);
+use Scalar::Util qw(looks_like_number);
+
+use Getopt::Long;
+
+# paths of the output configuration files
+our $databaseConfFile = "/opt/traffic_ops/app/conf/production/database.conf";
+our $dbConfFile = "/opt/traffic_ops/app/db/dbconf.yml";
+our $cdnConfFile = "/opt/traffic_ops/app/conf/cdn.conf";
+our $ldapConfFile = "/opt/traffic_ops/app/conf/ldap.conf";
+our $usersConfFile = "/opt/traffic_ops/install/data/json/users.json";
+our $profilesConfFile = "/opt/traffic_ops/install/data/profiles/";
+our $opensslConfFile = "/opt/traffic_ops/install/bin/openssl_configuration.json";
+our $paramConfFile = "/opt/traffic_ops/install/data/json/profiles.json";
+
+our $profile_dir = "/opt/traffic_ops/install/data/profiles/";
+our $post_install_cfg = "/opt/traffic_ops/install/data/json/post_install.json";
+
+our $reconfigure_defaults = "/opt/traffic_ops/.reconfigure_defaults";
+
+our $parameters;
+
+my $reconfigure_file = "/opt/traffic_ops/.reconfigure";
+my $reconfigure;
+my $dumpDefaults;
+
+# log file for the installer
+our $logFile = "/var/log/traffic_ops/postinstall.log";
+
+# maximum size the log file should be before rotating it - rotating it copies the current log
+# file to the same name appended with .bkp replacing the old backup if any is there
+my $maxLogSize = 1000000; #bytes
+
+# log file for cpan - this log becomes large and is rotated every install
+our $cpanLogFile = "/var/log/traffic_ops/cpan.log";
+
+# configuration file output with answers which can be used as input to postinstall
+our $outputConfigFile = "/var/log/traffic_ops/configuration_file.json";
+
+sub getDbDriver {
+ return "mymysql";
+}
+
+sub getInstallPath {
+ my $relPath = shift;
+ return join( '/', "/tmp/traffic_ops", $relPath );
+}
+
+# given a var to the hash of config_var and question, will return the question
+sub getConfigQuestion {
+ my $var = shift;
+ foreach my $key ( keys $var ) {
+ if ( $key ne "hidden" && $key ne "config_var" ) {
+ return $key;
+ }
+ }
+}
+
+# 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
+#
+# Determines if the script is being run in complete interactive mode and prompts user - otherwise
+# returns answer to question in config or defaults
+
+sub getField {
+ my $question = shift;
+ my $config_answer = shift;
+ my $hidden = shift;
+
+ # if there is no config file and not in automatic mode prompt for all questions with default answers
+ if ( !$::inputFile && !$::automatic ) {
+ if ($hidden) {
+ return promptPasswordVerify($question);
+ }
+ else {
+ return promptUser( $question, $config_answer );
+ }
+ }
+
+ return $config_answer;
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+# fileName: The name of the output config file given by the input config file
+#
+# Loops through an input config file and determines answers to each question using getField
+# and returns the hash of answers
+
+sub getConfig {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %config;
+
+ if ( !defined $userInput->{$fileName} ) {
+ logger( "No $fileName found in config", "error" );
+ }
+
+ 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 );
+
+ $config{ $var->{"config_var"} } = $answer;
+ if ( !$hidden ) {
+ logger( "$question: $answer", "info" );
+ }
+ }
+ return %config;
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+# dbFileName: The filename of the output config file for the database
+# toDBFileName: The filename of the output config file for the Traffic Ops database
+#
+# Generates a config file for the database based on the questions and answers in the input config file
+
+sub generateDbConf {
+ my $userInput = shift;
+ my $dbFileName = shift;
+ my $toDBFileName = shift;
+
+ my %dbconf = getConfig( $userInput, $dbFileName );
+
+ make_path( dirname($dbFileName), { mode => 0755 } );
+ writeJson( $dbFileName, \%dbconf );
+ logger( "Database configuration has been saved", "info" );
+
+ # broken out into separate file/config area
+ 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!");
+ print $fh "version: 1.0\n";
+ print $fh "name: dbconf.yml\n\n";
+ print $fh "production:\n";
+ print $fh " driver: ", getDbDriver() . "\n";
+ print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{user}/$dbconf{password}\n";
+ close $fh;
+
+ return \%todbconf;
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+# fileName: The filename of the output config file
+#
+# Generates a config file for the CDN
+
+sub generateCdnConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %cdnConfiguration = getConfig( $userInput, $fileName );
+
+ # 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: $@");
+ }
+ if ( lc $cdnConfiguration{genSecret} =~ /^y(?:es)?/ ) {
+ my @secrets = @{ $cdnConf->{secrets} };
+ my $newSecret = randomWord();
+ unshift @secrets, randomWord();
+ if ( $cdnConfiguration{keepSecrets} > 0
+ && $#secrets > $cdnConfiguration{keepSecrets} - 1 )
+ {
+
+ # Shorten the array to requested length
+ $#secrets = $cdnConfiguration{keepSecrets} - 1;
+ }
+ }
+ writePerl( $fileName, $cdnConf );
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+# fileName: The filename of the output config file
+#
+# Generates an LDAP config file
+
+sub generateLdapConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my $useLdap = $userInput->{$fileName}[0]->{"Do you want to set up LDAP?"};
+
+ if ( $useLdap eq "no" || $useLdap eq "n" ) {
+ logger( "Not setting up ldap", "info" );
+
+ return;
+ }
+
+ my %ldapConf = getConfig( $userInput, $fileName );
+
+ make_path( dirname($fileName), { mode => 0755 } );
+ writeJson( $fileName, \%ldapConf );
+}
+
+sub generateUsersConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %user = ();
+ my %config = getConfig( $userInput, $fileName );
+
+ $user{username} = $config{tmAdminUser};
+ $user{password} = sha1_hex( $config{tmAdminPw} );
+
+ writeJson( $fileName, \%user );
+ $user{password} = $config{tmAdminPw};
+ return \%user;
+}
+
+sub generateProfilesDir {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my $userIn = $userInput->{$fileName};
+}
+
+sub generateOpenSSLConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ if ( !defined $userInput->{$fileName} ) {
+ logger( "No OpenSSL Configuration - questions will be asked", "info" );
+ writeJson( $fileName, my %emptyConfig );
+ return;
+ }
+
+ my %config = getConfig( $userInput, $fileName );
+
+ writeJson( $fileName, \%config );
+}
+
+sub generateParamConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %config = getConfig( $userInput, $fileName );
+ return \%config;
+}
+
+# check default values for missing config_var parameter
+sub sanityCheckDefaults {
+ foreach my $file ( ( keys $::defaultInputs ) ) {
+ foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
+ my $question = getConfigQuestion($defaultValue);
+
+ if ( !defined $defaultValue->{"config_var"}
+ || $defaultValue->{"config_var"} eq "" )
+ {
+ errorOut( "Question \'$question\' in file \'$file\' has no config_var" );
+ }
+ }
+ }
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+#
+# Checks the input config file against the default inputs. If there is a question located in the default inputs which
+# is not located in the input config file it will output a warning message.
+#
+# This does not check the other way meaning questions which are present in defaults but not present in the input config
+# file will not be checked
+
+sub sanityCheckConfig {
+ my $userInput = shift;
+ my $diffs = 0;
+
+ foreach my $file ( ( keys $::defaultInputs ) ) {
+ if ( !defined $userInput->{$file} ) {
+ logger( "File \'$file\' found in defaults but not config file", "warn" );
+ $userInput->{$file} = [];
+ }
+
+ foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
+
+ my $found = 0;
+ foreach my $configValue ( @{ $userInput->{$file} } ) {
+ if ( $defaultValue->{"config_var"} eq $configValue->{"config_var"} ) {
+ $found = 1;
+ }
+ }
+
+ # 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);
+
+ my %temp;
+
+ # 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}
+ );
+ }
+
+ # 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"} )
+ {
+ $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
+ );
+ }
+ }
+ push $userInput->{$file}, \%temp;
+
+ $diffs++;
+ }
+ }
+ }
+
+ 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 );
+}
+
+# A function which returns the default inputs data structure. These questions and answers will be used if there is no
+# user input config file or if there are questions in the input config file which do not have answers
+
+sub getDefaults {
+ return {
+ $::databaseConfFile => [
+ {
+ "Database type" => "mysql",
+ "config_var" => "type",
+ },
+ {
+ "Database name" => "traffic_ops",
+ "config_var" => "dbname",
+ },
+ {
+ "Database server hostname IP or FQDN" => "localhost",
+ "config_var" => "hostname",
+ },
+ {
+ "Database port number" => "3306",
+ "config_var" => "port"
+ },
+ {
+ "Traffic Ops database user" => "traffic_ops",
+ "config_var" => "user"
+ },
+ {
+ "Password for Traffic Ops database user" => "",
+ "config_var" => "password",
+ "hidden" => "true"
+ }
+ ],
+ $::dbConfFile => [
+ {
+ "Database server root (admin) user" => "root",
+ "config_var" => "dbAdminUser"
+ },
+ {
+ "Password for database server admin" => "",
+ "config_var" => "dbAdminPw",
+ "hidden" => "true"
+ }
+ ],
+ $::cdnConfFile => [
+ {
+ "Generate a new secret?" => "yes",
+ "config_var" => "genSecret"
+ },
+ {
+ "Number of secrets to keep?" => "10",
+ "config_var" => "keepSecrets"
+ }
+ ],
+ $::ldapConfFile => [
+ {
+ "Do you want to set up LDAP?" => "no",
+ "config_var" => "setupLdap"
+ },
+ {
+ "LDAP server hostname" => "",
+ "config_var" => "hostname"
+ },
+ {
+ "LDAP Admin DN" => "",
+ "config_var" => "admin_dn"
+ },
+ {
+ "LDAP Admin Password" => "",
+ "config_var" => "password",
+ "hidden" => "true"
+ },
+ {
+ "LDAP Search Base" => "",
+ "config_var" => "search_base"
+ }
+ ],
+ $::usersConfFile => [
+ {
+ "Administration username for Traffic Ops" => "admin",
+ "config_var" => "tmAdminUser"
+ },
+ {
+ "Password for the admin user" => "",
+ "config_var" => "tmAdminPw",
+ "hidden" => "true"
+ }
+ ],
+ $::profilesConfFile => [],
+ $::opensslConfFile => [
+ {
+ "Country Name (2 letter code)" => "XX",
+ "config_var" => "country"
+ },
+ {
+ "State or Province Name (full name)" => "San Jose",
+ "config_var" => "state"
+ },
+ {
+ "Locality Name (eg, city)" => "Default City",
+ "config_var" => "locality"
+ },
+ {
+ "Organization Name (eg, company)" => "Default Company Ltd",
+ "config_var" => "company"
+ },
+ {
+ "Organizational Unit Name (eg, section)" => "",
+ "config_var" => "org_unit"
+ },
+ {
+ "Common Name (eg, your name or your server's hostname)" => "cisco.com",
+ "config_var" => "common_name"
+ },
+ {
+ "RSA Passphrase" => "",
+ "config_var" => "rsaPassword",
+ "hidden" => "true"
+ }
+ ],
+ $::paramConfFile = [
+ {
+ "Traffic Ops url" => "https://localhost",
+ "config_var" => "tm.url"
+ },
+ {
+ "Human-readable CDN Name. (No whitespace, please)" => "kabletown_cdn",
+ "config_var" => "cdn_name"
+ },
+ {
+ "Health Polling Interval (milliseconds)" => "8000",
+ "config_var" => "health_polling_int"
+ },
+ {
+ "DNS sub-domain for which your CDN is authoritative" => "cdn1.kabletown.net",
+ "config_var" => "dns_subdomain"
+ },
+ {
+ "TLD SOA admin" => "traffic_ops",
+ "config_var" => "soa_admin"
+ },
+ {
+ "TrafficServer Drive Prefix" => "/dev/sd",
+ "config_var" => "driver_prefix"
+ },
+ {
+ "TrafficServer RAM Drive Prefix" => "/dev/ram",
+ "config_var" => "ram_drive_prefix"
+ },
+ {
+ "TrafficServer RAM Drive Letters (comma separated)" => "0,1,2,3,4,5,6,7",
+ "config_var" => "ram_drive_letters"
+ },
+ {
+ "Health Threshold Load Average" => "25",
+ "config_var" => "health_thresh_load_avg"
+ },
+ {
+ "Health Threshold Available Bandwidth in Kbps" => "1750000",
+ "config_var" => "health_thresh_kbps"
+ },
+ {
+ "Traffic Server Health Connection Timeout (milliseconds)" => "2000",
+ "config_var" => "health_connect_timeout"
+ }
+
+ ]
+ };
+}
+
+sub setupDatabase {
+ my $todbconf = shift;
+ my $opensslconf = shift;
+
+ #
+ # Call mysql initialization script.
+ #
+ logger( "Creating database with user: $todbconf->{dbAdminUser}", "info" );
+ my $result = execCommand( "/opt/traffic_ops/install/bin/create_db", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
+ if ( $result != 0 ) {
+ errorOut("Failed to create the database");
+ }
+
+ logger( "Setting up database", "info" );
+ chdir("/opt/traffic_ops/app");
+ $result = execCommand( "/usr/bin/perl", "db/admin.pl", "--env=production", "setup" );
+
+ if ( $result != 0 ) {
+ errorOut("Database initialization failed");
+ }
+ else {
+ logger( "Database initialization succeeded", "info" );
+ }
+
+ $result = execCommand( "/opt/traffic_ops/install/bin/dataload", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
+ if ( $result != 0 ) {
+ logger( "Failed to load seed data", "error" );
+ }
+
+ 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" );
+ if ( $result != 0 ) {
+ logger( "Failed to download MaxMind data", "error" );
+ }
+
+ logger( "Copying coverage zone file to public dir", "info" );
+ $result = execCommand("/bin/mv /opt/traffic_ops/app/public/coverage-zone.json .");
+ if ( $result != 0 ) {
+ logger( "Failed to copy coverage zone file", "error" );
+ }
+
+ if ( -x "/usr/bin/openssl" ) {
+ logger( "Installing SSL Certificates", "info" );
+ $result = GenerateCert::createCert($opensslconf);
+
+ if ( $result != 0 ) {
+ errorOut("SSL Certificate Installation failed");
+ }
+ else {
+ logger( "SSL Certificates have been installed", "info" );
+ }
+ }
+ else {
+ logger( "Unable to install SSL certificates as openssl is not installed", "error" );
+ logger( "Install openssl and then run /opt/traffic_ops/install/bin/generateCert to install SSL certificates", "error" );
+ exit 4;
+ }
+
+}
+
+# -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
+
+sub main {
+ our $inputFile = "";
+ our $automatic = 0;
+ our $debug = 0;
+ my $help = 0;
+
+ my $usageString = "Usage: postinstall [-a] [-d] -cfile=[config_file]\n";
+
+ GetOptions(
+ "cfile=s" => \$inputFile,
+ "automatic" => \$automatic,
+ "reconfigure" => \$reconfigure,
+ "defaults" => \$dumpDefaults,
+ "debug" => \$debug,
+ "help" => \$help
+ ) or die($usageString);
+
+ # stores the default questions and answers
+ our $defaultInputs = getDefaults();
+
+ if ($help) {
+ print $usageString;
+ exit(0);
+ }
+
+ if ( $ENV{USER} ne "root" ) {
+ errorOut("You must run this script as the root user");
+ }
+
+ logger( "Starting postinstall", "info" );
+
+ if ($::debug) {
+ logger( "Debug is on", "info" );
+ }
+
+ if ($::automatic) {
+ logger( "Running in automatic mode", "info" );
+ }
+
+ if ( -f $reconfigure_file ) {
+ logger( "$reconfigure_file file is reprecated - please remove and rerun postinstall", "error" );
+ exit(-1);
+ }
+
+ if ($dumpDefaults) {
+ logger( "Writing default configuration file to $outputConfigFile", "info" );
+ writeJson( $outputConfigFile, $::defaultInputs );
+ exit(0);
+ }
+
+ if ($reconfigure) {
+ logger( "Postinstall is in reconfigure mode", "info" );
+ }
+ else {
+ logger( "Postinstall not in reconfigure mode", "info" );
+ }
+
+ # check if the user has root access
+ if ( $ENV{USER} ne "root" ) {
+ errorOut("You must run this script as the root user");
+ }
+
+ rotateLog($cpanLogFile);
+
+ if ( -s $::logFile > $maxLogSize ) {
+ logger( "Postinstall log above max size of $maxLogSize bytes - rotating", "info" );
+ rotateLog($logFile);
+ }
+
+ # used to store the questions and answers provided by the user
+ my $userInput;
+
+ # if no input file provided use the defaults
+ if ( $::inputFile eq "" ) {
+ logger( "No input file given - using defaults", "info" );
+ $userInput = $::defaultInputs;
+ }
+ else {
+ logger( "Using input file $::inputFile", "info" );
+
+ # check if the input file exists
+ errorOut("File \'$::inputFile\' not found") if ( !-f $::inputFile );
+
+ # read and store the input file
+ $userInput = readJson($::inputFile);
+ }
+
+ # sanity check the defaults if running them automatically
+ sanityCheckDefaults();
+
+ # check the input config file against the defaults to check for missing questions
+ sanityCheckConfig($userInput) if ( $inputFile ne "" );
+
+ chdir("/opt/traffic_ops/install/bin");
+
+ # if the reconfigure file exists or reconfigure is set then rebuild the perl deps
+ 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" );
+ }
+ $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" );
+ }
+ }
+ 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" );
+ }
+ $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" );
+ }
+ }
+
+ # The generator functions handle checking input/default/automatic mode
+
+ # todbconf will be used later when setting up the database
+ my $todbconf = generateDbConf( $userInput, $::databaseConfFile, $::dbConfFile );
+ generateCdnConf( $userInput, $::cdnConfFile );
+ generateLdapConf( $userInput, $::ldapConfFile );
+ my $adminconf = generateUsersConf( $userInput, $::usersConfFile );
+ generateProfilesDir( $userInput, $::profilesConfFile );
+ generateOpenSSLConf( $userInput, $::opensslConfFile );
+ my $paramconf = generateParamConf( $userInput, $::paramConfFile );
+
+ # if the reconfigure file exists or the reconfigure command line arg is set then setup the database
+ if ( -f $reconfigure_file || $reconfigure ) {
+ if ($::automatic) {
+ setupDatabase( $todbconf, $::opensslConfFile );
+ }
+ else {
+ setupDatabase( $todbconf, 0 );
+ }
+ }
+
+ # remove the reconfigure file if it exists
+ if ( -f $reconfigure_file ) {
+ logger( "Removing reconfigure file", "info" );
+ unlink($reconfigure_file);
+ }
+
+ logger( "Starting Traffic Ops", "info" );
+ execCommand("/sbin/service traffic_ops start");
+
+ 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"} );
+ import_profiles($adminconf);
+ profiles_exist($adminconf); # call again to create $reconfigure_defaults file if import was successful
+ }
+ else {
+ print "Not creating default profiles.\n";
+ }
+}
+
+main;
+
+logger( "Postinstall complete\n", "info" );
+
+# vi:syntax=perl
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/bae43757/traffic_ops/install/lib/BuildPerlDeps.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/BuildPerlDeps.pm b/traffic_ops/install/lib/BuildPerlDeps.pm
new file mode 100644
index 0000000..302d5c3
--- /dev/null
+++ b/traffic_ops/install/lib/BuildPerlDeps.pm
@@ -0,0 +1,99 @@
+#!/usr/bin/perl
+#
+# Copyright 2015 Comcast Cable Communications Management, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/lib/perl5 /opt/traffic_ops/app/lib);
+
+package BuildPerlDeps;
+
+use InstallUtils qw{ :all };
+
+use base qw{ Exporter };
+our @EXPORT_OK = qw{ build };
+our %EXPORT_TAGS = ( all => \@EXPORT_OK );
+
+sub build {
+ my $opt_i = shift;
+
+ my @dependencies = ( "expat-devel", "mod_ssl", "mkisofs", "libpcap", "libpcap-devel", "libcurl", "libcurl-devel", "mysql-server", "mysql-devel", "openssl", "openssl-devel", "cpan", "gcc", "make", "pkgconfig", "automake", "autoconf", "libtool", "gettext", "libidn-devel" );
+
+ my $msg = << 'EOF';
+
+This script will build and package the required Traffic Ops perl modules.
+In order to complete this operation, Development tools such as the gcc
+compiler will be installed on this machine.
+
+EOF
+
+ $ENV{PERL_MM_USE_DEFAULT} = 1;
+ $ENV{PERL_MM_NONINTERACTIVE} = 1;
+ $ENV{AUTOMATED_TESTING} = 1;
+
+ my $result;
+
+ if ( $ENV{USER} ne "root" ) {
+ errorOut("You must run this script as the root user");
+ }
+
+ logger( $msg, "info" );
+
+ chdir("/opt/traffic_ops/app");
+
+ if ( defined $opt_i && $opt_i == 1 ) {
+ if ( !-x "/usr/bin/yum" ) {
+ errorOut("You must install 'yum'");
+ }
+
+ logger( "Installing dependencies", "info" );
+ $result = execCommand( "/usr/bin/yum", "install", @dependencies );
+ if ( $result != 0 ) {
+ errorOut("Dependency installation failed, look through the output and correct the problem");
+ }
+ logger( "Building perl modules", "info" );
+
+ $result = execCommand( "/opt/traffic_ops/install/bin/cpan.sh", "pi_custom_log=" . $::cpanLogFile, "/opt/traffic_ops/install/bin/yaml.txt" );
+ if ( $result != 0 ) {
+ errorOut("Failed to install YAML, look through the output and correct the problem");
+ }
+
+ $result = execCommand( "/opt/traffic_ops/install/bin/cpan.sh", "pi_custom_log=" . $::cpanLogFile, "/opt/traffic_ops/install/bin/carton.txt" );
+ if ( $result != 0 ) {
+ errorOut("Failed to install Carton, look through the output and correct the problem");
+ }
+ }
+
+ $result = execCommand( "/usr/local/bin/carton", "install", "--deployment", "--cached" );
+ if ( $result != 0 ) {
+ errorOut("Failure to build required perl modules, check the output and correct the problem");
+ }
+
+ if ( !-s "/opt/traffic_ops/lib/perl5" ) {
+ logger( "Linking perl libraries...", "info" );
+ if ( !-d "/opt/traffic_ops/lib" ) {
+ mkdir("/opt/traffic_ops/lib");
+ }
+ symlink( "/opt/traffic_ops/app/local/lib/perl5", "/opt/traffic_ops/lib/perl5" );
+ execCommand( "/bin/chown", "-R", "trafops:trafops", "/opt/traffic_ops/lib" );
+ }
+ logger( "Installing perl scripts", "info" );
+ chdir("/opt/traffic_ops/app/local/bin");
+ my $rc = execCommand( "/bin/cp", "-R", ".", "/opt/traffic_ops/app/bin" );
+ if ( $rc != 0 ) {
+ logger( "Failed to copy perl scripts to /opt/traffic_ops/app/bin", "error" );
+ }
+
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/bae43757/traffic_ops/install/lib/GenerateCert.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/GenerateCert.pm b/traffic_ops/install/lib/GenerateCert.pm
new file mode 100644
index 0000000..efdcc96
--- /dev/null
+++ b/traffic_ops/install/lib/GenerateCert.pm
@@ -0,0 +1,232 @@
+#!/usr/bin/perl
+
+#
+# Copyright 2015 Comcast Cable Communications Management, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+package GenerateCert;
+
+use strict;
+
+use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/lib/perl5 /opt/traffic_ops/app/lib);
+
+use base qw{ Exporter };
+our @EXPORT_OK = qw{ createCert };
+our %EXPORT_TAGS = ( all => \@EXPORT_OK );
+
+use JSON;
+use InstallUtils;
+use File::Temp;
+use Data::Dumper;
+use File::Copy;
+use InstallUtils qw{ :all };
+
+my $ca = "/etc/pki/tls/certs/localhost.ca";
+my $csr = "/etc/pki/tls/certs/localhost.csr";
+my $cert = "/etc/pki/tls/certs/localhost.crt";
+my $cdn_conf = "/opt/traffic_ops/app/conf/cdn.conf";
+my $key = "/etc/pki/tls/private/localhost.key";
+my $msg = << 'EOF';
+
+ We're now running a script to generate a self signed X509 SSL certificate.
+
+EOF
+
+sub writeCdn_conf {
+ my $cdn_conf = shift;
+
+ # listen param to be inserted
+ my $listen_str = "https://[::]:443?cert=${cert}&key=${key}&ca=${ca}&verify=0x00&ciphers=AES128-GCM-SHA256:HIGH:!RC4:!MD5:!aNULL:!EDH:!ED";
+
+ # load as perl hash to find string to be replaced
+ my $cdnh = do $cdn_conf;
+ if ( exists $cdnh->{hypnotoad} ) {
+ $cdnh->{hypnotoad}{listen} = [$listen_str];
+ }
+ else {
+
+ # add the whole hypnotoad config without affecting anything else in the config
+ $cdnh->{hypnotoad} = {
+ listen => [$listen_str],
+ user => 'trafops',
+ group => 'trafops',
+ pid_file => '/var/run/traffic_ops.pid',
+ workers => 48,
+ };
+ }
+
+ # dump conf data in compact but readable form
+ my $dumper = Data::Dumper->new( [$cdnh] );
+ $dumper->Indent(1)->Terse(1)->Quotekeys(0);
+
+ # write whole config to temp file in pwd (keeps in same filesystem)
+ my $tmpfile = File::Temp->new( DIR => '.' );
+ print $tmpfile $dumper->Dump();
+ close $tmpfile;
+
+ # make backup of current file
+ my $backup_num = 0;
+ my $backup_name;
+ do {
+ $backup_num++;
+ $backup_name = "$cdn_conf.backup$backup_num";
+ } while ( -e $backup_name );
+ rename( $cdn_conf, $backup_name ) or die("rename(): $!");
+
+ # rename temp file to cdn.conf and set ownership/permissions same as backup
+ my @stats = stat($backup_name);
+ my ( $uid, $gid, $perm ) = @stats[ 4, 5, 2 ];
+ move( "$tmpfile", $cdn_conf ) or die("move(): $!");
+
+ chown $uid, $gid, $cdn_conf;
+ chmod $perm, $cdn_conf;
+}
+
+# execOpenssl takes a description of the command being done, and an array of arguments to OpenSSL,
+# and tries to execute the command, on failure prompting the user to retry.
+# The description should be capitalized, but not terminated with punctuation.
+# Returns the OpenSSL exit code.
+sub execOpenssl {
+ my ( $description, @args ) = @_;
+ logger( $description, "info" );
+ my $result = 1;
+ while ( $result != 0 ) {
+ $result = InstallUtils::execCommand( "openssl", @args );
+ if ( $result != 0 ) {
+ my $ans = "";
+ while ( $ans !~ /^[yY]/ && $ans !~ /^[nN]/ ) {
+ $ans = InstallUtils::promptUser( $description . " failed. Try again (y/n)", "y" );
+ }
+ if ( $ans =~ /^[nN]/ ) {
+ return $result;
+ }
+ }
+ }
+ return $result;
+}
+
+sub createCert {
+
+ # the file used for ssl configuration
+ my $opensslconf = shift;
+
+ if ( !defined $opensslconf ) {
+ logger( "No input file - running openssl configuration in interactive mode", "info" );
+ }
+
+ logger( $msg, "info" );
+
+ logger( "Postinstall SSL Certificate Creation", "info" );
+
+ my $params;
+ my $passphrase;
+
+ # load the parameters for the certificate
+ if ( defined $opensslconf ) {
+ my $config = InstallUtils::readJson($opensslconf);
+ if ( defined $config->{country} ) {
+
+ # the parameters to auto generate the certificate
+ $params = "/C=$config->{country}/ST=$config->{state}/L=$config->{locality}/O=$config->{company}/OU=$config->{org_unit}/CN=$config->{common_name}/";
+
+ $passphrase = $config->{rsaPassword};
+ }
+ }
+
+ if ( execOpenssl( "Generating an RSA Private Server Key", "genrsa", "-des3", "-out", "server.key", "-passout", "pass:$passphrase", "1024" ) != 0 ) {
+ exit 1;
+ }
+ logger( "The server key has been generated", "info" );
+
+ if ($params) {
+ if ( execOpenssl( "Creating a Certificate Signing Request (CSR)", "req", "-new", "-key", "server.key", "-out", "server.csr", "-passin", "pass:$passphrase", "-subj", $params ) != 0 ) {
+ exit 1;
+ }
+ }
+ else {
+ if ( execOpenssl( "Creating a Certificate Signing Request (CSR)", "req", "-new", "-key", "server.key", "-out", "server.csr", "-passin", "pass:$passphrase" ) != 0 ) {
+ exit 1;
+ }
+ }
+
+ logger( "The Certificate Signing Request has been generated", "info" );
+
+ InstallUtils::execCommand( "/bin/mv", "server.key", "server.key.orig" );
+
+ if ( execOpenssl( "Removing the pass phrase from the server key", "rsa", "-in", "server.key.orig", "-out", "server.key", "-passin", "pass:$passphrase" ) != 0 ) {
+ exit 1;
+ }
+ logger( "The pass phrase has been removed from the server key", "info" );
+
+ if ( execOpenssl( "Generating a Self-signed certificate", "x509", "-req", "-days", "365", "-in", "server.csr", "-signkey", "server.key", "-out", "server.crt" ) != 0 ) {
+ exit 1;
+ }
+ logger( "A server key and self signed certificate has been generated", "info" );
+
+ logger( "Installing the server key and server certificate", "info" );
+
+ my $result = InstallUtils::execCommand( "/bin/cp", "server.key", "$key" );
+ if ( $result != 0 ) {
+ errorOut("Failed to install the private server key");
+ }
+ $result = InstallUtils::execCommand( "/bin/chmod", "600", "$key" );
+ $result = InstallUtils::execCommand( "/bin/chown", "trafops:trafops", "$key" );
+
+ if ( $result != 0 ) {
+ errorOut("Failed to install the private server key");
+ }
+
+ logger( "The private key has been installed", "info" );
+ logger( "Installing the self signed certificate", "info" );
+
+ $result = InstallUtils::execCommand( "/bin/cp", "server.crt", "$cert" );
+
+ if ( $result != 0 ) {
+ errorOut("Failed to install the self signed certificate");
+ }
+
+ $result = InstallUtils::execCommand( "/bin/chmod", "600", "$cert" );
+ $result = InstallUtils::execCommand( "/bin/chown", "trafops:trafops", "$cert" );
+
+ if ( $result != 0 ) {
+ errorOut("Failed to install the self signed certificate");
+ }
+
+ logger( "Saving the self signed csr", "info" );
+ $result = InstallUtils::execCommand( "/bin/cp", "server.csr", "$csr" );
+
+ if ( $result != 0 ) {
+ errorOut("Failed to save the self signed csr");
+ }
+ $result = InstallUtils::execCommand( "/bin/chmod", "664", "$csr" );
+ $result = InstallUtils::execCommand( "/bin/chown", "trafops:trafops", "$csr" );
+
+ writeCdn_conf($cdn_conf);
+
+ my $msg = << 'EOF';
+
+ The self signed certificate has now been installed.
+
+ You may obtain a certificate signed by a Certificate Authority using the
+ server.csr file saved in the current directory. Once you have obtained
+ a signed certificate, copy it to /etc/pki/tls/certs/localhost.crt and
+ restart Traffic Ops.
+
+EOF
+
+ logger( $msg, "info" );
+
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/bae43757/traffic_ops/install/lib/InstallUtils.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/InstallUtils.pm b/traffic_ops/install/lib/InstallUtils.pm
index 4d45e7d..72665d1 100644
--- a/traffic_ops/install/lib/InstallUtils.pm
+++ b/traffic_ops/install/lib/InstallUtils.pm
@@ -24,126 +24,216 @@ package InstallUtils;
use Term::ReadPassword;
+use JSON;
+use IO::Pipe;
use base qw{ Exporter };
-our @EXPORT_OK = qw{ execCommand randomWord promptUser promptRequired promptPassword promptPasswordVerify trim readJson writeJson writePerl};
+our @EXPORT_OK = qw{ execCommand randomWord promptUser promptRequired promptPassword promptPasswordVerify trim readJson writeJson writePerl errorOut logger rotateLog};
our %EXPORT_TAGS = ( all => \@EXPORT_OK );
sub execCommand {
- my ( $cmd, @args ) = @_;
- system( $cmd, @args );
- my $result = $? >> 8;
- return $result;
+ my ( $command, @args ) = @_;
+
+ my $pipe = IO::Pipe->new;
+ my $pid;
+ my $result = 0;
+ my $customLog = "";
+
+ # find log file in args and remove if found
+ # TODO: More documentation here
+ foreach my $var (@args) {
+ if ( index($var, "pi_custom_log=") != -1 ) {
+ $customLog = (split(/=/, $var))[1];
+ splice(@args, index($var, "pi_custom_log="), 1);
+ logger("Using custom log \'$customLog\'", "info");
+ }
+ }
+
+ # create pipe between child and parent and redirect output from child to parent for logging
+ my $child = open READER, '-|';
+ defined $child or die "pipe/fork: $!\n";
+ if ($child) { #parent
+ while ( $line = <READER> ) {
+ # log all output from child pipe
+ if ($customLog ne "") {
+ logger($line, "info", $customLog);
+ }
+ else {
+ logger($line, "info");
+ }
+ }
+ }
+ else { #child
+ # redirect stderr to stdout so parent can read
+ open STDERR, '>&STDOUT';
+ exec($command, @args) or exit(1);
+ }
+}
+
+sub errorOut {
+ logger( @_, "error" );
+ die;
+}
+
+# moves a log to file to a backup file with the same name appended with .bkp
+# This function is intended to keep log file sizes low and is called from postinstall
+sub rotateLog {
+ my $logFileName = shift;
+
+ if ( !-f $logFileName ) {
+ logger("Log file \'$logFileName\' does not exist - not rotating log", "error");
+ return;
+ }
+
+ execCommand('/bin/mv', '-f', $logFileName, $logFileName . '.bkp');
+ logger("Rotated log $logFileName", "info");
+}
+
+# outputs logging messages to terminal and log file
+sub logger {
+ my $output = shift;
+ my $type = shift;
+
+ # optional custom log file to use instead of main log file used by postinstall
+ # cpan uses a custom log file because of its size
+ my $customLogFile = shift;
+
+ my $message = $output;
+ if (index($message, "\n") == -1) {
+ $message = $message . "\n";
+ }
+
+ # if in debug mode or message is more critical than info print to console
+ if ( $::debug || ( defined $type && $type ne "" && $type ne "info" ) ) {
+ print($message);
+ }
+
+ # output to log file
+ my $fh;
+ my $result = 0;
+ if ( defined $customLogFile && $customLogFile ne "" ) {
+ open $fh, '>>', $customLogFile or die("Couldn't open log file \'$::customLogFile\'");
+ $result = 1;
+ }
+ else {
+ if ($::logFile) {
+ open $fh, '>>', $::logFile or die("Couldn't open log file \'$::logFile\'");
+ $result = 1;
+ }
+ }
+
+ if ( $result ) {
+ print $fh localtime . ": " . uc($type) . ' ' . $message;
+ close $fh;
+ }
}
sub randomWord {
- my $length = shift || 12;
- my $secret = '';
- while ( length($secret) < $length ) {
- my $c = chr( rand(0x7F) );
- if ( $c =~ /\w/ ) {
- $secret .= $c;
- }
- }
- return $secret;
+ my $length = shift || 12;
+ my $secret = '';
+ while ( length($secret) < $length ) {
+ my $c = chr( rand(0x7F) );
+ if ( $c =~ /\w/ ) {
+ $secret .= $c;
+ }
+ }
+ return $secret;
}
sub promptUser {
- my ( $promptString, $defaultValue, $noEcho ) = @_;
-
- if ($defaultValue) {
- print $promptString, " [", $defaultValue, "]: ";
- }
- else {
- print $promptString, ": ";
- }
-
- if ( defined $noEcho && $noEcho ) {
- my $response = read_password('');
- if ( ( !defined $response || $response eq '' ) && ( defined $defaultValue && $defaultValue ne '' ) ) {
- $response = $defaultValue;
- }
- return $response;
- }
- else {
- $| = 1;
- $_ = <STDIN>;
- chomp;
-
- if ("$defaultValue") {
- return $_ ? $_ : $defaultValue;
- }
- else {
- return $_;
- }
- return $_;
- }
+ my ( $promptString, $defaultValue, $noEcho ) = @_;
+
+ if ($defaultValue) {
+ print $promptString, " [", $defaultValue, "]: ";
+ }
+ else {
+ print $promptString, ": ";
+ }
+
+ if ( defined $noEcho && $noEcho ) {
+ my $response = read_password('');
+ if ( ( !defined $response || $response eq '' ) && ( defined $defaultValue && $defaultValue ne '' ) ) {
+ $response = $defaultValue;
+ }
+ return $response;
+ }
+ else {
+ $| = 1;
+ $_ = <STDIN>;
+ chomp;
+
+ if ("$defaultValue") {
+ return $_ ? $_ : $defaultValue;
+ }
+ else {
+ return $_;
+ }
+ return $_;
+ }
}
sub promptRequired {
- my $val = '';
- while ( length($val) == 0 ) {
- $val = promptUser(@_);
- }
- return $val;
+ my $val = '';
+ while ( length($val) == 0 ) {
+ $val = promptUser(@_);
+ }
+ return $val;
}
sub promptPassword {
- my $prompt = shift;
- my $pw = promptRequired( $prompt, '', 1 );
- return $pw;
+ my $prompt = shift;
+ my $pw = promptRequired( $prompt, '', 1 );
+ return $pw;
}
sub promptPasswordVerify {
- my $prompt = shift;
- my $pw = shift;
-
- while (1) {
- $pw = promptPassword($prompt);
- my $verify = promptPassword("Re-Enter $prompt");
- last if $pw eq $verify;
- print "\nError: passwords do not match, try again.\n\n";
- }
- return $pw;
+ my $prompt = shift;
+ my $pw = shift;
+
+ while (1) {
+ $pw = promptPassword($prompt);
+ my $verify = promptPassword("Re-Enter $prompt");
+ last if $pw eq $verify;
+ print "\nError: passwords do not match, try again.\n\n";
+ }
+ return $pw;
}
sub trim {
- my $str = shift;
+ my $str = shift;
- $str =~ s/^\s+//;
- $str =~ s/^\s+$//;
+ $str =~ s/^\s+//;
+ $str =~ s/^\s+$//;
- return $str;
+ return $str;
}
sub readJson {
- my $file = shift;
- open( my $fh, '<', $file ) or return;
- local $/; # slurp mode
- my $text = <$fh>;
- undef $fh;
- return JSON->new->utf8->decode($text);
+ my $file = shift;
+ open( my $fh, '<', $file ) or die("open(): $!");
+ local $/; # slurp mode
+ my $text = <$fh>;
+ undef $fh;
+ return JSON->new->utf8->decode($text);
}
sub writeJson {
- my $file = shift;
- open( my $fh, '>', $file ) or die("open(): $!");
- foreach my $data (@_) {
- my $json_text = JSON->new->utf8->pretty->encode($data);
- print $fh $json_text, "\n";
- }
- close $fh;
+ my $file = shift;
+ open( my $fh, '>', $file ) or die("open(): $!");
+ foreach my $data (@_) {
+ my $json_text = JSON->new->utf8->pretty->encode($data);
+ print $fh $json_text, "\n";
+ }
+ close $fh;
}
sub writePerl {
- my $file = shift;
- my $data = shift;
-
- open( my $fh, '>', $file ) or die("open(): $!");
- my $dumper = Data::Dumper->new([ $data ]);
-
- # print without var names and with simple indentation
- print $fh $dumper->Terse(1)->Dump();
- close $fh;
-}
+ my $file = shift;
+ my $data = shift;
-1;
+ open( my $fh, '>', $file ) or die("open(): $!");
+ my $dumper = Data::Dumper->new( [$data] );
+
+ # print without var names and with simple indentation
+ print $fh $dumper->Terse(1)->Dump();
+ close $fh;
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/bae43757/traffic_ops/install/lib/ProfileCleanup.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/ProfileCleanup.pm b/traffic_ops/install/lib/ProfileCleanup.pm
new file mode 100644
index 0000000..3606002
--- /dev/null
+++ b/traffic_ops/install/lib/ProfileCleanup.pm
@@ -0,0 +1,192 @@
+
+package ProfileCleanup;
+
+use InstallUtils qw{ :all };
+use WWW::Curl::Easy;
+use LWP::UserAgent;
+
+use base qw{ Exporter };
+our @EXPORT_OK = qw{ replace_profile_templates import_profiles profiles_exist };
+our %EXPORT_TAGS = ( all => \@EXPORT_OK );
+
+sub profile_replace {
+ my ($profile) = @_;
+ my $profile_bak = $profile . ".bak";
+ rename( $profile, $profile_bak ) or die("rename(): $!");
+ open( my $fh, '<', $profile_bak ) or die("open(): $!");
+ open( my $ofh, '>', $profile ) or die("open(): $!");
+ while (<$fh>) {
+ s/{{.TmUrl}}/$::parameters->{'tm.url'}/g;
+ s/{{.TmInfoUrl}}/$::parameters->{"tminfo.url"}/g;
+ s/{{.TmInstanceName}}/$::parameters->{"cdnname"}/g;
+ s/{{.GeolocationPollingUrl}}/$::parameters->{"geolocation.polling.url"}/g;
+ s/{{.Geolocation6PollingUrl}}/$::parameters->{"geolocation6.polling.url"}/g;
+ s/{{.TmUrl}}/$::parameters->{'tm.url'}/g;
+ s/{{.TmToolName}}/Traffic Ops/g;
+ s/{{.HealthPollingInterval}}/$::parameters->{"health.polling.interval"}/g;
+ s/{{.CoveragezonePollingUrl}}/$::parameters->{"coveragezone.polling.url"}/g;
+ s/{{.DomainName}}/$::parameters->{"domainname"}/g;
+ s/{{.TldSoaAdmin}}/$::parameters->{"tld.soa.admin"}/g;
+ s/{{.DrivePrefix}}/$::parameters->{"Drive_Prefix"}/g;
+ s/{{.HealthThresholdLoadavg}}/$::parameters->{"health.threshold.loadavg"}/g;
+ s/{{.HealthThresholdAvailableBandwidthInKbps}}/$::parameters->{"health.threshold.availableBandwidthInKbps"}/g;
+ s/{{.RAMDrivePrefix}}/$::parameters->{"RAM_Drive_Prefix"}/g;
+ s/{{.RAMDriveLetters}}/$::parameters->{"RAM_Drive_Letters"}/g;
+ s/{{.HealthConnectionTimeout}}/$::parameters->{"health.connection.timeout"}/g;
+ s#{{.CronOrtSyncds}}#*/15 * * * * root /opt/ort/traffic_ops_ort.pl syncds warn $::parameters->{'tm.url'} $tmAdminUser:$tmAdminPw > /tmp/ort/syncds.log 2>&1#g;
+ print $ofh $_;
+ }
+ close $fh;
+ close $ofh;
+ unlink $profile_bak;
+}
+
+sub replace_profile_templates {
+ my $conf = shift;
+
+ $::parameters->{'tm.url'} = $conf->{"tm.url"};
+ $::parameters->{"tminfo.url"} = "$::parameters->{'tm.url'}/info";
+ $::parameters->{"cdnname"} = $conf->{"cdn_name"};
+ $::parameters->{"geolocation.polling.url"} = "$::parameters->{'tm.url'}/routing/GeoIP2-City.mmdb.gz";
+ $::parameters->{"geolocation6.polling.url"} = "$::parameters->{'tm.url'}/routing/GeoIP2-Cityv6.mmdb.gz";
+ $::parameters->{"health.polling.interval"} = $conf->{"health_polling_int"};
+ $::parameters->{"coveragezone.polling.url"} = "$::parameters->{'tm.url'}/routing/coverage-zone.json";
+ $::parameters->{"domainname"} = $conf->{"dns_subdomain"};
+ $::parameters->{"tld.soa.admin"} = $conf->{"soa_admin"};
+ $::parameters->{"Drive_Prefix"} = $conf->{"driver_prefix"};
+ $::parameters->{"RAM_Drive_Prefix"} = $conf->{"ram_drive_prefix"};
+ $::parameters->{"RAM_Drive_Letters"} = $conf->{"ram_drive_letters"};
+ $::parameters->{"health.threshold.loadavg"} = $conf->{"health_thresh_load_avg"};
+ $::parameters->{"health.threshold.availableBandwidthInKbps"} = $conf->{"health_thresh_kbps"};
+ $::parameters->{"health.connection.timeout"} = $conf->{"health_connect_timeout"};
+
+ profile_replace( $::profile_dir . "profile.global.traffic_ops" );
+ profile_replace( $::profile_dir . "profile.traffic_monitor.traffic_ops" );
+ profile_replace( $::profile_dir . "profile.traffic_router.traffic_ops" );
+ profile_replace( $::profile_dir . "profile.trafficserver_edge.traffic_ops" );
+ profile_replace( $::profile_dir . "profile.trafficserver_mid.traffic_ops" );
+ writeJson( $::post_install_cfg, $::parameters );
+}
+
+# Takes the Traffic Ops URI, user, and password.
+# Returns the cookie, or the empty string on error
+sub get_traffic_ops_cookie {
+ my ( $uri, $user, $pass ) = @_;
+
+ my $loginUri = "/api/1.2/user/login";
+
+ my $curl = WWW::Curl::Easy->new;
+ my $response_body = "";
+ open( my $fileb, ">", \$response_body );
+ my $loginData = JSON::encode_json( { u => $user, p => $pass } );
+ $curl->setopt( WWW::Curl::Easy::CURLOPT_URL, $uri . $loginUri );
+ $curl->setopt( WWW::Curl::Easy::CURLOPT_SSL_VERIFYPEER, 0 );
+ $curl->setopt( WWW::Curl::Easy::CURLOPT_HEADER, 1 ); # include header in response
+ $curl->setopt( WWW::Curl::Easy::CURLOPT_NOBODY, 1 ); # disclude body in response
+ $curl->setopt( WWW::Curl::Easy::CURLOPT_POST, 1 );
+ $curl->setopt( WWW::Curl::Easy::CURLOPT_POSTFIELDS, $loginData );
+ $curl->setopt( WWW::Curl::Easy::CURLOPT_WRITEDATA, $fileb ); # put response in this var
+ $curl->perform();
+
+ my $cookie = $response_body;
+ if ( $cookie =~ /mojolicious=(.*); expires/ ) {
+ $cookie = $1;
+ }
+ else {
+ $cookie = "";
+ }
+ return $cookie;
+}
+
+# Takes the filename of a Traffic Ops (TO) profile to import, the TO URI, and the TO login cookie
+sub profile_import_single {
+ my ( $profileFilename, $uri, $trafficOpsCookie ) = @_;
+ logger( "Importing Profiles with: " . "curl -v -k -X POST -H \"Cookie: mojolicious=$trafficOpsCookie\" -F \"filename=$profileFilename\" -F \"profile_to_import=\@$profileFilename\" $uri/profile/doImport", "info" );
+ my $rc = execCommand("curl -v -k -X POST -H \"Cookie: mojolicious=$trafficOpsCookie\" -F \"filename=$profileFilename\" -F \"profile_to_import=\@$profileFilename\" $uri/profile/doImport");
+ if ( $rc != 0 ) {
+ logger( "Failed to import Traffic Ops profile, check the console output and rerun postinstall once you've resolved the error", "error" );
+ }
+}
+
+sub import_profiles {
+ my $config = shift;
+ logger( "Importing profiles...", "info" );
+
+ my $toUri = $::parameters->{'tm.url'};
+ my $toUser = $config->{"username"};
+ my $toPass = $config->{"password"};
+
+ my $toCookie = get_traffic_ops_cookie( $toUri, $toUser, $toPass );
+
+ logger( "Got cookie: " . $toCookie, "info" );
+
+ # \todo use an array?
+ logger( "Importing Global profile...", "info" );
+ profile_import_single( $::profile_dir . "profile.global.traffic_ops", $toUri, $toCookie );
+ logger( "Importing Traffic Monitor profile...", "info" );
+ profile_import_single( $::profile_dir . "profile.traffic_monitor.traffic_ops", $toUri, $toCookie );
+ logger( "Importing Traffic Router profile...", "info" );
+ profile_import_single( $::profile_dir . "profile.traffic_router.traffic_ops", $toUri, $toCookie );
+ logger( "Importing TrafficServer Edge profile...", "info" );
+ profile_import_single( $::profile_dir . "profile.trafficserver_edge.traffic_ops", $toUri, $toCookie );
+ logger( "Importing TrafficServer Mid profile...", "info" );
+ profile_import_single( $::profile_dir . "profile.trafficserver_mid.traffic_ops", $toUri, $toCookie );
+ logger( "Finished Importing Profiles.", "info" );
+}
+
+sub profiles_exist {
+ my $config = shift;
+ my $tmurl = shift;
+
+ if ( -f $::reconfigure_defaults ) {
+ logger( "Default profiles were previously created. Remove " . $::reconfigure_defaults . " to create again", "warn" );
+ return 1;
+ }
+
+ $::parameters->{'tm.url'} = $tmurl;
+
+ my $uri = $::parameters->{'tm.url'};
+ my $toCookie = get_traffic_ops_cookie( $::parameters->{'tm.url'}, $config->{"username"}, $config->{"password"} );
+
+ my $profileEndpoint = "/api/1.2/profiles.json";
+
+ my $ua = LWP::UserAgent->new;
+ $ua->ssl_opts( verify_hostname => 0, SSL_verify_mode => 0x00 );
+ my $req = HTTP::Request->new( GET => $uri . $profileEndpoint );
+ $req->header( 'Cookie' => "mojolicious=" . $toCookie );
+ my $resp = $ua->request($req);
+
+ if ( !$resp->is_success ) {
+ logger( "Error checking if profiles exist: " . $resp->status_line, "error" );
+ return 1; # return true, so we don't attempt to create profiles
+ }
+ my $message = $resp->decoded_content;
+
+ my $profiles = JSON->new->utf8->decode($message);
+ if ( ( !defined $profiles->{"response"} )
+ || ( ref $profiles->{"response"} ne 'ARRAY' ) )
+ {
+ logger( "Error checking if profiles exist: invalid JSON: $message", "error" );
+ return 1; # return true, so we don't attempt to create profiles
+ }
+
+ my $num_profiles = scalar( @{ $profiles->{"response"} } );
+ logger( "Existing Profile Count: $num_profiles", "info" );
+
+ my %initial_profiles = (
+ "INFLUXDB" => 1,
+ "RIAK_ALL" => 1,
+ "TRAFFIC_STATS" => 1
+ );
+
+ my $profiles_response = $profiles->{"response"};
+ foreach my $profile (@$profiles_response) {
+ if ( !exists $initial_profiles{ $profile->{"name"} } ) {
+ logger( "Found existing profile (" . $profile->{"name"} . ")", "info" );
+ open( my $reconfigure_defaults_file, '>', $::reconfigure_defaults ) or die("Failed to open() $reconfigure_defaults: $!");
+ close($reconfigure_defaults_file);
+ return 1;
+ }
+ }
+ return 0;
+}
[22/36] incubator-trafficcontrol git commit: Perltidy on all files
Posted by da...@apache.org.
Perltidy on all files
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/d665814e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/d665814e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/d665814e
Branch: refs/heads/master
Commit: d665814e939e482bcb665d076e64d9861c1804f8
Parents: ca4b10a
Author: peryder <pe...@cisco.com>
Authored: Wed Dec 7 10:18:49 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/lib/BuildPerlDeps.pm | 5 ++-
traffic_ops/install/lib/GenerateCert.pm | 1 -
traffic_ops/install/lib/InstallUtils.pm | 50 +++++++++++++-------------
traffic_ops/install/lib/ProfileCleanup.pm | 16 +--------
4 files changed, 28 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d665814e/traffic_ops/install/lib/BuildPerlDeps.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/BuildPerlDeps.pm b/traffic_ops/install/lib/BuildPerlDeps.pm
index 7c20845..e127d07 100644
--- a/traffic_ops/install/lib/BuildPerlDeps.pm
+++ b/traffic_ops/install/lib/BuildPerlDeps.pm
@@ -1,5 +1,4 @@
#!/usr/bin/perl
-
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,10 +13,10 @@
# limitations under the License.
#
-package BuildPerlDeps;
-
use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/lib/perl5 /opt/traffic_ops/app/lib);
+package BuildPerlDeps;
+
use InstallUtils qw{ :all };
use base qw{ Exporter };
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d665814e/traffic_ops/install/lib/GenerateCert.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/GenerateCert.pm b/traffic_ops/install/lib/GenerateCert.pm
index 0d4a458..8fb1a11 100644
--- a/traffic_ops/install/lib/GenerateCert.pm
+++ b/traffic_ops/install/lib/GenerateCert.pm
@@ -54,7 +54,6 @@ sub writeCdn_conf {
$cdnh->{hypnotoad}{listen} = [$listen_str];
}
else {
-
# add the whole hypnotoad config without affecting anything else in the config
$cdnh->{hypnotoad} = {
listen => [$listen_str],
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d665814e/traffic_ops/install/lib/InstallUtils.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/InstallUtils.pm b/traffic_ops/install/lib/InstallUtils.pm
index c0ad9b5..a4f0266 100644
--- a/traffic_ops/install/lib/InstallUtils.pm
+++ b/traffic_ops/install/lib/InstallUtils.pm
@@ -42,42 +42,43 @@ our @EXPORT_OK = qw{ execCommand randomWord promptUser promptRequired promptPass
our %EXPORT_TAGS = ( all => \@EXPORT_OK );
sub execCommand {
- my ( $command, @args ) = @_;
+ my ( $command, @args ) = @_;
my $pipe = IO::Pipe->new;
my $pid;
- my $result = 0;
+ my $result = 0;
my $customLog = "";
- # find log file in args and remove if found
+ # find log file in args and remove if found
# 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];
- splice(@args, index($var, "pi_custom_log="), 1);
- logger("Using custom log '$customLog'", "info");
+ if ( index( $var, "pi_custom_log=" ) != -1 ) {
+ $customLog = ( split( /=/, $var ) )[1];
+ splice( @args, index( $var, "pi_custom_log=" ), 1 );
+ logger( "Using custom log '$customLog'", "info" );
}
}
-
+
# create pipe between child and parent and redirect output from child to parent for logging
my $child = open READER, '-|';
defined $child or die "pipe/fork: $!\n";
- if ($child) { #parent
+ if ($child) { #parent
while ( $line = <READER> ) {
+
# log all output from child pipe
- if ($customLog ne "") {
- logger($line, "info", $customLog);
+ if ( $customLog ne "" ) {
+ logger( $line, "info", $customLog );
}
else {
- logger($line, "info");
+ logger( $line, "info" );
}
}
}
- else { #child
- # redirect stderr to stdout so parent can read
+ else { #child
+ # redirect stderr to stdout so parent can read
open STDERR, '>&STDOUT';
- exec($command, @args) or exit(1);
+ exec( $command, @args ) or exit(1);
}
}
@@ -91,27 +92,27 @@ sub errorOut {
# This function is intended to keep log file sizes low and is called from postinstall
sub rotateLog {
my $logFileName = shift;
-
+
if ( !-f $logFileName ) {
- logger("Log file '$logFileName' does not exist - not rotating log", "error");
+ logger( "Log file '$logFileName' does not exist - not rotating log", "error" );
return;
}
- execCommand('/bin/mv', '-f', $logFileName, $logFileName . '.bkp');
- logger("Rotated log $logFileName", "info");
+ execCommand( '/bin/mv', '-f', $logFileName, $logFileName . '.bkp' );
+ logger( "Rotated log $logFileName", "info" );
}
# outputs logging messages to terminal and log file
sub logger {
my $output = shift;
my $type = shift;
-
+
# optional custom log file to use instead of main log file used by postinstall
# cpan uses a custom log file because of its size
my $customLogFile = shift;
my $message = $output;
- if (index($message, "\n") == -1) {
+ if ( index( $message, "\n" ) == -1 ) {
$message = $message . "\n";
}
@@ -124,7 +125,7 @@ sub logger {
my $fh;
my $result = 0;
if ( defined $customLogFile && $customLogFile ne "" ) {
- open $fh, '>>', $customLogFile or die("Couldn't open log file '$::customLogFile'");
+ open $fh, '>>', $customLogFile or die("Couldn't open log file '$::customLogFile'");
$result = 1;
}
else {
@@ -133,8 +134,8 @@ sub logger {
$result = 1;
}
}
-
- if ( $result ) {
+
+ if ($result) {
print $fh localtime . ": " . uc($type) . ' ' . $message;
close $fh;
}
@@ -152,7 +153,6 @@ sub randomWord {
return $secret;
}
-# deprecated
sub promptUser {
my ( $promptString, $defaultValue, $noEcho ) = @_;
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d665814e/traffic_ops/install/lib/ProfileCleanup.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/ProfileCleanup.pm b/traffic_ops/install/lib/ProfileCleanup.pm
index eab10a1..3fe6220 100644
--- a/traffic_ops/install/lib/ProfileCleanup.pm
+++ b/traffic_ops/install/lib/ProfileCleanup.pm
@@ -1,17 +1,3 @@
-#!/usr/bin/perl
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
package ProfileCleanup;
@@ -159,7 +145,7 @@ sub profiles_exist {
$::parameters->{'tm.url'} = $tmurl;
- logger("Checking profiles at $tmurl using username " . $config->{"username"}, "info");
+ 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"} );
[09/36] incubator-trafficcontrol git commit: Several minor updates to
sanityCheck
Posted by da...@apache.org.
Several minor updates to sanityCheck
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/ce47eb81
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/ce47eb81
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/ce47eb81
Branch: refs/heads/master
Commit: ce47eb817e9abc489368951259275a52c391ba6a
Parents: 034a587
Author: peryder <pe...@cisco.com>
Authored: Mon Nov 14 14:16:49 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall-new | 38 ++++++++++++++++------------
1 file changed, 22 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/ce47eb81/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
index 0228b5a..6d3ca0f 100755
--- a/traffic_ops/install/bin/postinstall-new
+++ b/traffic_ops/install/bin/postinstall-new
@@ -53,7 +53,7 @@ sub getField {
# if no config value and in interactive mode prompt user
if ($::interactive) {
return promptUser($question);
- }
+ }
# if no answer given in input file attempt to use default answer
foreach my $var (@{ $::defaultInputs->{$fileName} }) {
@@ -63,7 +63,7 @@ sub getField {
}
#No way of getting answer
- errorOut("No config answer given\n");
+ errorOut("No config answer given for question \'$question\'\n");
}
errorOut("error: end of function");
@@ -90,8 +90,8 @@ sub getConfig {
}
foreach my $var (@{ $userInput->{$fileName} }) {
- my $question = ( (keys $var)[0] eq "config_var" ? (keys $var)[1] : (keys $var)[0] );
- my $answer = $config{$var->{"config_var"}} = getField($question, $var->{$question}, $fileName);
+ my $question = ( (keys $var)[0] eq "config_var" ? (keys $var)[1] : (keys $var)[0] );
+ my $answer = $config{$var->{"config_var"}} = getField($question, $var->{$question}, $fileName);
$config{$var->{"config_var"}} = $answer;
if ($::debug) {
@@ -149,7 +149,7 @@ sub generateCdnConf {
my %cdnconf = getConfig($userInput, $fileName);
if (! looks_like_number($cdnconf{keepSecrets}) ) {
- errorOut("Number of secrets to keep must be a number\n");
+ errorOut("Error: Number of secrets to keep must be a number\n");
}
if ( lc $cdnconf{genSecret} =~ /^y(?:es)?/ ) {
@@ -223,8 +223,8 @@ sub generateProfilesDir {
# userInput: The entire input config file which is either user input or the defaults
#
-# Checks the input config file against the default inputs. If there is a question located in the input config file
-# which is not present in the defaults it will output a warning message.
+# Checks the input config file against the default inputs. If there is a question located in the default inputs which
+# is not located in the input config file it will output a warning message.
#
# This does not check the other way meaning questions which are present in defaults but not present in the input config
# file will not be checked
@@ -233,19 +233,25 @@ sub sanityCheckConfig {
my $userInput = shift;
my $diffs = 0;
- foreach my $file ( (keys $userInput) ) {
- if (!defined $::defaultInputs->{$file}) {
- print "Warning: File \'$file\' found in input but not defaults\n";
+ foreach my $file ( (keys $::defaultInputs) ) {
+ if (!defined $userInput->{$file}) {
+ print "Warning: File \'$file\' found in defaults but not config file\n";
next;
}
- my $counter = 0;
- foreach my $value (@ { $userInput->{$file} }) {
- if ( !defined $::defaultInputs->{$file}[$counter]->{"config_var"} ) {
- print "Warning: Value " . Dumper($value) . "found in file \'$file\' but not defaults\n";
- $diffs++;
+ foreach my $defaultValue (@ { $::defaultInputs->{$file} }) {
+
+ my $found = 0;
+ foreach my $configValue (@ { $userInput->{$file} }) {
+ if ($defaultValue->{"config_var"} eq $configValue->{"config_var"} ) {
+ $found = 1;
+ }
+ }
+
+ if (!$found) {
+ print "Warning: Value " . Dumper($defaultValue) . "found in defaults but not in \'$file\'\n";
+ $diffs++;
}
- $counter++;
}
}
[06/36] incubator-trafficcontrol git commit: More updates to
postinstall for handling logic flow
Posted by da...@apache.org.
More updates to postinstall for handling logic flow
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/9edf9d71
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/9edf9d71
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/9edf9d71
Branch: refs/heads/master
Commit: 9edf9d714eb92243efbaa0830915183674638f42
Parents: faa8619
Author: peryder <pe...@cisco.com>
Authored: Tue Nov 15 11:16:09 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall-new | 57 +++++++++++++++++++++++++---
1 file changed, 51 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/9edf9d71/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
index d1d497b..abd2170 100755
--- a/traffic_ops/install/bin/postinstall-new
+++ b/traffic_ops/install/bin/postinstall-new
@@ -45,6 +45,11 @@ sub getField {
my $config_answer = shift;
my $fileName = shift;
+ # if there is no config file and interactive mode prompt for all questions with default answers
+ if ( $::inputFile eq "" && $::interactive ) {
+ return promptUser( $question, $config_answer );
+ }
+
# if answer provided in config file use it
if ($config_answer) {
return $config_answer;
@@ -57,7 +62,7 @@ sub getField {
# if no answer given in input file attempt to use default answer
foreach my $var ( @{ $::defaultInputs->{$fileName} } ) {
- if ( defined $var->{$question} ) {
+ if ( defined $var->{$question} && $var->{$question} ne "" ) {
return $var->{$question};
}
}
@@ -91,6 +96,7 @@ sub getConfig {
foreach my $var ( @{ $userInput->{$fileName} } ) {
my $question = ( ( keys $var )[0] eq "config_var" ? ( keys $var )[1] : ( keys $var )[0] );
+
my $answer = $config{ $var->{"config_var"} } = getField( $question, $var->{$question}, $fileName );
$config{ $var->{"config_var"} } = $answer;
@@ -221,6 +227,21 @@ sub generateProfilesDir {
my $userIn = $userInput->{$fileName};
}
+sub sanityCheckDefaults {
+ foreach my $file ( ( keys $::defaultInputs ) ) {
+ foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
+ my $question = ( ( keys $defaultValue )[0] eq "config_var" ? ( keys $defaultValue )[1] : ( keys $defaultValue )[0] );
+ if ( !defined $defaultValue->{$question} || $defaultValue->{$question} eq "" ) {
+ errorOut("Error: question \'$question\' in file \'$file\' has no default answer\n");
+ }
+
+ if ( !defined $defaultValue->{"config_var"} || $defaultValue->{"config_var"} eq "" ) {
+ errorOut("Error: question \'$question\' in file \'$file\' has no config_var");
+ }
+ }
+ }
+}
+
# userInput: The entire input config file which is either user input or the defaults
#
# Checks the input config file against the default inputs. If there is a question located in the default inputs which
@@ -248,8 +269,26 @@ sub sanityCheckConfig {
}
}
+ # if the question is not found in the config file add it from defaults
if ( !$found ) {
print "Warning: Value " . Dumper($defaultValue) . "found in defaults but not in \'$file\'\n";
+
+ my $question = ( ( keys $defaultValue )[0] eq "config_var" ? ( keys $defaultValue )[1] : ( keys $defaultValue )[0] );
+
+ my %temp;
+
+ # if interactive add the question without default answer
+ if ($::interactive) {
+ %temp = ( "config_var" => $defaultValue->{"config_var"}, $question => "" );
+ }
+
+ # if not interactive add question with default answer
+ else {
+ %temp = ( "config_var" => $defaultValue->{"config_var"}, $question => $defaultValue->{$question} );
+ }
+
+ push $userInput->{$file}, \%temp;
+
$diffs++;
}
}
@@ -364,13 +403,14 @@ sub getDefaults {
# if no answer in default die
sub main {
- my $inputFile = "";
- my $help = 0;
+ our $inputFile = "";
+ my $help = 0;
our $interactive = 0;
our $debug = 0;
GetOptions(
"cfile=s" => \$inputFile,
+ "c=s" => \$inputFile,
"i" => \$interactive,
"d" => \$debug,
"h" => \$help,
@@ -397,13 +437,18 @@ sub main {
# will either be input config file or defaults
my $userInput;
- if ( $inputFile eq "" ) {
+ if ( $::inputFile eq "" ) {
print "No input file given - using defaults\n";
$userInput = $::defaultInputs;
}
else {
- print "Using input file $inputFile\n";
- $userInput = readJson($inputFile);
+ print "Using input file $::inputFile\n";
+ $userInput = readJson($::inputFile);
+ }
+
+ # check the defaults
+ if ( $::inputFile eq "" && !$::interactive ) {
+ sanityCheckDefaults();
}
# check the input config file against the defaults
[11/36] incubator-trafficcontrol git commit: Formatting changes
Posted by da...@apache.org.
Formatting changes
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/faa86192
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/faa86192
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/faa86192
Branch: refs/heads/master
Commit: faa86192b1bcf611e33f65ced805e0d34d5e62c0
Parents: ce47eb8
Author: peryder <pe...@cisco.com>
Authored: Mon Nov 14 15:47:00 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall-new | 609 ++++++++++++++-------------
1 file changed, 306 insertions(+), 303 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/faa86192/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
index 6d3ca0f..d1d497b 100755
--- a/traffic_ops/install/bin/postinstall-new
+++ b/traffic_ops/install/bin/postinstall-new
@@ -19,54 +19,54 @@ use Scalar::Util qw(looks_like_number);
use Getopt::Long;
sub errorOut {
- die @_;
+ die @_;
}
sub getDbDriver {
- return "mymysql";
+ return "mymysql";
}
sub getInstallPath {
- my $relPath = shift;
- return join( '/', "/tmp/traffic_ops", $relPath );
+ my $relPath = shift;
+ return join( '/', "/tmp/traffic_ops", $relPath );
}
# 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
# fileName: The name of the output config file given by the input config file
#
-# Determines an answer to the questions asked. If an input question and answer pair is given, will return the
+# Determines an answer to the questions asked. If an input question and answer pair is given, will return the
# answer. If a question is given but no answer, it will prompt the user if interactive mode is enabled, but if
# interactive mode is not enabled it will return the default answer to the question. If there is no default answer
# to the question and interactive mode is not enabled it will return an error and quit.
sub getField {
- my $question = shift;
- my $config_answer = shift;
- my $fileName = shift;
-
- # if answer provided in config file use it
- if ($config_answer) {
- return $config_answer;
- }
- else {
- # if no config value and in interactive mode prompt user
- if ($::interactive) {
- return promptUser($question);
- }
-
- # if no answer given in input file attempt to use default answer
- foreach my $var (@{ $::defaultInputs->{$fileName} }) {
- if ( defined $var->{$question} ) {
- return $var->{$question};
- }
- }
-
- #No way of getting answer
- errorOut("No config answer given for question \'$question\'\n");
- }
-
- errorOut("error: end of function");
+ my $question = shift;
+ my $config_answer = shift;
+ my $fileName = shift;
+
+ # if answer provided in config file use it
+ if ($config_answer) {
+ return $config_answer;
+ }
+ else {
+ # if no config value and in interactive mode prompt user
+ if ($::interactive) {
+ return promptUser($question);
+ }
+
+ # if no answer given in input file attempt to use default answer
+ foreach my $var ( @{ $::defaultInputs->{$fileName} } ) {
+ if ( defined $var->{$question} ) {
+ return $var->{$question};
+ }
+ }
+
+ #No way of getting answer
+ errorOut("No config answer given for question \'$question\'\n");
+ }
+
+ errorOut("error: end of function");
}
# userInput: The entire input config file which is either user input or the defaults
@@ -76,29 +76,29 @@ sub getField {
# and returns the hash of answers
sub getConfig {
- my $userInput = shift;
- my $fileName = shift;
-
- my %config;
-
- if (!defined $userInput->{$fileName}) {
- print "Error: No $fileName found in config\n";
- }
-
- if ($::debug) {
- print "===========$fileName===========\n";
- }
-
- foreach my $var (@{ $userInput->{$fileName} }) {
- my $question = ( (keys $var)[0] eq "config_var" ? (keys $var)[1] : (keys $var)[0] );
- my $answer = $config{$var->{"config_var"}} = getField($question, $var->{$question}, $fileName);
-
- $config{$var->{"config_var"}} = $answer;
- if ($::debug) {
- print "$question: $answer\n";
- }
- }
- return %config;
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %config;
+
+ if ( !defined $userInput->{$fileName} ) {
+ print "Error: No $fileName found in config\n";
+ }
+
+ if ($::debug) {
+ print "===========$fileName===========\n";
+ }
+
+ foreach my $var ( @{ $userInput->{$fileName} } ) {
+ my $question = ( ( keys $var )[0] eq "config_var" ? ( keys $var )[1] : ( keys $var )[0] );
+ my $answer = $config{ $var->{"config_var"} } = getField( $question, $var->{$question}, $fileName );
+
+ $config{ $var->{"config_var"} } = $answer;
+ if ($::debug) {
+ print "$question: $answer\n";
+ }
+ }
+ return %config;
}
# userInput: The entire input config file which is either user input or the defaults
@@ -109,29 +109,29 @@ sub getConfig {
# Generates a config file for the database based on the questions and answers in the input config file
sub generateDbConf {
- my $userInput = shift;
- my $dbFileName = shift;
- my $toDBFileName = shift;
- my $dbAccessFileName = shift;
-
- my %dbconf = getConfig($userInput, $dbFileName);
-
- make_path( dirname($dbFileName), { mode => 0755 } );
- writeJson( $dbFileName, \%dbconf );
-
- # broken out into separate file/config area
- my %todbconf = getConfig($userInput, $toDBFileName);
-
- # No YAML library installed, but this is a simple file..
- open( my $fh, '>', $dbAccessFileName ) or errorOut("Can't write to $dbAccessFileName $!");
- print $fh "version: 1.0\n";
- print $fh "name: dbconf.yml\n\n";
- print $fh "production:\n";
- print $fh " driver: ", getDbDriver() . "\n";
- print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{root_user}/$dbconf{root_passwd}\n";
- close $fh;
-
- return \%todbconf;
+ my $userInput = shift;
+ my $dbFileName = shift;
+ my $toDBFileName = shift;
+ my $dbAccessFileName = shift;
+
+ my %dbconf = getConfig( $userInput, $dbFileName );
+
+ make_path( dirname($dbFileName), { mode => 0755 } );
+ writeJson( $dbFileName, \%dbconf );
+
+ # broken out into separate file/config area
+ my %todbconf = getConfig( $userInput, $toDBFileName );
+
+ # No YAML library installed, but this is a simple file..
+ open( my $fh, '>', $dbAccessFileName ) or errorOut("Can't write to $dbAccessFileName $!");
+ print $fh "version: 1.0\n";
+ print $fh "name: dbconf.yml\n\n";
+ print $fh "production:\n";
+ print $fh " driver: ", getDbDriver() . "\n";
+ print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{root_user}/$dbconf{root_passwd}\n";
+ close $fh;
+
+ return \%todbconf;
}
# userInput: The entire input config file which is either user input or the defaults
@@ -140,29 +140,29 @@ sub generateDbConf {
# Generates a config file for the CDN
sub generateCdnConf {
- my $userInput = shift;
- my $fileName = shift;
-
- # First, read existing one -- already loaded with a bunch of stuff
- my $cdnConf = Safe->new->rdo($fileName) or errorOut("Error loading $fileName: $@");
-
- my %cdnconf = getConfig($userInput, $fileName);
-
- if (! looks_like_number($cdnconf{keepSecrets}) ) {
- errorOut("Error: Number of secrets to keep must be a number\n");
- }
-
- if ( lc $cdnconf{genSecret} =~ /^y(?:es)?/ ) {
- my @secrets = @{ $cdnConf->{secrets} };
- my $newSecret = randomWord();
- unshift @secrets, randomWord();
- if ( $cdnconf{keepSecrets} > 0 && $#secrets > $cdnconf{keepSecrets} - 1 ) {
-
- # Shorten the array to requested length
- $#secrets = $cdnconf{keepSecrets} - 1;
- }
- }
- writePerl( $fileName, $cdnConf );
+ my $userInput = shift;
+ my $fileName = shift;
+
+ # First, read existing one -- already loaded with a bunch of stuff
+ my $cdnConf = Safe->new->rdo($fileName) or errorOut("Error loading $fileName: $@");
+
+ my %cdnconf = getConfig( $userInput, $fileName );
+
+ if ( !looks_like_number( $cdnconf{keepSecrets} ) ) {
+ errorOut("Error: Number of secrets to keep must be a number\n");
+ }
+
+ if ( lc $cdnconf{genSecret} =~ /^y(?:es)?/ ) {
+ my @secrets = @{ $cdnConf->{secrets} };
+ my $newSecret = randomWord();
+ unshift @secrets, randomWord();
+ if ( $cdnconf{keepSecrets} > 0 && $#secrets > $cdnconf{keepSecrets} - 1 ) {
+
+ # Shorten the array to requested length
+ $#secrets = $cdnconf{keepSecrets} - 1;
+ }
+ }
+ writePerl( $fileName, $cdnConf );
}
# userInput: The entire input config file which is either user input or the defaults
@@ -171,54 +171,54 @@ sub generateCdnConf {
# Generates an LDAP config file
sub generateLdapConf {
- my $userInput = shift;
- my $fileName = shift;
-
- my $useLdap = $userInput->{$fileName}[0]->{"Do you want to set up LDAP?"};
-
- if ($useLdap eq "no" || $useLdap eq "n" ) {
- if ($::debug) {
- print "Not setting up ldap\n";
- }
- return;
- }
-
- my %ldapConf = getConfig($userInput, $fileName);
-
- if ( $::debug && $ldapConf{setupLdap} eq "no" ) {
- print "Not setting up ldap\n";
- return;
- }
-
- make_path( dirname($fileName), { mode => 0755 } );
- writeJson( $fileName, \%ldapConf );
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my $useLdap = $userInput->{$fileName}[0]->{"Do you want to set up LDAP?"};
+
+ if ( $useLdap eq "no" || $useLdap eq "n" ) {
+ if ($::debug) {
+ print "Not setting up ldap\n";
+ }
+ return;
+ }
+
+ my %ldapConf = getConfig( $userInput, $fileName );
+
+ if ( $::debug && $ldapConf{setupLdap} eq "no" ) {
+ print "Not setting up ldap\n";
+ return;
+ }
+
+ make_path( dirname($fileName), { mode => 0755 } );
+ writeJson( $fileName, \%ldapConf );
}
sub generatePostInstallConf {
- my $userInput = shift;
- my $fileName = shift;
+ my $userInput = shift;
+ my $fileName = shift;
- my $userIn = $userInput->{$fileName};
+ my $userIn = $userInput->{$fileName};
}
sub generateUsersConf {
- my $userInput = shift;
- my $fileName = shift;
-
- my %user = ();
- my %config = getConfig($userInput, $fileName);
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %user = ();
+ my %config = getConfig( $userInput, $fileName );
- $user{username} = $config{tmAdminUser};
- $user{password} = sha1_hex($config{tmAdminPw});
+ $user{username} = $config{tmAdminUser};
+ $user{password} = sha1_hex( $config{tmAdminPw} );
- writeJson( $fileName, \%user );
+ writeJson( $fileName, \%user );
}
sub generateProfilesDir {
- my $userInput = shift;
- my $fileName = shift;
+ my $userInput = shift;
+ my $fileName = shift;
- my $userIn = $userInput->{$fileName};
+ my $userIn = $userInput->{$fileName};
}
# userInput: The entire input config file which is either user input or the defaults
@@ -230,126 +230,126 @@ sub generateProfilesDir {
# file will not be checked
sub sanityCheckConfig {
- my $userInput = shift;
- my $diffs = 0;
-
- foreach my $file ( (keys $::defaultInputs) ) {
- if (!defined $userInput->{$file}) {
- print "Warning: File \'$file\' found in defaults but not config file\n";
- next;
- }
-
- foreach my $defaultValue (@ { $::defaultInputs->{$file} }) {
-
- my $found = 0;
- foreach my $configValue (@ { $userInput->{$file} }) {
- if ($defaultValue->{"config_var"} eq $configValue->{"config_var"} ) {
- $found = 1;
- }
- }
-
- if (!$found) {
- print "Warning: Value " . Dumper($defaultValue) . "found in defaults but not in \'$file\'\n";
- $diffs++;
- }
- }
- }
-
- if ($::debug && $diffs == 0) {
- print "File sanity check complete - found $diffs differences\n";
- }
-
- if ($diffs > 0) {
- print "File sanity check complete - found $diffs difference(s)\n";
- }
+ my $userInput = shift;
+ my $diffs = 0;
+
+ foreach my $file ( ( keys $::defaultInputs ) ) {
+ if ( !defined $userInput->{$file} ) {
+ print "Warning: File \'$file\' found in defaults but not config file\n";
+ next;
+ }
+
+ foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
+
+ my $found = 0;
+ foreach my $configValue ( @{ $userInput->{$file} } ) {
+ if ( $defaultValue->{"config_var"} eq $configValue->{"config_var"} ) {
+ $found = 1;
+ }
+ }
+
+ if ( !$found ) {
+ print "Warning: Value " . Dumper($defaultValue) . "found in defaults but not in \'$file\'\n";
+ $diffs++;
+ }
+ }
+ }
+
+ if ( $::debug && $diffs == 0 ) {
+ print "File sanity check complete - found $diffs differences\n";
+ }
+
+ if ( $diffs > 0 ) {
+ print "File sanity check complete - found $diffs difference(s)\n";
+ }
}
-
+
# A function which returns the default inputs data structure. These questions and answers will be used if there is no
# user input config file or if there are questions in the input config file which do not have answers
-sub getDefaults{
- return {
- "testdb.conf" => [
- {
- "Database type" => "mysql",
- "config_var" => "type"
- },
- {
- "Database name" => "traffic_ops",
- "config_var" => "dbname"
- },
- {
- "Database server hostname IP or FQDN" => "localhost",
- "config_var" => "hostname"
- },
- {
- "Database port number" => 3306,
- "config_var" => "port"
- },
- {
- "Root database user" => "root",
- "config_var" => "root_user"
- },
- {
- "Root database password" => "default",
- "config_var" => "root_passwd"
- }
- ],
- "testtodb.conf" => [
- {
- "Traffic Ops database user" => "root",
- "config_var" => "dbAdminUser"
- },
- {
- "Password for Traffic Ops database user" => "default",
- "config_var" => "dbAdminPw"
- }
- ],
- "testcdn.conf" => [
- {
- "Generate a new secret?" => "yes",
- "config_var" => "genSecret"
- },
- {
- "Number of secrets to keep?" => "10",
- "config_var" => "keepSecrets"
- }
- ],
- "testldap.conf" => [
- {
- "Do you want to set up LDAP?" => "no",
- "config_var" => "setupLdap"
- },
- {
- "LDAP server hostname" => "",
- "config_var" => "hostname"
- },
- {
- "LDAP Admin DN" => "",
- "config_var" => "admin_dn"
- },
- {
- "LDAP Admin Password" => "",
- "config_var" => "password"
- },
- {
- "LDAP Search Base" => "",
- "config_var" => "search_base"
- }
+sub getDefaults {
+ return {
+ "testdb.conf" => [
+ {
+ "Database type" => "mysql",
+ "config_var" => "type"
+ },
+ {
+ "Database name" => "traffic_ops",
+ "config_var" => "dbname"
+ },
+ {
+ "Database server hostname IP or FQDN" => "localhost",
+ "config_var" => "hostname"
+ },
+ {
+ "Database port number" => 3306,
+ "config_var" => "port"
+ },
+ {
+ "Root database user" => "root",
+ "config_var" => "root_user"
+ },
+ {
+ "Root database password" => "default",
+ "config_var" => "root_passwd"
+ }
+ ],
+ "testtodb.conf" => [
+ {
+ "Traffic Ops database user" => "root",
+ "config_var" => "dbAdminUser"
+ },
+ {
+ "Password for Traffic Ops database user" => "default",
+ "config_var" => "dbAdminPw"
+ }
+ ],
+ "testcdn.conf" => [
+ {
+ "Generate a new secret?" => "yes",
+ "config_var" => "genSecret"
+ },
+ {
+ "Number of secrets to keep?" => "10",
+ "config_var" => "keepSecrets"
+ }
+ ],
+ "testldap.conf" => [
+ {
+ "Do you want to set up LDAP?" => "no",
+ "config_var" => "setupLdap"
+ },
+ {
+ "LDAP server hostname" => "",
+ "config_var" => "hostname"
+ },
+ {
+ "LDAP Admin DN" => "",
+ "config_var" => "admin_dn"
+ },
+ {
+ "LDAP Admin Password" => "",
+ "config_var" => "password"
+ },
+ {
+ "LDAP Search Base" => "",
+ "config_var" => "search_base"
+ }
],
"testpost_install.json" => [],
- "testusers.json" => [
- {
- "Administration username for Traffic Ops" => "admin",
- "config_var" => "tmAdminUser"
- },
- {
- "Password for the admin user" => "default",
- "config_var" => "tmAdminPw"
- }
- ],
+ "testusers.json" => [
+ {
+ "Administration username for Traffic Ops" => "admin",
+ "config_var" => "tmAdminUser"
+ },
+ {
+ "Password for the admin user" => "default",
+ "config_var" => "tmAdminPw"
+ }
+ ],
"testprofiles/" => []
- };
+ };
}
# -d - Debug Mode: More output to the terminal
@@ -360,64 +360,67 @@ sub getDefaults{
# In interactive mode: prompt if no value in cfile
-# Not in interactive mode: if answer in cfile, use if. If no answer in cfile, use answer in default.
+# Not in interactive mode: if answer in cfile, use if. If no answer in cfile, use answer in default.
# if no answer in default die
sub main {
- my $inputFile = "";
- my $help = 0;
- our $interactive = 0;
- our $debug = 0;
-
- GetOptions( "cfile=s" => \$inputFile,
- "i" => \$interactive,
- "d" => \$debug,
- "h" => \$help,
- "help" => \$help)
- or die ("Error in command line arguments");
-
- # stores the default questions and answers
- our $defaultInputs = getDefaults();
-
- if ($help) {
- print "Usage: postinstall [-i] [-d] -cfile=[config_file]\n";
- exit(0);
- }
-
- if ($::debug) {
- print "Debug is on\n";
- }
-
- if ($::debug && $::interactive) {
- print "Running in interactive mode\n";
- }
-
- # used to store the questions and answers - will either be input config file or defaults
- my $userInput;
-
- if ($inputFile eq "") {
- print "No input file given - using defaults\n";
- $userInput = $::defaultInputs;
- }
- else {
- print "Using input file $inputFile\n";
- $userInput = readJson($inputFile);
- }
-
- # check the input config file against the defaults to check for missing questions
- if ($inputFile ne "") {
- sanityCheckConfig($userInput);
- }
-
- # The generator functions handle checking input/default/interactive mode
-
- # todbconf will be used later when setting up the database
- my $todbconf = generateDbConf( $userInput, 'testdb.conf', 'testtodb.conf', 'testdbconf.yml' );
- generateCdnConf( $userInput, 'testcdn.conf' );
- generateLdapConf( $userInput, 'testldap.conf' );
- generatePostInstallConf( $userInput, 'testpost_install.json' );
- generateUsersConf( $userInput, 'testusers.json' );
- generateProfilesDir( $userInput, 'testprofiles/' );
+ my $inputFile = "";
+ my $help = 0;
+ our $interactive = 0;
+ our $debug = 0;
+
+ GetOptions(
+ "cfile=s" => \$inputFile,
+ "i" => \$interactive,
+ "d" => \$debug,
+ "h" => \$help,
+ "help" => \$help
+ ) or die("Error in command line arguments");
+
+ # stores the default questions and answers
+ our $defaultInputs = getDefaults();
+
+ if ($help) {
+ print "Usage: postinstall [-i] [-d] -cfile=[config_file]\n";
+ exit(0);
+ }
+
+ if ($::debug) {
+ print "Debug is on\n";
+ }
+
+ if ( $::debug && $::interactive ) {
+ print "Running in interactive mode\n";
+ }
+
+ # used to store the questions and answers -
+ # will either be input config file or defaults
+ my $userInput;
+
+ if ( $inputFile eq "" ) {
+ print "No input file given - using defaults\n";
+ $userInput = $::defaultInputs;
+ }
+ else {
+ print "Using input file $inputFile\n";
+ $userInput = readJson($inputFile);
+ }
+
+ # check the input config file against the defaults
+ # to check for missing questions
+ if ( $inputFile ne "" ) {
+ sanityCheckConfig($userInput);
+ }
+
+ # The generator functions handle checking input/default/interactive mode
+
+ # todbconf will be used later when setting up the database
+ my $todbconf = generateDbConf( $userInput, 'testdb.conf', 'testtodb.conf', 'testdbconf.yml' );
+ generateCdnConf( $userInput, 'testcdn.conf' );
+ generateLdapConf( $userInput, 'testldap.conf' );
+ generatePostInstallConf( $userInput, 'testpost_install.json' );
+ generateUsersConf( $userInput, 'testusers.json' );
+ generateProfilesDir( $userInput, 'testprofiles/' );
}
main;
[07/36] incubator-trafficcontrol git commit: Work in progress of
automating postinstall
Posted by da...@apache.org.
Work in progress of automating postinstall
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/c0545f7d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/c0545f7d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/c0545f7d
Branch: refs/heads/master
Commit: c0545f7d2690aed814fd1f9f1cb57e3f5db7b116
Parents: 5be5a7c
Author: peryder <pe...@cisco.com>
Authored: Wed Nov 9 17:05:21 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
.../install/bin/build_trafficops_perl_library | 44 +-
traffic_ops/install/bin/input.json | 82 ++++
traffic_ops/install/bin/postinstall-new | 419 +++++++++++++++++++
traffic_ops/install/lib/InstallUtils.pm | 42 +-
4 files changed, 553 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c0545f7d/traffic_ops/install/bin/build_trafficops_perl_library
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/build_trafficops_perl_library b/traffic_ops/install/bin/build_trafficops_perl_library
index 684916d..33eda0c 100755
--- a/traffic_ops/install/bin/build_trafficops_perl_library
+++ b/traffic_ops/install/bin/build_trafficops_perl_library
@@ -1,5 +1,6 @@
#!/usr/bin/perl
#
+# Copyright 2015 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,6 +15,10 @@
# limitations under the License.
#
+use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
+$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
+$ENV{PERL5LIB} = "/opt/traffic_ops/install/lib:/opt/traffic_ops/install/lib/perl5:/opt/traffic_ops/app/local/lib/perl5:/opt/traffic_ops/app/lib";
+
use strict;
use warnings;
use Getopt::Std;
@@ -21,6 +26,9 @@ use InstallUtils;
our ($opt_i);
+my $auto = $ARGV[0];
+print $auto;
+
my @dependencies = (
"expat-devel", "mod_ssl", "mkisofs", "libpcap", "libpcap-devel", "libcurl",
"libcurl-devel", "mysql-server", "mysql-devel", "openssl", "cpan", "gcc",
@@ -34,38 +42,6 @@ compiler will be installed on this machine.
EOF
-sub promptUser {
- my ( $promptString, $defaultValue, $noEcho ) = @_;
-
- if ($defaultValue) {
- print $promptString, " [", $defaultValue, "]: ";
- }
- else {
- print $promptString, ": ";
- }
-
- if ( defined $noEcho && $noEcho ) {
- my $response = read_password('');
- if ( ( !defined $response || $response eq '' ) && ( defined $defaultValue && $defaultValue ne '' ) ) {
- $response = $defaultValue;
- }
- return $response;
- }
- else {
- $| = 1;
- $_ = <STDIN>;
- chomp;
-
- if ("$defaultValue") {
- return $_ ? $_ : $defaultValue;
- }
- else {
- return $_;
- }
- return $_;
- }
-}
-
sub trim {
my $str = shift;
@@ -96,7 +72,9 @@ if ( $ENV{USER} ne "root" ) {
print $msg;
-promptUser( "Hit ENTER to continue", "" );
+if ( !$auto ) {
+ InstallUtils::promptUser( "Hit ENTER to continue", "" );
+}
chdir("/opt/traffic_ops/app");
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c0545f7d/traffic_ops/install/bin/input.json
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/input.json b/traffic_ops/install/bin/input.json
new file mode 100644
index 0000000..8428eec
--- /dev/null
+++ b/traffic_ops/install/bin/input.json
@@ -0,0 +1,82 @@
+{
+ "testdb.conf": [
+ {
+ "Database type": "mysql",
+ "config_var": "type"
+ },
+ {
+ "Database name": "traffic_ops",
+ "config_var": "dbname"
+ },
+ {
+ "Database server hostname IP or FQDN": "localhost",
+ "config_var": "hostname"
+ },
+ {
+ "Database port number": "3306",
+ "config_var": "port"
+ },
+ {
+ "Root database user": "root",
+ "config_var": "root_user"
+ },
+ {
+ "Root database password": "default",
+ "config_var": "root_passwd"
+ }
+ ],
+ "testtodb.conf": [
+ {
+ "Traffic Ops database user": "root",
+ "config_var": "dbAdminUser"
+ },
+ {
+ "Password for Traffic Ops database user": "default",
+ "config_var": "dbAdminPw"
+ }
+ ],
+ "testcdn.conf": [
+ {
+ "Generate a new secret?": "yes",
+ "config_var": "genSecret"
+ },
+ {
+ "Number of secrets to keep?": "10",
+ "config_var": "keepSecrets"
+ }
+ ],
+ "testldap.conf": [
+ {
+ "Do you want to set up LDAP?": "no",
+ "config_var": "setupLdap"
+ },
+ {
+ "LDAP server hostname": "",
+ "config_var": "hostname"
+ },
+ {
+ "LDAP Admin DN": "",
+ "config_var": "admin_dn"
+ },
+ {
+ "LDAP Admin Password": "",
+ "config_var": "password"
+ },
+ {
+ "LDAP Search Base": "",
+ "config_var": "search_base"
+ }
+ ],
+ "testpost_install.json": [],
+ "testusers.json": [
+ {
+ "Administration username for Traffic Ops": "admin",
+ "config_var": "tmAdminUser"
+ },
+ {
+ "Password for the admin user": "default",
+ "config_var": "tmAdminPw"
+ }
+ ],
+ "testprofiles/": []
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c0545f7d/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
new file mode 100755
index 0000000..0228b5a
--- /dev/null
+++ b/traffic_ops/install/bin/postinstall-new
@@ -0,0 +1,419 @@
+#!/usr/bin/perl
+
+use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
+$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
+$ENV{PERL5LIB} = "/opt/traffic_ops/install/lib:/opt/traffic_ops/install/lib/perl5:/opt/traffic_ops/app/local/lib/perl5:/opt/traffic_ops/app/lib";
+
+use strict;
+use warnings;
+
+use Safe;
+use JSON;
+use File::Basename qw{dirname};
+use File::Path qw{make_path};
+use InstallUtils qw{ :all };
+use Digest::SHA1 qw(sha1_hex);
+use Data::Dumper qw(Dumper);
+use Scalar::Util qw(looks_like_number);
+
+use Getopt::Long;
+
+sub errorOut {
+ die @_;
+}
+
+sub getDbDriver {
+ return "mymysql";
+}
+
+sub getInstallPath {
+ my $relPath = shift;
+ return join( '/', "/tmp/traffic_ops", $relPath );
+}
+
+# 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
+# fileName: The name of the output config file given by the input config file
+#
+# Determines an answer to the questions asked. If an input question and answer pair is given, will return the
+# answer. If a question is given but no answer, it will prompt the user if interactive mode is enabled, but if
+# interactive mode is not enabled it will return the default answer to the question. If there is no default answer
+# to the question and interactive mode is not enabled it will return an error and quit.
+
+sub getField {
+ my $question = shift;
+ my $config_answer = shift;
+ my $fileName = shift;
+
+ # if answer provided in config file use it
+ if ($config_answer) {
+ return $config_answer;
+ }
+ else {
+ # if no config value and in interactive mode prompt user
+ if ($::interactive) {
+ return promptUser($question);
+ }
+
+ # if no answer given in input file attempt to use default answer
+ foreach my $var (@{ $::defaultInputs->{$fileName} }) {
+ if ( defined $var->{$question} ) {
+ return $var->{$question};
+ }
+ }
+
+ #No way of getting answer
+ errorOut("No config answer given\n");
+ }
+
+ errorOut("error: end of function");
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+# fileName: The name of the output config file given by the input config file
+#
+# Loops through an input config file and determines answers to each question using getField
+# and returns the hash of answers
+
+sub getConfig {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %config;
+
+ if (!defined $userInput->{$fileName}) {
+ print "Error: No $fileName found in config\n";
+ }
+
+ if ($::debug) {
+ print "===========$fileName===========\n";
+ }
+
+ foreach my $var (@{ $userInput->{$fileName} }) {
+ my $question = ( (keys $var)[0] eq "config_var" ? (keys $var)[1] : (keys $var)[0] );
+ my $answer = $config{$var->{"config_var"}} = getField($question, $var->{$question}, $fileName);
+
+ $config{$var->{"config_var"}} = $answer;
+ if ($::debug) {
+ print "$question: $answer\n";
+ }
+ }
+ return %config;
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+# dbFileName: The filename of the output config file for the database
+# toDBFileName: The filename of the output config file for the Traffic Ops database
+# dbAccessFileName: The filename of DBAccess
+#
+# Generates a config file for the database based on the questions and answers in the input config file
+
+sub generateDbConf {
+ my $userInput = shift;
+ my $dbFileName = shift;
+ my $toDBFileName = shift;
+ my $dbAccessFileName = shift;
+
+ my %dbconf = getConfig($userInput, $dbFileName);
+
+ make_path( dirname($dbFileName), { mode => 0755 } );
+ writeJson( $dbFileName, \%dbconf );
+
+ # broken out into separate file/config area
+ my %todbconf = getConfig($userInput, $toDBFileName);
+
+ # No YAML library installed, but this is a simple file..
+ open( my $fh, '>', $dbAccessFileName ) or errorOut("Can't write to $dbAccessFileName $!");
+ print $fh "version: 1.0\n";
+ print $fh "name: dbconf.yml\n\n";
+ print $fh "production:\n";
+ print $fh " driver: ", getDbDriver() . "\n";
+ print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{root_user}/$dbconf{root_passwd}\n";
+ close $fh;
+
+ return \%todbconf;
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+# fileName: The filename of the output config file
+#
+# Generates a config file for the CDN
+
+sub generateCdnConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ # First, read existing one -- already loaded with a bunch of stuff
+ my $cdnConf = Safe->new->rdo($fileName) or errorOut("Error loading $fileName: $@");
+
+ my %cdnconf = getConfig($userInput, $fileName);
+
+ if (! looks_like_number($cdnconf{keepSecrets}) ) {
+ errorOut("Number of secrets to keep must be a number\n");
+ }
+
+ if ( lc $cdnconf{genSecret} =~ /^y(?:es)?/ ) {
+ my @secrets = @{ $cdnConf->{secrets} };
+ my $newSecret = randomWord();
+ unshift @secrets, randomWord();
+ if ( $cdnconf{keepSecrets} > 0 && $#secrets > $cdnconf{keepSecrets} - 1 ) {
+
+ # Shorten the array to requested length
+ $#secrets = $cdnconf{keepSecrets} - 1;
+ }
+ }
+ writePerl( $fileName, $cdnConf );
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+# fileName: The filename of the output config file
+#
+# Generates an LDAP config file
+
+sub generateLdapConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my $useLdap = $userInput->{$fileName}[0]->{"Do you want to set up LDAP?"};
+
+ if ($useLdap eq "no" || $useLdap eq "n" ) {
+ if ($::debug) {
+ print "Not setting up ldap\n";
+ }
+ return;
+ }
+
+ my %ldapConf = getConfig($userInput, $fileName);
+
+ if ( $::debug && $ldapConf{setupLdap} eq "no" ) {
+ print "Not setting up ldap\n";
+ return;
+ }
+
+ make_path( dirname($fileName), { mode => 0755 } );
+ writeJson( $fileName, \%ldapConf );
+}
+
+sub generatePostInstallConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my $userIn = $userInput->{$fileName};
+}
+
+sub generateUsersConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %user = ();
+ my %config = getConfig($userInput, $fileName);
+
+ $user{username} = $config{tmAdminUser};
+ $user{password} = sha1_hex($config{tmAdminPw});
+
+ writeJson( $fileName, \%user );
+}
+
+sub generateProfilesDir {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my $userIn = $userInput->{$fileName};
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+#
+# Checks the input config file against the default inputs. If there is a question located in the input config file
+# which is not present in the defaults it will output a warning message.
+#
+# This does not check the other way meaning questions which are present in defaults but not present in the input config
+# file will not be checked
+
+sub sanityCheckConfig {
+ my $userInput = shift;
+ my $diffs = 0;
+
+ foreach my $file ( (keys $userInput) ) {
+ if (!defined $::defaultInputs->{$file}) {
+ print "Warning: File \'$file\' found in input but not defaults\n";
+ next;
+ }
+
+ my $counter = 0;
+ foreach my $value (@ { $userInput->{$file} }) {
+ if ( !defined $::defaultInputs->{$file}[$counter]->{"config_var"} ) {
+ print "Warning: Value " . Dumper($value) . "found in file \'$file\' but not defaults\n";
+ $diffs++;
+ }
+ $counter++;
+ }
+ }
+
+ if ($::debug && $diffs == 0) {
+ print "File sanity check complete - found $diffs differences\n";
+ }
+
+ if ($diffs > 0) {
+ print "File sanity check complete - found $diffs difference(s)\n";
+ }
+}
+
+# A function which returns the default inputs data structure. These questions and answers will be used if there is no
+# user input config file or if there are questions in the input config file which do not have answers
+
+sub getDefaults{
+ return {
+ "testdb.conf" => [
+ {
+ "Database type" => "mysql",
+ "config_var" => "type"
+ },
+ {
+ "Database name" => "traffic_ops",
+ "config_var" => "dbname"
+ },
+ {
+ "Database server hostname IP or FQDN" => "localhost",
+ "config_var" => "hostname"
+ },
+ {
+ "Database port number" => 3306,
+ "config_var" => "port"
+ },
+ {
+ "Root database user" => "root",
+ "config_var" => "root_user"
+ },
+ {
+ "Root database password" => "default",
+ "config_var" => "root_passwd"
+ }
+ ],
+ "testtodb.conf" => [
+ {
+ "Traffic Ops database user" => "root",
+ "config_var" => "dbAdminUser"
+ },
+ {
+ "Password for Traffic Ops database user" => "default",
+ "config_var" => "dbAdminPw"
+ }
+ ],
+ "testcdn.conf" => [
+ {
+ "Generate a new secret?" => "yes",
+ "config_var" => "genSecret"
+ },
+ {
+ "Number of secrets to keep?" => "10",
+ "config_var" => "keepSecrets"
+ }
+ ],
+ "testldap.conf" => [
+ {
+ "Do you want to set up LDAP?" => "no",
+ "config_var" => "setupLdap"
+ },
+ {
+ "LDAP server hostname" => "",
+ "config_var" => "hostname"
+ },
+ {
+ "LDAP Admin DN" => "",
+ "config_var" => "admin_dn"
+ },
+ {
+ "LDAP Admin Password" => "",
+ "config_var" => "password"
+ },
+ {
+ "LDAP Search Base" => "",
+ "config_var" => "search_base"
+ }
+ ],
+ "testpost_install.json" => [],
+ "testusers.json" => [
+ {
+ "Administration username for Traffic Ops" => "admin",
+ "config_var" => "tmAdminUser"
+ },
+ {
+ "Password for the admin user" => "default",
+ "config_var" => "tmAdminPw"
+ }
+ ],
+ "testprofiles/" => []
+ };
+}
+
+# -d - Debug Mode: More output to the terminal
+# -i - Interactive mode: Any questions which do not have answersin config file will result in blocking prompts going
+# to the user
+# -h - Help: Basic command line help menu
+# -cfile - Input File: The input config file used to ask and answer questions
+
+# In interactive mode: prompt if no value in cfile
+
+# Not in interactive mode: if answer in cfile, use if. If no answer in cfile, use answer in default.
+# if no answer in default die
+
+sub main {
+ my $inputFile = "";
+ my $help = 0;
+ our $interactive = 0;
+ our $debug = 0;
+
+ GetOptions( "cfile=s" => \$inputFile,
+ "i" => \$interactive,
+ "d" => \$debug,
+ "h" => \$help,
+ "help" => \$help)
+ or die ("Error in command line arguments");
+
+ # stores the default questions and answers
+ our $defaultInputs = getDefaults();
+
+ if ($help) {
+ print "Usage: postinstall [-i] [-d] -cfile=[config_file]\n";
+ exit(0);
+ }
+
+ if ($::debug) {
+ print "Debug is on\n";
+ }
+
+ if ($::debug && $::interactive) {
+ print "Running in interactive mode\n";
+ }
+
+ # used to store the questions and answers - will either be input config file or defaults
+ my $userInput;
+
+ if ($inputFile eq "") {
+ print "No input file given - using defaults\n";
+ $userInput = $::defaultInputs;
+ }
+ else {
+ print "Using input file $inputFile\n";
+ $userInput = readJson($inputFile);
+ }
+
+ # check the input config file against the defaults to check for missing questions
+ if ($inputFile ne "") {
+ sanityCheckConfig($userInput);
+ }
+
+ # The generator functions handle checking input/default/interactive mode
+
+ # todbconf will be used later when setting up the database
+ my $todbconf = generateDbConf( $userInput, 'testdb.conf', 'testtodb.conf', 'testdbconf.yml' );
+ generateCdnConf( $userInput, 'testcdn.conf' );
+ generateLdapConf( $userInput, 'testldap.conf' );
+ generatePostInstallConf( $userInput, 'testpost_install.json' );
+ generateUsersConf( $userInput, 'testusers.json' );
+ generateProfilesDir( $userInput, 'testprofiles/' );
+}
+
+main;
+
+# vi:syntax=perl
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c0545f7d/traffic_ops/install/lib/InstallUtils.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/InstallUtils.pm b/traffic_ops/install/lib/InstallUtils.pm
index 0574468..ddd1c22 100644
--- a/traffic_ops/install/lib/InstallUtils.pm
+++ b/traffic_ops/install/lib/InstallUtils.pm
@@ -25,7 +25,7 @@ package InstallUtils;
use Term::ReadPassword;
use base qw{ Exporter };
-our @EXPORT_OK = qw{ execCommand randomWord promptUser promptRequired promptPassword promptPasswordVerify trim};
+our @EXPORT_OK = qw{ execCommand randomWord promptUser promptRequired promptPassword promptPasswordVerify trim readJson writeJson writePerl};
our %EXPORT_TAGS = ( all => \@EXPORT_OK );
sub execCommand {
@@ -64,6 +64,10 @@ sub promptUser {
}
return $response;
}
+ elsif ( $::auto && defined $defaultValue ) {
+ print( "$defaultValue\n" );
+ return $defaultValue;
+ }
else {
$| = 1;
$_ = <STDIN>;
@@ -96,6 +100,11 @@ sub promptPassword {
sub promptPasswordVerify {
my $prompt = shift;
my $pw = shift;
+
+ if ( $::auto && defined $pw ) {
+ print( "$prompt: $pw\n" );
+ return $pw;
+ }
while (1) {
$pw = promptPassword($prompt);
@@ -115,4 +124,35 @@ sub trim {
return $str;
}
+sub readJson {
+ my $file = shift;
+ open( my $fh, '<', $file ) or return;
+ local $/; # slurp mode
+ my $text = <$fh>;
+ undef $fh;
+ return JSON->new->utf8->decode($text);
+}
+
+sub writeJson {
+ my $file = shift;
+ open( my $fh, '>', $file ) or die("open(): $!");
+ foreach my $data (@_) {
+ my $json_text = JSON->new->utf8->pretty->encode($data);
+ print $fh $json_text, "\n";
+ }
+ close $fh;
+}
+
+sub writePerl {
+ my $file = shift;
+ my $data = shift;
+
+ open( my $fh, '>', $file ) or die("open(): $!");
+ my $dumper = Data::Dumper->new([ $data ]);
+
+ # print without var names and with simple indentation
+ print $fh $dumper->Terse(1)->Dump();
+ close $fh;
+}
+
1;
[33/36] incubator-trafficcontrol git commit: Changed format of
dbconf.yml to more closely match format of old postinstall
Posted by da...@apache.org.
Changed format of dbconf.yml to more closely match format of old postinstall
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/ed582864
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/ed582864
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/ed582864
Branch: refs/heads/master
Commit: ed5828644972949b054ce5d1ddab121655eb7df9
Parents: 2778409
Author: peryder <pe...@cisco.com>
Authored: Mon Dec 19 15:06:29 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall-new | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/ed582864/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
index 08ba7a7..1092338 100755
--- a/traffic_ops/install/bin/postinstall-new
+++ b/traffic_ops/install/bin/postinstall-new
@@ -172,11 +172,9 @@ sub generateDbConf {
# No YAML library installed, but this is a simple file..
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";
- print $fh " driver: ", getDbDriver() . "\n";
- print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{user}/$dbconf{password}\n";
+ print $fh " driver: ", getDbDriver() . "\n";
+ print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{user}/$dbconf{password}\n";
close $fh;
return \%todbconf;
[26/36] incubator-trafficcontrol git commit: Changed filename to
postinstall-new
Posted by da...@apache.org.
Changed filename to postinstall-new
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/7ba725b1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/7ba725b1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/7ba725b1
Branch: refs/heads/master
Commit: 7ba725b101e2bc2f4ebfdd183b2c353b7374e077
Parents: 7054561
Author: peryder <pe...@cisco.com>
Authored: Wed Dec 7 10:59:30 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall-new | 781 +++++++++++++++++++
.../install/bin/postinstall-new-integrated | 781 -------------------
2 files changed, 781 insertions(+), 781 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7ba725b1/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
new file mode 100755
index 0000000..9972daa
--- /dev/null
+++ b/traffic_ops/install/bin/postinstall-new
@@ -0,0 +1,781 @@
+#!/usr/bin/perl
+
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
+$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
+$ENV{PERL5LIB} = "/opt/traffic_ops/install/lib:/opt/traffic_ops/install/lib/perl5:/opt/traffic_ops/app/local/lib/perl5:/opt/traffic_ops/app/lib";
+
+use strict;
+use warnings;
+
+use Safe;
+use POSIX;
+use File::Basename qw{dirname};
+use File::Path qw{make_path};
+use InstallUtils qw{ :all };
+use BuildPerlDeps qw{ :all };
+use GenerateCert qw{ :all };
+use ProfileCleanup qw { :all };
+use Digest::SHA1 qw(sha1_hex);
+use Data::Dumper qw(Dumper);
+use Scalar::Util qw(looks_like_number);
+use Getopt::Long;
+
+# paths of the output configuration files
+our $databaseConfFile = "/opt/traffic_ops/app/conf/production/database.conf";
+our $dbConfFile = "/opt/traffic_ops/app/db/dbconf.yml";
+our $cdnConfFile = "/opt/traffic_ops/app/conf/cdn.conf";
+our $ldapConfFile = "/opt/traffic_ops/app/conf/ldap.conf";
+our $usersConfFile = "/opt/traffic_ops/install/data/json/users.json";
+our $profilesConfFile = "/opt/traffic_ops/install/data/profiles/";
+our $opensslConfFile = "/opt/traffic_ops/install/bin/openssl_configuration.json";
+our $paramConfFile = "/opt/traffic_ops/install/data/json/profiles.json";
+
+our $profile_dir = "/opt/traffic_ops/install/data/profiles/";
+our $post_install_cfg = "/opt/traffic_ops/install/data/json/post_install.json";
+
+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
+our $logFile = "/var/log/traffic_ops/postinstall.log";
+
+# maximum size the uncompressed log file should be before rotating it - rotating it copies the current log
+# file to the same name appended with .bkp replacing the old backup if any is there
+my $maxLogSize = 1000000; #bytes
+
+# log file for cpan - this log becomes large and is rotated every install
+our $cpanLogFile = "/var/log/traffic_ops/cpan.log";
+
+# configuration file output with answers which can be used as input to postinstall
+our $outputConfigFile = "/var/log/traffic_ops/configuration_file.json";
+
+sub getDbDriver {
+ return "mymysql";
+}
+
+sub getInstallPath {
+ my $relPath = shift;
+ return join( '/', "/tmp/traffic_ops", $relPath );
+}
+
+# given a var to the hash of config_var and question, will return the question
+sub getConfigQuestion {
+ my $var = shift;
+ foreach my $key ( keys $var ) {
+ if ( $key ne "hidden" && $key ne "config_var" ) {
+ return $key;
+ }
+ }
+}
+
+# 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
+
+sub getField {
+ my $question = shift;
+ my $config_answer = shift;
+ my $hidden = shift;
+
+ # 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);
+ }
+ else {
+ return promptUser( $question, $config_answer );
+ }
+ }
+
+ return $config_answer;
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+# fileName: The name of the output config file given by the input config file
+#
+# Loops through an input config file and determines answers to each question using getField
+# and returns the hash of answers
+
+sub getConfig {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %config;
+
+ if ( !defined $userInput->{$fileName} ) {
+ logger( "No $fileName found in config", "error" );
+ }
+
+ 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 );
+
+ $config{ $var->{"config_var"} } = $answer;
+ if ( !$hidden ) {
+ logger( "$question: $answer", "info" );
+ }
+ }
+ return %config;
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+# dbFileName: The filename of the output config file for the database
+# toDBFileName: The filename of the output config file for the Traffic Ops database
+#
+# Generates a config file for the database based on the questions and answers in the input config file
+
+sub generateDbConf {
+ my $userInput = shift;
+ my $dbFileName = shift;
+ my $toDBFileName = shift;
+
+ my %dbconf = getConfig( $userInput, $dbFileName );
+
+ make_path( dirname($dbFileName), { mode => 0755 } );
+ writeJson( $dbFileName, \%dbconf );
+ logger( "Database configuration has been saved", "info" );
+
+ # broken out into separate file/config area
+ 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!");
+ print $fh "version: 1.0\n";
+ print $fh "name: dbconf.yml\n\n";
+ print $fh "production:\n";
+ print $fh " driver: ", getDbDriver() . "\n";
+ print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{user}/$dbconf{password}\n";
+ close $fh;
+
+ return \%todbconf;
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+# fileName: The filename of the output config file
+#
+# Generates a config file for the CDN
+
+sub generateCdnConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %cdnConfiguration = getConfig( $userInput, $fileName );
+
+ # 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: $@");
+ }
+ if ( lc $cdnConfiguration{genSecret} =~ /^y(?:es)?/ ) {
+ my @secrets = @{ $cdnConf->{secrets} };
+ my $newSecret = randomWord();
+ unshift @secrets, randomWord();
+ if ( $cdnConfiguration{keepSecrets} > 0 && $#secrets > $cdnConfiguration{keepSecrets} - 1 ) {
+
+ # Shorten the array to requested length
+ $#secrets = $cdnConfiguration{keepSecrets} - 1;
+ }
+ }
+ writePerl( $fileName, $cdnConf );
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+# fileName: The filename of the output config file
+#
+# Generates an LDAP config file
+
+sub generateLdapConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my $useLdap = $userInput->{$fileName}[0]->{"Do you want to set up LDAP?"};
+
+ if ( $useLdap eq "no" || $useLdap eq "n" ) {
+ logger( "Not setting up ldap", "info" );
+
+ return;
+ }
+
+ my %ldapConf = getConfig( $userInput, $fileName );
+
+ make_path( dirname($fileName), { mode => 0755 } );
+ writeJson( $fileName, \%ldapConf );
+}
+
+sub generateUsersConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %user = ();
+ my %config = getConfig( $userInput, $fileName );
+
+ $user{username} = $config{tmAdminUser};
+ $user{password} = sha1_hex( $config{tmAdminPw} );
+
+ writeJson( $fileName, \%user );
+ $user{password} = $config{tmAdminPw};
+ return \%user;
+}
+
+sub generateProfilesDir {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my $userIn = $userInput->{$fileName};
+}
+
+sub generateOpenSSLConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ 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;
+ }
+
+ my %config = getConfig( $userInput, $fileName );
+
+ writeJson( $fileName, \%config );
+}
+
+sub generateParamConf {
+ my $userInput = shift;
+ my $fileName = shift;
+
+ my %config = getConfig( $userInput, $fileName );
+ return \%config;
+}
+
+# check default values for missing config_var parameter
+sub sanityCheckDefaults {
+ foreach my $file ( ( keys $::defaultInputs ) ) {
+ foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
+ my $question = getConfigQuestion($defaultValue);
+
+ if ( !defined $defaultValue->{"config_var"}
+ || $defaultValue->{"config_var"} eq "" )
+ {
+ errorOut("Question '$question' in file '$file' has no config_var");
+ }
+ }
+ }
+}
+
+# userInput: The entire input config file which is either user input or the defaults
+#
+# Checks the input config file against the default inputs. If there is a question located in the default inputs which
+# is not located in the input config file it will output a warning message.
+#
+# This does not check the other way meaning questions which are present in defaults but not present in the input config
+# file will not be checked
+
+sub sanityCheckConfig {
+ my $userInput = shift;
+ my $diffs = 0;
+
+ foreach my $file ( ( keys $::defaultInputs ) ) {
+ if ( !defined $userInput->{$file} ) {
+ logger( "File '$file' found in defaults but not config file", "warn" );
+ $userInput->{$file} = [];
+ }
+
+ foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
+
+ my $found = 0;
+ foreach my $configValue ( @{ $userInput->{$file} } ) {
+ if ( $defaultValue->{"config_var"} eq $configValue->{"config_var"} ) {
+ $found = 1;
+ }
+ }
+
+ # if the question is not found in the config file add it from defaults
+ if ( !$found ) {
+ 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) {
+ $answer = $defaultValue->{$question};
+ logger( "Adding question '$question' with default answer " . ( $hidden ? "" : "'$answer'" ), "info" );
+ }
+
+ # in interactive mode prompt the user for answer to missing question
+ else {
+ logger( "Prompting user for answer", "info" );
+ if ($hidden) {
+ $answer = promptPasswordVerify($question);
+ }
+ else {
+ $answer = promptUser( $question, $defaultValue->{$question} );
+ }
+ }
+
+ %temp = (
+ "config_var" => $defaultValue->{"config_var"},
+ $question => $answer
+ );
+
+ if ($hidden) {
+ $temp{"hidden"} .= "true";
+ }
+
+ push $userInput->{$file}, \%temp;
+
+ $diffs++;
+ }
+ }
+ }
+
+ 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
+# user input config file or if there are questions in the input config file which do not have answers
+
+sub getDefaults {
+ return {
+ $::databaseConfFile => [
+ {
+ "Database type" => "mysql",
+ "config_var" => "type"
+ },
+ {
+ "Database name" => "traffic_ops",
+ "config_var" => "dbname"
+ },
+ {
+ "Database server hostname IP or FQDN" => "localhost",
+ "config_var" => "hostname"
+ },
+ {
+ "Database port number" => "3306",
+ "config_var" => "port"
+ },
+ {
+ "Traffic Ops database user" => "traffic_ops",
+ "config_var" => "user"
+ },
+ {
+ "Password for Traffic Ops database user" => "",
+ "config_var" => "password",
+ "hidden" => "true"
+ }
+ ],
+ $::dbConfFile => [
+ {
+ "Database server root (admin) user" => "root",
+ "config_var" => "dbAdminUser"
+ },
+ {
+ "Password for database server admin" => "",
+ "config_var" => "dbAdminPw",
+ "hidden" => "true"
+ }
+ ],
+ $::cdnConfFile => [
+ {
+ "Generate a new secret?" => "yes",
+ "config_var" => "genSecret"
+ },
+ {
+ "Number of secrets to keep?" => "10",
+ "config_var" => "keepSecrets"
+ }
+ ],
+ $::ldapConfFile => [
+ {
+ "Do you want to set up LDAP?" => "no",
+ "config_var" => "setupLdap"
+ },
+ {
+ "LDAP server hostname" => "",
+ "config_var" => "hostname"
+ },
+ {
+ "LDAP Admin DN" => "",
+ "config_var" => "admin_dn"
+ },
+ {
+ "LDAP Admin Password" => "",
+ "config_var" => "password",
+ "hidden" => "true"
+ },
+ {
+ "LDAP Search Base" => "",
+ "config_var" => "search_base"
+ }
+ ],
+ $::usersConfFile => [
+ {
+ "Administration username for Traffic Ops" => "admin",
+ "config_var" => "tmAdminUser"
+ },
+ {
+ "Password for the admin user" => "",
+ "config_var" => "tmAdminPw",
+ "hidden" => "true"
+ }
+ ],
+ $::profilesConfFile => [],
+ $::opensslConfFile => [
+ {
+ "Country Name (2 letter code)" => "XX",
+ "config_var" => "country"
+ },
+ {
+ "State or Province Name (full name)" => "San Jose",
+ "config_var" => "state"
+ },
+ {
+ "Locality Name (eg, city)" => "Default City",
+ "config_var" => "locality"
+ },
+ {
+ "Organization Name (eg, company)" => "Default Company Ltd",
+ "config_var" => "company"
+ },
+ {
+ "Organizational Unit Name (eg, section)" => "",
+ "config_var" => "org_unit"
+ },
+ {
+ "Common Name (eg, your name or your server's hostname)" => "cisco.com",
+ "config_var" => "common_name"
+ },
+ {
+ "RSA Passphrase" => "",
+ "config_var" => "rsaPassword",
+ "hidden" => "true"
+ }
+ ],
+ $::paramConfFile => [
+ {
+ "Traffic Ops url" => "https://localhost",
+ "config_var" => "tm.url"
+ },
+ {
+ "Human-readable CDN Name. (No whitespace, please)" => "kabletown_cdn",
+ "config_var" => "cdn_name"
+ },
+ {
+ "Health Polling Interval (milliseconds)" => "8000",
+ "config_var" => "health_polling_int"
+ },
+ {
+ "DNS sub-domain for which your CDN is authoritative" => "cdn1.kabletown.net",
+ "config_var" => "dns_subdomain"
+ },
+ {
+ "TLD SOA admin" => "traffic_ops",
+ "config_var" => "soa_admin"
+ },
+ {
+ "TrafficServer Drive Prefix" => "/dev/sd",
+ "config_var" => "driver_prefix"
+ },
+ {
+ "TrafficServer RAM Drive Prefix" => "/dev/ram",
+ "config_var" => "ram_drive_prefix"
+ },
+ {
+ "TrafficServer RAM Drive Letters (comma separated)" => "0,1,2,3,4,5,6,7",
+ "config_var" => "ram_drive_letters"
+ },
+ {
+ "Health Threshold Load Average" => "25",
+ "config_var" => "health_thresh_load_avg"
+ },
+ {
+ "Health Threshold Available Bandwidth in Kbps" => "1750000",
+ "config_var" => "health_thresh_kbps"
+ },
+ {
+ "Traffic Server Health Connection Timeout (milliseconds)" => "2000",
+ "config_var" => "health_connect_timeout"
+ }
+
+ ]
+ };
+}
+
+# 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;
+
+ #
+ # Call mysql initialization script.
+ #
+ logger( "Creating database with user: $todbconf->{dbAdminUser}", "info" );
+ my $result = execCommand( "/opt/traffic_ops/install/bin/create_db", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
+ if ( $result != 0 ) {
+ errorOut("Failed to create the database");
+ }
+
+ logger( "Setting up database", "info" );
+ chdir("/opt/traffic_ops/app");
+ $result = execCommand( "/usr/bin/perl", "db/admin.pl", "--env=production", "setup" );
+
+ if ( $result != 0 ) {
+ errorOut("Database initialization failed");
+ }
+ else {
+ logger( "Database initialization succeeded", "info" );
+ }
+
+ $result = execCommand( "/opt/traffic_ops/install/bin/dataload", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
+ if ( $result != 0 ) {
+ logger( "Failed to load seed data", "error" );
+ }
+
+ 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");
+ if ( $result != 0 ) {
+ logger( "Failed to download MaxMind data", "error" );
+ }
+
+ logger( "Copying coverage zone file to public dir", "info" );
+ $result = execCommand("/bin/mv /opt/traffic_ops/app/public/coverage-zone.json .");
+ if ( $result != 0 ) {
+ logger( "Failed to copy coverage zone file", "error" );
+ }
+
+ if ( -x "/usr/bin/openssl" ) {
+ logger( "Installing SSL Certificates", "info" );
+ $result = GenerateCert::createCert($opensslconf);
+
+ if ( $result != 0 ) {
+ errorOut("SSL Certificate Installation failed");
+ }
+ else {
+ logger( "SSL Certificates have been installed", "info" );
+ }
+ }
+ else {
+ logger( "Unable to install SSL certificates as openssl is not installed", "error" );
+ logger( "Install openssl and then run /opt/traffic_ops/install/bin/generateCert to install SSL certificates", "error" );
+ exit 4;
+ }
+
+}
+
+# -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 = "";
+ our $automatic = 0;
+ our $debug = 0;
+ my $help = 0;
+
+ my $usageString = "Usage: postinstall [-a] [-debug] [-defaults] [-r] -cfile=[config_file]\n";
+
+ GetOptions(
+ "cfile=s" => \$inputFile,
+ "automatic" => \$automatic,
+ "reconfigure" => \$reconfigure,
+ "defaults" => \$dumpDefaults,
+ "debug" => \$debug,
+ "help" => \$help
+ ) or die($usageString);
+
+ # stores the default questions and answers
+ our $defaultInputs = getDefaults();
+
+ if ($help) {
+ print $usageString;
+ 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" );
+
+ 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" );
+ return;
+ }
+
+ if ($dumpDefaults) {
+ logger( "Writing default configuration file to $outputConfigFile", "info" );
+ writeJson( $outputConfigFile, $::defaultInputs );
+ return;
+ }
+
+ logger( "Postinstall " . ( defined $reconfigure ? "in" : "not" ) . " in reconfigure mode", "info" );
+
+ # check if the user has root access
+ if ( $ENV{USER} ne "root" ) {
+ errorOut("You must run this script as the root user");
+ }
+
+ rotateLog($cpanLogFile);
+
+ if ( -s $::logFile > $maxLogSize ) {
+ logger( "Postinstall log above max size of $maxLogSize bytes - rotating", "info" );
+ rotateLog($logFile);
+ }
+
+ # used to store the questions and answers provided by the user
+ my $userInput;
+
+ # if no input file provided use the defaults
+ if ( $::inputFile eq "" ) {
+ logger( "No input file given - using defaults", "info" );
+ $userInput = $::defaultInputs;
+ }
+ else {
+ logger( "Using input file $::inputFile", "info" );
+
+ # check if the input file exists
+ errorOut("File '$::inputFile' not found") if ( !-f $::inputFile );
+
+ # read and store the input file
+ $userInput = readJson($::inputFile);
+ }
+
+ # sanity check the defaults if running them automatically
+ sanityCheckDefaults();
+
+ # check the input config file against the defaults to check for missing questions
+ sanityCheckConfig($userInput) if ( $inputFile ne "" );
+
+ chdir("/opt/traffic_ops/install/bin");
+
+ # if the reconfigure file exists or reconfigure is set then rebuild the perl deps
+ 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");
+ }
+ $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");
+ }
+ }
+ 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");
+ }
+ $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");
+ }
+ }
+
+ # The generator functions handle checking input/default/automatic mode
+
+ # todbconf will be used later when setting up the database
+ my $todbconf = generateDbConf( $userInput, $::databaseConfFile, $::dbConfFile );
+ generateCdnConf( $userInput, $::cdnConfFile );
+ generateLdapConf( $userInput, $::ldapConfFile );
+ my $adminconf = generateUsersConf( $userInput, $::usersConfFile );
+ generateProfilesDir( $userInput, $::profilesConfFile );
+ generateOpenSSLConf( $userInput, $::opensslConfFile );
+ my $paramconf = generateParamConf( $userInput, $::paramConfFile );
+
+ # if the reconfigure file exists or the reconfigure command line arg is set then setup the database
+ if ( -f $reconfigure_file || $reconfigure ) {
+ if ($::automatic) {
+ setupDatabase( $todbconf, $::opensslConfFile );
+ }
+ else {
+ setupDatabase( $todbconf, 0 );
+ }
+ }
+
+ # remove the reconfigure file if it exists
+ if ( -f $reconfigure_file ) {
+ logger( "Removing reconfigure file", "info" );
+ unlink($reconfigure_file);
+ }
+
+ logger( "Starting Traffic Ops", "info" );
+ execCommand("/sbin/service traffic_ops start");
+
+ logger( "Waiting for Traffic Ops to start", "info" );
+
+ if ( !profiles_exist( $adminconf, $paramconf->{"tm.url"} ) ) {
+ logger( "Creating default profiles...", "info" );
+ replace_profile_templates($paramconf);
+ import_profiles($adminconf);
+ profiles_exist( $adminconf, $paramconf->{"tm.url"} ); # call again to create $reconfigure_defaults file if import was successful
+ }
+ else {
+ logger( "Not creating default profiles", "info" );
+ }
+
+ logger("Postinstall complete");
+
+ execCommand( "/bin/gzip", "$logFile" );
+}
+
+main;
+
+# vi:syntax=perl
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7ba725b1/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
deleted file mode 100755
index 9972daa..0000000
--- a/traffic_ops/install/bin/postinstall-new-integrated
+++ /dev/null
@@ -1,781 +0,0 @@
-#!/usr/bin/perl
-
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
-$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
-$ENV{PERL5LIB} = "/opt/traffic_ops/install/lib:/opt/traffic_ops/install/lib/perl5:/opt/traffic_ops/app/local/lib/perl5:/opt/traffic_ops/app/lib";
-
-use strict;
-use warnings;
-
-use Safe;
-use POSIX;
-use File::Basename qw{dirname};
-use File::Path qw{make_path};
-use InstallUtils qw{ :all };
-use BuildPerlDeps qw{ :all };
-use GenerateCert qw{ :all };
-use ProfileCleanup qw { :all };
-use Digest::SHA1 qw(sha1_hex);
-use Data::Dumper qw(Dumper);
-use Scalar::Util qw(looks_like_number);
-use Getopt::Long;
-
-# paths of the output configuration files
-our $databaseConfFile = "/opt/traffic_ops/app/conf/production/database.conf";
-our $dbConfFile = "/opt/traffic_ops/app/db/dbconf.yml";
-our $cdnConfFile = "/opt/traffic_ops/app/conf/cdn.conf";
-our $ldapConfFile = "/opt/traffic_ops/app/conf/ldap.conf";
-our $usersConfFile = "/opt/traffic_ops/install/data/json/users.json";
-our $profilesConfFile = "/opt/traffic_ops/install/data/profiles/";
-our $opensslConfFile = "/opt/traffic_ops/install/bin/openssl_configuration.json";
-our $paramConfFile = "/opt/traffic_ops/install/data/json/profiles.json";
-
-our $profile_dir = "/opt/traffic_ops/install/data/profiles/";
-our $post_install_cfg = "/opt/traffic_ops/install/data/json/post_install.json";
-
-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
-our $logFile = "/var/log/traffic_ops/postinstall.log";
-
-# maximum size the uncompressed log file should be before rotating it - rotating it copies the current log
-# file to the same name appended with .bkp replacing the old backup if any is there
-my $maxLogSize = 1000000; #bytes
-
-# log file for cpan - this log becomes large and is rotated every install
-our $cpanLogFile = "/var/log/traffic_ops/cpan.log";
-
-# configuration file output with answers which can be used as input to postinstall
-our $outputConfigFile = "/var/log/traffic_ops/configuration_file.json";
-
-sub getDbDriver {
- return "mymysql";
-}
-
-sub getInstallPath {
- my $relPath = shift;
- return join( '/', "/tmp/traffic_ops", $relPath );
-}
-
-# given a var to the hash of config_var and question, will return the question
-sub getConfigQuestion {
- my $var = shift;
- foreach my $key ( keys $var ) {
- if ( $key ne "hidden" && $key ne "config_var" ) {
- return $key;
- }
- }
-}
-
-# 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
-
-sub getField {
- my $question = shift;
- my $config_answer = shift;
- my $hidden = shift;
-
- # 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);
- }
- else {
- return promptUser( $question, $config_answer );
- }
- }
-
- return $config_answer;
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-# fileName: The name of the output config file given by the input config file
-#
-# Loops through an input config file and determines answers to each question using getField
-# and returns the hash of answers
-
-sub getConfig {
- my $userInput = shift;
- my $fileName = shift;
-
- my %config;
-
- if ( !defined $userInput->{$fileName} ) {
- logger( "No $fileName found in config", "error" );
- }
-
- 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 );
-
- $config{ $var->{"config_var"} } = $answer;
- if ( !$hidden ) {
- logger( "$question: $answer", "info" );
- }
- }
- return %config;
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-# dbFileName: The filename of the output config file for the database
-# toDBFileName: The filename of the output config file for the Traffic Ops database
-#
-# Generates a config file for the database based on the questions and answers in the input config file
-
-sub generateDbConf {
- my $userInput = shift;
- my $dbFileName = shift;
- my $toDBFileName = shift;
-
- my %dbconf = getConfig( $userInput, $dbFileName );
-
- make_path( dirname($dbFileName), { mode => 0755 } );
- writeJson( $dbFileName, \%dbconf );
- logger( "Database configuration has been saved", "info" );
-
- # broken out into separate file/config area
- 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!");
- print $fh "version: 1.0\n";
- print $fh "name: dbconf.yml\n\n";
- print $fh "production:\n";
- print $fh " driver: ", getDbDriver() . "\n";
- print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{user}/$dbconf{password}\n";
- close $fh;
-
- return \%todbconf;
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-# fileName: The filename of the output config file
-#
-# Generates a config file for the CDN
-
-sub generateCdnConf {
- my $userInput = shift;
- my $fileName = shift;
-
- my %cdnConfiguration = getConfig( $userInput, $fileName );
-
- # 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: $@");
- }
- if ( lc $cdnConfiguration{genSecret} =~ /^y(?:es)?/ ) {
- my @secrets = @{ $cdnConf->{secrets} };
- my $newSecret = randomWord();
- unshift @secrets, randomWord();
- if ( $cdnConfiguration{keepSecrets} > 0 && $#secrets > $cdnConfiguration{keepSecrets} - 1 ) {
-
- # Shorten the array to requested length
- $#secrets = $cdnConfiguration{keepSecrets} - 1;
- }
- }
- writePerl( $fileName, $cdnConf );
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-# fileName: The filename of the output config file
-#
-# Generates an LDAP config file
-
-sub generateLdapConf {
- my $userInput = shift;
- my $fileName = shift;
-
- my $useLdap = $userInput->{$fileName}[0]->{"Do you want to set up LDAP?"};
-
- if ( $useLdap eq "no" || $useLdap eq "n" ) {
- logger( "Not setting up ldap", "info" );
-
- return;
- }
-
- my %ldapConf = getConfig( $userInput, $fileName );
-
- make_path( dirname($fileName), { mode => 0755 } );
- writeJson( $fileName, \%ldapConf );
-}
-
-sub generateUsersConf {
- my $userInput = shift;
- my $fileName = shift;
-
- my %user = ();
- my %config = getConfig( $userInput, $fileName );
-
- $user{username} = $config{tmAdminUser};
- $user{password} = sha1_hex( $config{tmAdminPw} );
-
- writeJson( $fileName, \%user );
- $user{password} = $config{tmAdminPw};
- return \%user;
-}
-
-sub generateProfilesDir {
- my $userInput = shift;
- my $fileName = shift;
-
- my $userIn = $userInput->{$fileName};
-}
-
-sub generateOpenSSLConf {
- my $userInput = shift;
- my $fileName = shift;
-
- 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;
- }
-
- my %config = getConfig( $userInput, $fileName );
-
- writeJson( $fileName, \%config );
-}
-
-sub generateParamConf {
- my $userInput = shift;
- my $fileName = shift;
-
- my %config = getConfig( $userInput, $fileName );
- return \%config;
-}
-
-# check default values for missing config_var parameter
-sub sanityCheckDefaults {
- foreach my $file ( ( keys $::defaultInputs ) ) {
- foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
- my $question = getConfigQuestion($defaultValue);
-
- if ( !defined $defaultValue->{"config_var"}
- || $defaultValue->{"config_var"} eq "" )
- {
- errorOut("Question '$question' in file '$file' has no config_var");
- }
- }
- }
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-#
-# Checks the input config file against the default inputs. If there is a question located in the default inputs which
-# is not located in the input config file it will output a warning message.
-#
-# This does not check the other way meaning questions which are present in defaults but not present in the input config
-# file will not be checked
-
-sub sanityCheckConfig {
- my $userInput = shift;
- my $diffs = 0;
-
- foreach my $file ( ( keys $::defaultInputs ) ) {
- if ( !defined $userInput->{$file} ) {
- logger( "File '$file' found in defaults but not config file", "warn" );
- $userInput->{$file} = [];
- }
-
- foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
-
- my $found = 0;
- foreach my $configValue ( @{ $userInput->{$file} } ) {
- if ( $defaultValue->{"config_var"} eq $configValue->{"config_var"} ) {
- $found = 1;
- }
- }
-
- # if the question is not found in the config file add it from defaults
- if ( !$found ) {
- 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) {
- $answer = $defaultValue->{$question};
- logger( "Adding question '$question' with default answer " . ( $hidden ? "" : "'$answer'" ), "info" );
- }
-
- # in interactive mode prompt the user for answer to missing question
- else {
- logger( "Prompting user for answer", "info" );
- if ($hidden) {
- $answer = promptPasswordVerify($question);
- }
- else {
- $answer = promptUser( $question, $defaultValue->{$question} );
- }
- }
-
- %temp = (
- "config_var" => $defaultValue->{"config_var"},
- $question => $answer
- );
-
- if ($hidden) {
- $temp{"hidden"} .= "true";
- }
-
- push $userInput->{$file}, \%temp;
-
- $diffs++;
- }
- }
- }
-
- 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
-# user input config file or if there are questions in the input config file which do not have answers
-
-sub getDefaults {
- return {
- $::databaseConfFile => [
- {
- "Database type" => "mysql",
- "config_var" => "type"
- },
- {
- "Database name" => "traffic_ops",
- "config_var" => "dbname"
- },
- {
- "Database server hostname IP or FQDN" => "localhost",
- "config_var" => "hostname"
- },
- {
- "Database port number" => "3306",
- "config_var" => "port"
- },
- {
- "Traffic Ops database user" => "traffic_ops",
- "config_var" => "user"
- },
- {
- "Password for Traffic Ops database user" => "",
- "config_var" => "password",
- "hidden" => "true"
- }
- ],
- $::dbConfFile => [
- {
- "Database server root (admin) user" => "root",
- "config_var" => "dbAdminUser"
- },
- {
- "Password for database server admin" => "",
- "config_var" => "dbAdminPw",
- "hidden" => "true"
- }
- ],
- $::cdnConfFile => [
- {
- "Generate a new secret?" => "yes",
- "config_var" => "genSecret"
- },
- {
- "Number of secrets to keep?" => "10",
- "config_var" => "keepSecrets"
- }
- ],
- $::ldapConfFile => [
- {
- "Do you want to set up LDAP?" => "no",
- "config_var" => "setupLdap"
- },
- {
- "LDAP server hostname" => "",
- "config_var" => "hostname"
- },
- {
- "LDAP Admin DN" => "",
- "config_var" => "admin_dn"
- },
- {
- "LDAP Admin Password" => "",
- "config_var" => "password",
- "hidden" => "true"
- },
- {
- "LDAP Search Base" => "",
- "config_var" => "search_base"
- }
- ],
- $::usersConfFile => [
- {
- "Administration username for Traffic Ops" => "admin",
- "config_var" => "tmAdminUser"
- },
- {
- "Password for the admin user" => "",
- "config_var" => "tmAdminPw",
- "hidden" => "true"
- }
- ],
- $::profilesConfFile => [],
- $::opensslConfFile => [
- {
- "Country Name (2 letter code)" => "XX",
- "config_var" => "country"
- },
- {
- "State or Province Name (full name)" => "San Jose",
- "config_var" => "state"
- },
- {
- "Locality Name (eg, city)" => "Default City",
- "config_var" => "locality"
- },
- {
- "Organization Name (eg, company)" => "Default Company Ltd",
- "config_var" => "company"
- },
- {
- "Organizational Unit Name (eg, section)" => "",
- "config_var" => "org_unit"
- },
- {
- "Common Name (eg, your name or your server's hostname)" => "cisco.com",
- "config_var" => "common_name"
- },
- {
- "RSA Passphrase" => "",
- "config_var" => "rsaPassword",
- "hidden" => "true"
- }
- ],
- $::paramConfFile => [
- {
- "Traffic Ops url" => "https://localhost",
- "config_var" => "tm.url"
- },
- {
- "Human-readable CDN Name. (No whitespace, please)" => "kabletown_cdn",
- "config_var" => "cdn_name"
- },
- {
- "Health Polling Interval (milliseconds)" => "8000",
- "config_var" => "health_polling_int"
- },
- {
- "DNS sub-domain for which your CDN is authoritative" => "cdn1.kabletown.net",
- "config_var" => "dns_subdomain"
- },
- {
- "TLD SOA admin" => "traffic_ops",
- "config_var" => "soa_admin"
- },
- {
- "TrafficServer Drive Prefix" => "/dev/sd",
- "config_var" => "driver_prefix"
- },
- {
- "TrafficServer RAM Drive Prefix" => "/dev/ram",
- "config_var" => "ram_drive_prefix"
- },
- {
- "TrafficServer RAM Drive Letters (comma separated)" => "0,1,2,3,4,5,6,7",
- "config_var" => "ram_drive_letters"
- },
- {
- "Health Threshold Load Average" => "25",
- "config_var" => "health_thresh_load_avg"
- },
- {
- "Health Threshold Available Bandwidth in Kbps" => "1750000",
- "config_var" => "health_thresh_kbps"
- },
- {
- "Traffic Server Health Connection Timeout (milliseconds)" => "2000",
- "config_var" => "health_connect_timeout"
- }
-
- ]
- };
-}
-
-# 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;
-
- #
- # Call mysql initialization script.
- #
- logger( "Creating database with user: $todbconf->{dbAdminUser}", "info" );
- my $result = execCommand( "/opt/traffic_ops/install/bin/create_db", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
- if ( $result != 0 ) {
- errorOut("Failed to create the database");
- }
-
- logger( "Setting up database", "info" );
- chdir("/opt/traffic_ops/app");
- $result = execCommand( "/usr/bin/perl", "db/admin.pl", "--env=production", "setup" );
-
- if ( $result != 0 ) {
- errorOut("Database initialization failed");
- }
- else {
- logger( "Database initialization succeeded", "info" );
- }
-
- $result = execCommand( "/opt/traffic_ops/install/bin/dataload", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
- if ( $result != 0 ) {
- logger( "Failed to load seed data", "error" );
- }
-
- 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");
- if ( $result != 0 ) {
- logger( "Failed to download MaxMind data", "error" );
- }
-
- logger( "Copying coverage zone file to public dir", "info" );
- $result = execCommand("/bin/mv /opt/traffic_ops/app/public/coverage-zone.json .");
- if ( $result != 0 ) {
- logger( "Failed to copy coverage zone file", "error" );
- }
-
- if ( -x "/usr/bin/openssl" ) {
- logger( "Installing SSL Certificates", "info" );
- $result = GenerateCert::createCert($opensslconf);
-
- if ( $result != 0 ) {
- errorOut("SSL Certificate Installation failed");
- }
- else {
- logger( "SSL Certificates have been installed", "info" );
- }
- }
- else {
- logger( "Unable to install SSL certificates as openssl is not installed", "error" );
- logger( "Install openssl and then run /opt/traffic_ops/install/bin/generateCert to install SSL certificates", "error" );
- exit 4;
- }
-
-}
-
-# -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 = "";
- our $automatic = 0;
- our $debug = 0;
- my $help = 0;
-
- my $usageString = "Usage: postinstall [-a] [-debug] [-defaults] [-r] -cfile=[config_file]\n";
-
- GetOptions(
- "cfile=s" => \$inputFile,
- "automatic" => \$automatic,
- "reconfigure" => \$reconfigure,
- "defaults" => \$dumpDefaults,
- "debug" => \$debug,
- "help" => \$help
- ) or die($usageString);
-
- # stores the default questions and answers
- our $defaultInputs = getDefaults();
-
- if ($help) {
- print $usageString;
- 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" );
-
- 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" );
- return;
- }
-
- if ($dumpDefaults) {
- logger( "Writing default configuration file to $outputConfigFile", "info" );
- writeJson( $outputConfigFile, $::defaultInputs );
- return;
- }
-
- logger( "Postinstall " . ( defined $reconfigure ? "in" : "not" ) . " in reconfigure mode", "info" );
-
- # check if the user has root access
- if ( $ENV{USER} ne "root" ) {
- errorOut("You must run this script as the root user");
- }
-
- rotateLog($cpanLogFile);
-
- if ( -s $::logFile > $maxLogSize ) {
- logger( "Postinstall log above max size of $maxLogSize bytes - rotating", "info" );
- rotateLog($logFile);
- }
-
- # used to store the questions and answers provided by the user
- my $userInput;
-
- # if no input file provided use the defaults
- if ( $::inputFile eq "" ) {
- logger( "No input file given - using defaults", "info" );
- $userInput = $::defaultInputs;
- }
- else {
- logger( "Using input file $::inputFile", "info" );
-
- # check if the input file exists
- errorOut("File '$::inputFile' not found") if ( !-f $::inputFile );
-
- # read and store the input file
- $userInput = readJson($::inputFile);
- }
-
- # sanity check the defaults if running them automatically
- sanityCheckDefaults();
-
- # check the input config file against the defaults to check for missing questions
- sanityCheckConfig($userInput) if ( $inputFile ne "" );
-
- chdir("/opt/traffic_ops/install/bin");
-
- # if the reconfigure file exists or reconfigure is set then rebuild the perl deps
- 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");
- }
- $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");
- }
- }
- 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");
- }
- $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");
- }
- }
-
- # The generator functions handle checking input/default/automatic mode
-
- # todbconf will be used later when setting up the database
- my $todbconf = generateDbConf( $userInput, $::databaseConfFile, $::dbConfFile );
- generateCdnConf( $userInput, $::cdnConfFile );
- generateLdapConf( $userInput, $::ldapConfFile );
- my $adminconf = generateUsersConf( $userInput, $::usersConfFile );
- generateProfilesDir( $userInput, $::profilesConfFile );
- generateOpenSSLConf( $userInput, $::opensslConfFile );
- my $paramconf = generateParamConf( $userInput, $::paramConfFile );
-
- # if the reconfigure file exists or the reconfigure command line arg is set then setup the database
- if ( -f $reconfigure_file || $reconfigure ) {
- if ($::automatic) {
- setupDatabase( $todbconf, $::opensslConfFile );
- }
- else {
- setupDatabase( $todbconf, 0 );
- }
- }
-
- # remove the reconfigure file if it exists
- if ( -f $reconfigure_file ) {
- logger( "Removing reconfigure file", "info" );
- unlink($reconfigure_file);
- }
-
- logger( "Starting Traffic Ops", "info" );
- execCommand("/sbin/service traffic_ops start");
-
- logger( "Waiting for Traffic Ops to start", "info" );
-
- if ( !profiles_exist( $adminconf, $paramconf->{"tm.url"} ) ) {
- logger( "Creating default profiles...", "info" );
- replace_profile_templates($paramconf);
- import_profiles($adminconf);
- profiles_exist( $adminconf, $paramconf->{"tm.url"} ); # call again to create $reconfigure_defaults file if import was successful
- }
- else {
- logger( "Not creating default profiles", "info" );
- }
-
- logger("Postinstall complete");
-
- execCommand( "/bin/gzip", "$logFile" );
-}
-
-main;
-
-# vi:syntax=perl
[12/36] incubator-trafficcontrol git commit: Fixed formatting
Posted by da...@apache.org.
Fixed formatting
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/bac2db29
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/bac2db29
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/bac2db29
Branch: refs/heads/master
Commit: bac2db29122674ac9bff366710704b37914be848
Parents: 7046baa
Author: peryder <pe...@cisco.com>
Authored: Tue Nov 15 13:58:17 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall-new | 60 ++++++++++++----------------
1 file changed, 25 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/bac2db29/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
index ce5fe9c..83e6d63 100755
--- a/traffic_ops/install/bin/postinstall-new
+++ b/traffic_ops/install/bin/postinstall-new
@@ -1,10 +1,8 @@
#!/usr/bin/perl
-use lib
- qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
-$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
-$ENV{PERL5LIB} =
-"/opt/traffic_ops/install/lib:/opt/traffic_ops/install/lib/perl5:/opt/traffic_ops/app/local/lib/perl5:/opt/traffic_ops/app/lib";
+use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
+$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
+$ENV{PERL5LIB} = "/opt/traffic_ops/install/lib:/opt/traffic_ops/install/lib/perl5:/opt/traffic_ops/app/local/lib/perl5:/opt/traffic_ops/app/lib";
use strict;
use warnings;
@@ -47,7 +45,7 @@ sub getField {
my $config_answer = shift;
my $fileName = shift;
-# if there is no config file and not in automatic mode prompt for all questions with default answers
+ # if there is no config file and not in automatic mode prompt for all questions with default answers
if ( $::inputFile eq "" && !$::automatic ) {
return promptUser( $question, $config_answer );
}
@@ -97,10 +95,11 @@ sub getConfig {
}
foreach my $var ( @{ $userInput->{$fileName} } ) {
- my $question =
- ( ( keys $var )[0] eq "config_var"
+ my $question = (
+ ( keys $var )[0] eq "config_var"
? ( keys $var )[1]
- : ( keys $var )[0] );
+ : ( keys $var )[0]
+ );
my $answer = $config{ $var->{"config_var"} } =
getField( $question, $var->{$question}, $fileName );
@@ -141,8 +140,7 @@ sub generateDbConf {
print $fh "name: dbconf.yml\n\n";
print $fh "production:\n";
print $fh " driver: ", getDbDriver() . "\n";
- print $fh
-" open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{root_user}/$dbconf{root_passwd}\n";
+ print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{root_user}/$dbconf{root_passwd}\n";
close $fh;
return \%todbconf;
@@ -241,24 +239,21 @@ sub generateProfilesDir {
sub sanityCheckDefaults {
foreach my $file ( ( keys $::defaultInputs ) ) {
foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
- my $question =
- ( ( keys $defaultValue )[0] eq "config_var"
+ my $question = (
+ ( keys $defaultValue )[0] eq "config_var"
? ( keys $defaultValue )[1]
- : ( keys $defaultValue )[0] );
+ : ( keys $defaultValue )[0]
+ );
if ( !defined $defaultValue->{$question}
|| $defaultValue->{$question} eq "" )
{
- errorOut(
-"Error: question \'$question\' in file \'$file\' has no default answer\n"
- );
+ errorOut( "Error: question \'$question\' in file \'$file\' has no default answer\n" );
}
if ( !defined $defaultValue->{"config_var"}
|| $defaultValue->{"config_var"} eq "" )
{
- errorOut(
-"Error: question \'$question\' in file \'$file\' has no config_var"
- );
+ errorOut( "Error: question \'$question\' in file \'$file\' has no config_var" );
}
}
}
@@ -278,8 +273,7 @@ sub sanityCheckConfig {
foreach my $file ( ( keys $::defaultInputs ) ) {
if ( !defined $userInput->{$file} ) {
- print
- "Warning: File \'$file\' found in defaults but not config file\n";
+ print "Warning: File \'$file\' found in defaults but not config file\n";
next;
}
@@ -287,27 +281,24 @@ sub sanityCheckConfig {
my $found = 0;
foreach my $configValue ( @{ $userInput->{$file} } ) {
- if ( $defaultValue->{"config_var"} eq
- $configValue->{"config_var"} )
- {
+ if ( $defaultValue->{"config_var"} eq $configValue->{"config_var"} ) {
$found = 1;
}
}
- # if the question is not found in the config file add it from defaults
+ # if the question is not found in the config file add it from defaults
if ( !$found ) {
- print "Warning: Value "
- . Dumper($defaultValue)
- . "found in defaults but not in \'$file\'\n";
+ print "Warning: Value " . Dumper($defaultValue) . "found in defaults but not in \'$file\'\n";
- my $question =
- ( ( keys $defaultValue )[0] eq "config_var"
+ my $question = (
+ ( keys $defaultValue )[0] eq "config_var"
? ( keys $defaultValue )[1]
- : ( keys $defaultValue )[0] );
+ : ( keys $defaultValue )[0]
+ );
my %temp;
- # if not in automatic mode add the question without default answer
+ # if not in automatic mode add the question without default answer
if ( !$::automatic ) {
%temp = (
"config_var" => $defaultValue->{"config_var"},
@@ -497,8 +488,7 @@ sub main {
# The generator functions handle checking input/default/automatic mode
# todbconf will be used later when setting up the database
- my $todbconf = generateDbConf( $userInput, 'testdb.conf', 'testtodb.conf',
- 'testdbconf.yml' );
+ my $todbconf = generateDbConf( $userInput, 'testdb.conf', 'testtodb.conf', 'testdbconf.yml' );
generateCdnConf( $userInput, 'testcdn.conf' );
generateLdapConf( $userInput, 'testldap.conf' );
generatePostInstallConf( $userInput, 'testpost_install.json' );
[19/36] incubator-trafficcontrol git commit: Minor changes to
formatting and reverted changes made to build_trafficops_perl_library
Posted by da...@apache.org.
Minor changes to formatting and reverted changes made to build_trafficops_perl_library
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/5bcd2be5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/5bcd2be5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/5bcd2be5
Branch: refs/heads/master
Commit: 5bcd2be51234d2fc0a423f659f353e8ebd57ec6b
Parents: fcd93ba
Author: peryder <pe...@cisco.com>
Authored: Wed Dec 7 10:06:20 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
.../install/bin/build_trafficops_perl_library | 127 +++--
traffic_ops/install/bin/input.json | 8 +-
traffic_ops/install/bin/postinstall-new | 491 -------------------
.../install/bin/postinstall-new-integrated | 2 +-
traffic_ops/install/lib/InstallUtils.pm | 8 +-
5 files changed, 97 insertions(+), 539 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5bcd2be5/traffic_ops/install/bin/build_trafficops_perl_library
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/build_trafficops_perl_library b/traffic_ops/install/bin/build_trafficops_perl_library
index aa3809d..0bca5e9 100755
--- a/traffic_ops/install/bin/build_trafficops_perl_library
+++ b/traffic_ops/install/bin/build_trafficops_perl_library
@@ -1,11 +1,13 @@
#!/usr/bin/perl
#
+# Copyright 2015 Comcast Cable Communications Management, LLC
+#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -13,22 +15,16 @@
# limitations under the License.
#
-use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
-$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
-$ENV{PERL5LIB} = "/opt/traffic_ops/install/lib:/opt/traffic_ops/install/lib/perl5:/opt/traffic_ops/app/local/lib/perl5:/opt/traffic_ops/app/lib";
-
use strict;
use warnings;
use Getopt::Std;
-use InstallUtils;
our ($opt_i);
-my @dependencies = (
- "expat-devel", "mod_ssl", "mkisofs", "libpcap", "libpcap-devel", "libcurl",
- "libcurl-devel", "mysql-server", "mysql-devel", "openssl", "cpan", "gcc",
- "make", "pkgconfig", "automake", "autoconf", "libtool", "gettext"
-);
+my @dependencies = ("expat-devel","mod_ssl","mkisofs","libpcap","libpcap-devel",
+ "libcurl","libcurl-devel","mysql-server","mysql-devel",
+ "openssl","openssl-devel","cpan","gcc","make","pkgconfig","automake","autoconf",
+ "libtool","gettext","libidn-devel");
my $msg = << 'EOF';
This script will build and package the required Traffic Ops perl modules.
@@ -37,6 +33,57 @@ compiler will be installed on this machine.
EOF
+sub execCommand {
+ my ($command, @args) = @_;
+ my $pid = fork ();
+ my $result = 0;
+
+ if ($pid == 0) {
+ exec ($command, @args);
+ exit 0;
+ }
+ else {
+ wait;
+ $result = $?;
+ if ($result != 0) {
+ print "ERROR executing: $command, args: " . join (' ', @args) . "\n";
+ }
+ }
+ return $result;
+}
+
+sub promptUser {
+ my ($promptString, $defaultValue, $noEcho) = @_;
+
+ if ($defaultValue) {
+ print $promptString, " [", $defaultValue, "]: ";
+ }
+ else {
+ print $promptString, ": ";
+ }
+
+ if (defined $noEcho && $noEcho) {
+ my $response = read_password('');
+ if ((!defined $response || $response eq '') && (defined $defaultValue && $defaultValue ne '')) {
+ $response = $defaultValue;
+ }
+ return $response
+ }
+ else {
+ $| = 1;
+ $_ = <STDIN>;
+ chomp;
+
+ if ("$defaultValue") {
+ return $_ ? $_ : $defaultValue;
+ }
+ else {
+ return $_;
+ }
+ return $_;
+ }
+}
+
sub trim {
my $str = shift;
@@ -52,67 +99,69 @@ my $result;
## MAIN ##
#################################
-$ENV{PERL_MM_USE_DEFAULT} = 1;
-$ENV{PERL_MM_NONINTERACTIVE} = 1;
-$ENV{AUTOMATED_TESTING} = 1;
+$ENV{PERL_MM_USE_DEFAULT}=1;
+$ENV{PERL_MM_NONINTERACTIVE}=1;
+$ENV{AUTOMATED_TESTING}=1;
-getopts('i');
+getopts ('i');
-InstallUtils::execCommand( "/usr/bin/tput", "clear" );
+execCommand ("/usr/bin/tput","clear");
-if ( $ENV{USER} ne "root" ) {
+if ($ENV{USER} ne "root") {
print "WARNING: You must run this script as the root user.\n";
exit 0;
}
print $msg;
-chdir("/opt/traffic_ops/app");
+promptUser ("Hit ENTER to continue","");
+
+chdir ("/opt/traffic_ops/app");
-if ( defined $opt_i && $opt_i == 1 ) {
- if ( !-x "/usr/bin/yum" ) {
+if (defined $opt_i && $opt_i == 1) {
+ if (! -x "/usr/bin/yum") {
print "WARNING: You must install 'yum'.\n";
exit 0;
}
print "\nInstalling dependencies.\n";
- $result = InstallUtils::execCommand( "/usr/bin/yum", "install", @dependencies );
- if ( $result != 0 ) {
+ $result = execCommand ("/usr/bin/yum", "install", @dependencies);
+ if ($result != 0) {
print "WARNING: dependency installation failed, look through the output and correct the problem.\n";
exit 0;
}
print "\nBuilding perl modules\n";
- $result = InstallUtils::execCommand( "/usr/bin/cpan", "-if", "YAML" );
- if ( $result != 0 ) {
+ $result = execCommand ("/opt/traffic_ops/install/bin/cpan.sh", "/opt/traffic_ops/install/bin/yaml.txt");
+ if ($result != 0) {
print "WARNING: Failed to install YAML, look through the output and correct the problem.\n";
exit 0;
}
- $result = InstallUtils::execCommand( "/usr/bin/cpan", "-if", "MIYAGAWA/Carton-v1.0.15.tar.gz" );
- if ( $result != 0 ) {
+ $result = execCommand ("/opt/traffic_ops/install/bin/cpan.sh", "/opt/traffic_ops/install/bin/carton.txt");
+ if ($result != 0) {
print "WARNING: Failed to install Carton, look through the output and correct the problem.\n";
exit 0;
}
}
-$result = InstallUtils::execCommand( "/usr/local/bin/carton", "install" );
-if ( $result != 0 ) {
+$result = execCommand ("/usr/local/bin/carton","install","--deployment","--cached");
+if ($result != 0) {
print "WARNING: Failure to build required perl modules, check the output and correct the problem.\n";
exit 0;
}
-if ( !-s "/opt/traffic_ops/lib/perl5" ) {
- print "Linking perl libraries...\n";
- if ( !-d "/opt/traffic_ops/lib" ) {
- mkdir("/opt/traffic_ops/lib");
- }
- symlink( "/opt/traffic_ops/app/local/lib/perl5", "/opt/traffic_ops/lib/perl5" );
- InstallUtils::execCommand( "/bin/chown", "-R", "trafops:trafops", "/opt/traffic_ops/lib" );
+if (! -s "/opt/traffic_ops/lib/perl5") {
+ print "Linking perl libraries...\n";
+ if (! -d "/opt/traffic_ops/lib") {
+ mkdir ("/opt/traffic_ops/lib");
+ }
+ symlink ("/opt/traffic_ops/app/local/lib/perl5","/opt/traffic_ops/lib/perl5");
+ execCommand ("/bin/chown","-R","trafops:trafops","/opt/traffic_ops/lib");
}
print "Installing perl scripts\n";
-chdir("/opt/traffic_ops/app/local/bin");
-my $rc = InstallUtils::execCommand( "/bin/cp", "-R", ".", "/opt/traffic_ops/app/bin" );
-if ( $rc != 0 ) {
- print "WARNING: Failed to copy perl scripts to /opt/traffic_ops/app/bin.\n";
+chdir ("/opt/traffic_ops/app/local/bin");
+my $rc = execCommand ("/bin/cp","-R",".","/opt/traffic_ops/app/bin");
+if ($rc != 0) {
+ print "WARNING: Failed to copy perl scripts to /opt/traffic_ops/app/bin.\n";
}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5bcd2be5/traffic_ops/install/bin/input.json
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/input.json b/traffic_ops/install/bin/input.json
index f5ca7b6..40430e9 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/5bcd2be5/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
deleted file mode 100755
index 2d22fcf..0000000
--- a/traffic_ops/install/bin/postinstall-new
+++ /dev/null
@@ -1,491 +0,0 @@
-#!/usr/bin/perl
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
-$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
-$ENV{PERL5LIB} = "/opt/traffic_ops/install/lib:/opt/traffic_ops/install/lib/perl5:/opt/traffic_ops/app/local/lib/perl5:/opt/traffic_ops/app/lib";
-
-use strict;
-use warnings;
-
-use Safe;
-use JSON;
-use POSIX;
-use File::Basename qw{dirname};
-use File::Path qw{make_path};
-use InstallUtils qw{ :all };
-use Digest::SHA1 qw(sha1_hex);
-use Data::Dumper qw(Dumper);
-use Scalar::Util qw(looks_like_number);
-
-use Getopt::Long;
-
-# paths of the output configuration files
-our $databaseConfFile = "testdb.conf";
-our $dbConfFile = "testdbconf.yml";
-our $cdnConfFile = "testcdn.conf";
-our $ldapConfFile = "testldap.conf";
-our $usersConfFile = "testusers.json";
-our $profilesConfFile = "testprofiles.json";
-
-# log file for the installer
-our $logFile = "/var/log/traffic_ops/postinstall.log";
-
-# configuration file output with answers which can be used as input to postinstall
-our $outputConfigFile = "/var/log/traffic_ops/configuration_file.json";
-
-sub errorOut {
- logger( @_, "error" );
- die;
-}
-
-# outputs logging messages to terminal and log file
-# TODO: move to InstallUtils
-sub logger {
- my $output = shift;
- my $type = shift;
-
- my $message = $output . "\n";
-
- # if in debug mode or message is more critical than info print to console
- if ( $::debug || ( defined $type && $type ne "" && $type ne "info" ) ) {
- print($message);
- }
-
- # output to log file
- open my $fh, '>>', $::logFile or errorOut("Couldn't open log file");
- print $fh localtime . ": " . uc($type) . ' ' . $message;
- close $fh;
-}
-
-sub getDbDriver {
- return "mymysql";
-}
-
-sub getInstallPath {
- my $relPath = shift;
- return join( '/', "/tmp/traffic_ops", $relPath );
-}
-
-# given a var to the hash of config_var and question, will return the question
-sub getConfigQuestion {
- my $var = shift;
- return ( keys $var )[0] eq "config_var" ? ( keys $var )[1] : ( keys $var )[0];
-}
-
-# 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
-# fileName: The name of the output config file given by the input config file
-#
-# Determines an answer to the questions asked. If an input question and answer pair is given, will return the
-# answer. If a question is given but no answer, it will prompt the user if interactive mode is enabled, but if
-# interactive mode is not enabled it will return the default answer to the question. If there is no default answer
-# to the question and interactive mode is not enabled it will return an error and quit.
-
-sub getField {
- my $question = shift;
- my $config_answer = shift;
- my $fileName = shift;
-
- # if there is no config file and not in automatic mode prompt for all questions with default answers
- if ( !$::inputFile && !$::automatic ) {
- return promptUser( $question, $config_answer );
- }
-
- return $config_answer;
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-# fileName: The name of the output config file given by the input config file
-#
-# Loops through an input config file and determines answers to each question using getField
-# and returns the hash of answers
-
-sub getConfig {
- my $userInput = shift;
- my $fileName = shift;
-
- my %config;
-
- if ( !defined $userInput->{$fileName} ) {
- logger( "No $fileName found in config", "error" );
- }
-
- logger( "===========$fileName===========", "info" );
-
- my $counter = 0;
- foreach my $var ( @{ $userInput->{$fileName} } ) {
-
- my $question = getConfigQuestion($var);
-
- my $answer = $config{ $var->{"config_var"} } = getField( $question, $var->{$question}, $fileName );
-
- $config{ $var->{"config_var"} } = $answer;
- logger( "$question: $answer", "info" );
-
- $counter++;
- }
- return %config;
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-# dbFileName: The filename of the output config file for the database
-# toDBFileName: The filename of the output config file for the Traffic Ops database
-# dbAccessFileName: The filename of DBAccess
-#
-# Generates a config file for the database based on the questions and answers in the input config file
-
-sub generateDbConf {
- my $userInput = shift;
- my $dbFileName = shift;
- my $toDBFileName = shift;
-
- my %dbconf = getConfig( $userInput, $dbFileName );
-
- make_path( dirname($dbFileName), { mode => 0755 } );
- writeJson( $dbFileName, \%dbconf );
- logger( "Database configuration has been saved", "info" );
-
- # broken out into separate file/config area
- 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!");
- print $fh "version: 1.0\n";
- print $fh "name: dbconf.yml\n\n";
- print $fh "production:\n";
- print $fh " driver: ", getDbDriver() . "\n";
- print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{user}/$dbconf{password}\n";
- close $fh;
-
- return \%todbconf;
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-# fileName: The filename of the output config file
-#
-# Generates a config file for the CDN
-
-sub generateCdnConf {
- my $userInput = shift;
- my $fileName = shift;
-
- my %cdnConfiguration = getConfig( $userInput, $fileName );
-
- # First, read existing one -- already loaded with a bunch of stuff
- my $cdnConf;
- if ( -e $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 ) {
-
- # Shorten the array to requested length
- $#secrets = $cdnConfiguration{keepSecrets} - 1;
- }
- }
- writePerl( $fileName, $cdnConf );
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-# fileName: The filename of the output config file
-#
-# Generates an LDAP config file
-
-sub generateLdapConf {
- my $userInput = shift;
- my $fileName = shift;
-
- my $useLdap = $userInput->{$fileName}[0]->{"Do you want to set up LDAP?"};
-
- if ( $useLdap eq "no" || $useLdap eq "n" ) {
- logger( "Not setting up ldap", "info" );
-
- return;
- }
-
- my %ldapConf = getConfig( $userInput, $fileName );
-
- make_path( dirname($fileName), { mode => 0755 } );
- writeJson( $fileName, \%ldapConf );
-}
-
-sub generateUsersConf {
- my $userInput = shift;
- my $fileName = shift;
-
- my %user = ();
- my %config = getConfig( $userInput, $fileName );
-
- $user{username} = $config{tmAdminUser};
- $user{password} = sha1_hex( $config{tmAdminPw} );
-
- writeJson( $fileName, \%user );
-}
-
-sub generateProfilesDir {
- my $userInput = shift;
- my $fileName = shift;
-
- my $userIn = $userInput->{$fileName};
-}
-
-# check default values for missing config_var parameter
-sub sanityCheckDefaults {
- foreach my $file ( ( keys $::defaultInputs ) ) {
- foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
- my $question = getConfigQuestion($defaultValue);
-
- if ( !defined $defaultValue->{"config_var"} || $defaultValue->{"config_var"} eq "" ) {
- errorOut("Question \'$question\' in file \'$file\' has no config_var");
- }
- }
- }
-}
-
-# userInput: The entire input config file which is either user input or the defaults
-#
-# Checks the input config file against the default inputs. If there is a question located in the default inputs which
-# is not located in the input config file it will output a warning message. If in auto mode the default answer will be
-# used. If in interactive mode the user will be prompted with the default question missing from the config file
-#
-# This does not check the other way meaning questions which are present in defaults but not present in the input config
-# file will not be checked
-
-sub sanityCheckConfig {
- my $userInput = shift;
- my $diffs = 0;
-
- foreach my $file ( ( keys $::defaultInputs ) ) {
- if ( !defined $userInput->{$file} ) {
- logger( "File \'$file\' found in defaults but not config file", "warn" );
- $userInput->{$file} = [];
- }
- foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
-
- my $found = 0;
- foreach my $configValue ( @{ $userInput->{$file} } ) {
- if ( $defaultValue->{"config_var"} eq $configValue->{"config_var"} ) {
- $found = 1;
- }
- }
-
- # 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);
-
- my %temp;
-
- # 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}
- );
- }
-
- # in interactive mode prompt the user for answer to missing question
- else {
- logger( "Prompting user for answer", "info" );
-
- my $answer = promptUser( $question, $defaultValue->{$question} );
-
- %temp = ( "config_var" => $defaultValue->{"config_var"}, $question => $answer );
- }
- push $userInput->{$file}, \%temp;
-
- $diffs++;
- }
- }
- }
-
- 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 );
-}
-
-# A function which returns the default inputs data structure. These questions and answers will be used if there is no
-# user input config file or if there are questions in the input config file which do not have answers
-
-sub getDefaults {
- return {
- $::databaseConfFile => [
- {
- "Database type" => "mysql",
- "config_var" => "type",
- },
- {
- "Database name" => "traffic_ops",
- "config_var" => "dbname",
- },
- {
- "Database server hostname IP or FQDN" => "localhost",
- "config_var" => "hostname",
- },
- {
- "Database port number" => "3306",
- "config_var" => "port"
- },
- {
- "Traffic Ops database user" => "traffic_ops",
- "config_var" => "user"
- },
- {
- "Password for Traffic Ops database user" => "default",
- "config_var" => "password"
- }
- ],
- $::dbConfFile => [
- {
- "Database server root (admin) user" => "root",
- "config_var" => "dbAdminUser"
- },
- {
- "Password for database server admin" => "default",
- "config_var" => "dbAdminPw"
- }
- ],
- $::cdnConfFile => [
- {
- "Generate a new secret?" => "yes",
- "config_var" => "genSecret"
- },
- {
- "Number of secrets to keep?" => "10",
- "config_var" => "keepSecrets"
- }
- ],
- $::ldapConfFile => [
- {
- "Do you want to set up LDAP?" => "no",
- "config_var" => "setupLdap"
- },
- {
- "LDAP server hostname" => "",
- "config_var" => "hostname"
- },
- {
- "LDAP Admin DN" => "",
- "config_var" => "admin_dn"
- },
- {
- "LDAP Admin Password" => "",
- "config_var" => "password"
- },
- {
- "LDAP Search Base" => "",
- "config_var" => "search_base"
- }
- ],
- $::usersConfFile => [
- {
- "Administration username for Traffic Ops" => "admin",
- "config_var" => "tmAdminUser"
- },
- {
- "Password for the admin user" => "default",
- "config_var" => "tmAdminPw"
- }
- ],
- $::profilesConfFile => []
- };
-}
-
-# -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
-
-sub main {
- our $inputFile = "";
- our $automatic = 0;
- our $debug = 0;
- my $help = 0;
-
- my $usageString = "Usage: postinstall [-a] [-d] -cfile=[config_file]\n";
-
- GetOptions(
- "cfile=s" => \$inputFile,
- "automatic" => \$automatic,
- "debug" => \$debug,
- "help" => \$help
- ) or die($usageString);
-
- # stores the default questions and answers
- our $defaultInputs = getDefaults();
-
- if ($help) {
- print $usageString;
- exit(0);
- }
-
- if ($::debug) {
- print "Debug is on\n";
- }
-
- if ( $::debug && $::automatic ) {
- print "Running in automatic mode\n";
- }
-
- logger( "Starting postinstall", "info" );
-
- # used to store the questions and answers provided by the user
- my $userInput;
-
- if ( $::inputFile eq "" ) {
- print "No input file given - using defaults\n" if ($::debug);
- $userInput = $::defaultInputs;
- }
- else {
- print "Using input file $::inputFile\n" if ($::debug);
-
- # check if the input file exists
- errorOut("File \'$::inputFile\' not found") if ( !-e $::inputFile );
-
- # read and store the input file
- $userInput = readJson($::inputFile);
- }
-
- # sanity check the defaults if running them automatically
- sanityCheckDefaults();
-
- # check the input config file against the defaults to check for missing questions
- sanityCheckConfig($userInput) if ( $inputFile ne "" );
-
- writeJson( $outputConfigFile, $userInput );
-
- # The generator functions handle checking input/default/automatic mode
-
- # todbconf will be used later when setting up the database
- generateDbConf( $userInput, $::databaseConfFile, $::dbConfFile );
- generateCdnConf( $userInput, $::cdnConfFile );
- generateLdapConf( $userInput, $::ldapConfFile );
- generateUsersConf( $userInput, $::usersConfFile );
- generateProfilesDir( $userInput, $::profilesConfFile );
-}
-
-main;
-
-logger( "Postinstall complete\n", "info" );
-
-# vi:syntax=perl
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5bcd2be5/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 dbf0791..cc6ec82 100755
--- a/traffic_ops/install/bin/postinstall-new-integrated
+++ b/traffic_ops/install/bin/postinstall-new-integrated
@@ -320,8 +320,8 @@ sub sanityCheckConfig {
# in automatic mode add the missing question with default answer
if ($::automatic) {
- logger( "Adding question '$question' with default answer " . ( $defaultValue->{"hidden"} ? "" : "'$defaultValue->{$question}'" ), "info" );
$answer = $defaultValue->{$question};
+ logger( "Adding question '$question' with default answer " . ( $hidden ? "" : "'$answer'" ), "info" );
}
# in interactive mode prompt the user for answer to missing question
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5bcd2be5/traffic_ops/install/lib/InstallUtils.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/InstallUtils.pm b/traffic_ops/install/lib/InstallUtils.pm
index 452a4d9..c0ad9b5 100644
--- a/traffic_ops/install/lib/InstallUtils.pm
+++ b/traffic_ops/install/lib/InstallUtils.pm
@@ -56,7 +56,7 @@ sub execCommand {
if ( index($var, "pi_custom_log=") != -1 ) {
$customLog = (split(/=/, $var))[1];
splice(@args, index($var, "pi_custom_log="), 1);
- logger("Using custom log \'$customLog\'", "info");
+ logger("Using custom log '$customLog'", "info");
}
}
@@ -93,7 +93,7 @@ sub rotateLog {
my $logFileName = shift;
if ( !-f $logFileName ) {
- logger("Log file \'$logFileName\' does not exist - not rotating log", "error");
+ logger("Log file '$logFileName' does not exist - not rotating log", "error");
return;
}
@@ -124,12 +124,12 @@ sub logger {
my $fh;
my $result = 0;
if ( defined $customLogFile && $customLogFile ne "" ) {
- open $fh, '>>', $customLogFile or die("Couldn't open log file \'$::customLogFile\'");
+ open $fh, '>>', $customLogFile or die("Couldn't open log file '$::customLogFile'");
$result = 1;
}
else {
if ($::logFile) {
- open $fh, '>>', $::logFile or die("Couldn't open log file \'$::logFile\'");
+ open $fh, '>>', $::logFile or die("Couldn't open log file '$::logFile'");
$result = 1;
}
}
[23/36] incubator-trafficcontrol git commit: Added apache license to
ProfileCleanup
Posted by da...@apache.org.
Added apache license to ProfileCleanup
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/831d58d2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/831d58d2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/831d58d2
Branch: refs/heads/master
Commit: 831d58d2350a32d0e0b3714332e1388c6bad21b8
Parents: d665814
Author: peryder <pe...@cisco.com>
Authored: Wed Dec 7 10:21:01 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/lib/ProfileCleanup.pm | 15 +++++++++++++++
1 file changed, 15 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/831d58d2/traffic_ops/install/lib/ProfileCleanup.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/ProfileCleanup.pm b/traffic_ops/install/lib/ProfileCleanup.pm
index 3fe6220..1e6edf9 100644
--- a/traffic_ops/install/lib/ProfileCleanup.pm
+++ b/traffic_ops/install/lib/ProfileCleanup.pm
@@ -1,3 +1,18 @@
+#!/usr/bin/perl
+
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
package ProfileCleanup;
[02/36] incubator-trafficcontrol git commit: Changed database to pg
and made downloading maxmind database optional defaulting to yes
Posted by da...@apache.org.
Changed database to pg and made downloading maxmind database optional defaulting to yes
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/2f73509c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/2f73509c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/2f73509c
Branch: refs/heads/master
Commit: 2f73509c900146dd2afee3ff299b1e238a2f4c3b
Parents: 2ab71fd
Author: peter.w.ryder <pe...@gmail.com>
Authored: Fri Jan 20 09:34:10 2017 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/input.json | 11 ++++++--
traffic_ops/install/bin/postinstall | 47 ++++++++++++++++----------------
2 files changed, 33 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2f73509c/traffic_ops/install/bin/input.json
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/input.json b/traffic_ops/install/bin/input.json
index 31b126f..136dfa7 100644
--- a/traffic_ops/install/bin/input.json
+++ b/traffic_ops/install/bin/input.json
@@ -1,7 +1,7 @@
{
"/opt/traffic_ops/app/conf/production/database.conf":[
{
- "Database type":"mysql",
+ "Database type":"pg",
"config_var":"type"
},
{
@@ -24,6 +24,10 @@
"Traffic Ops database password":"default",
"config_var":"password",
"hidden":"1"
+ },
+ {
+ "Download Maxmind Database?":"yes",
+ "config_var":"maxmind"
}
],
"/opt/traffic_ops/app/db/dbconf.yml":[
@@ -82,7 +86,10 @@
}
],
"/opt/traffic_ops/install/data/profiles/":[
-
+ {
+ "Add custom profiles?":"no",
+ "config_var":"custom_profiles"
+ }
],
"/opt/traffic_ops/install/data/json/openssl_configuration.json":[
{
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2f73509c/traffic_ops/install/bin/postinstall
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall b/traffic_ops/install/bin/postinstall
index 0f187b8..f1aa23f 100755
--- a/traffic_ops/install/bin/postinstall
+++ b/traffic_ops/install/bin/postinstall
@@ -87,7 +87,7 @@ my $automatic = 0;
my $defaultInputs;
sub getDbDriver {
- return "mymysql";
+ return "pg";
}
sub getInstallPath {
@@ -407,6 +407,10 @@ sub getDefaults {
"Password for Traffic Ops database user" => "",
"config_var" => "password",
"hidden" => "true"
+ },
+ {
+ "Download Maxmind Database?" => "yes",
+ "config_var" => "maxmind"
}
],
$dbConfFile => [
@@ -464,7 +468,12 @@ sub getDefaults {
"hidden" => "true"
}
],
- $profilesConfFile => [],
+ $profilesConfFile => [
+ {
+ "Add custom profiles?" =>"no",
+ "config_var" => "custom_profiles"
+ }
+ ],
$opensslConfFile => [
{
"Do you want to generate a certificate?" => "yes",
@@ -559,19 +568,11 @@ sub setupDatabase {
my $todbconf = shift;
my $opensslconf = shift;
my $genCert = shift;
-
- #
- # Call mysql initialization script.
- #
- InstallUtils::logger( "Creating database with user: $todbconf->{dbAdminUser}", "info" );
- my $result = InstallUtils::execCommand( "/opt/traffic_ops/install/bin/create_db", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
- if ( $result != 0 ) {
- errorOut("Failed to create the database");
- }
+ my $setupMaxmind = shift;
InstallUtils::logger( "Setting up database", "info" );
chdir("/opt/traffic_ops/app");
- $result = InstallUtils::execCommand( "/usr/bin/perl", "db/admin.pl", "--env=production", "setup" );
+ my $result = InstallUtils::execCommand( "/usr/bin/perl", "db/admin.pl", "--env=production", "setup" );
if ( $result != 0 ) {
errorOut("Database initialization failed");
@@ -580,16 +581,16 @@ sub setupDatabase {
InstallUtils::logger( "Database initialization succeeded", "info" );
}
- $result = InstallUtils::execCommand( "/opt/traffic_ops/install/bin/dataload", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
- if ( $result != 0 ) {
- InstallUtils::logger( "Failed to load seed data", "error" );
+ if ($setupMaxmind =~ /^y(?:es)?/) {
+ InstallUtils::logger( "Downloading Maxmind data", "info" );
+ chdir("/opt/traffic_ops/app/public/routing");
+ $result = InstallUtils::execCommand("/usr/bin/wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz");
+ if ( $result != 0 ) {
+ InstallUtils::logger( "Failed to download MaxMind data", "error" );
+ }
}
-
- InstallUtils::logger( "Downloading MaxMind data", "info" );
- chdir("/opt/traffic_ops/app/public/routing");
- $result = InstallUtils::execCommand("/usr/bin/wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz");
- if ( $result != 0 ) {
- InstallUtils::logger( "Failed to download MaxMind data", "error" );
+ else {
+ InstallUtils::logger("Not downloading Maxmind data");
}
InstallUtils::logger( "Copying coverage zone file to public dir", "info" );
@@ -758,10 +759,10 @@ sub main {
# if reconfigure is set then setup the database
if ($reconfigure) {
if ($automatic) {
- setupDatabase( $todbconf, $opensslConfFile, $opensslconf->{genCert} );
+ setupDatabase( $todbconf, $opensslConfFile, $opensslconf->{"genCert"}, $todbconf->{"maxmind"} );
}
else {
- setupDatabase( $todbconf, 0, $opensslconf->{genCert} );
+ setupDatabase( $todbconf, 0, $opensslconf->{"genCert"} );
}
}
[15/36] incubator-trafficcontrol git commit: Many minor tweaks -
better logging, gzip logs, and comments
Posted by da...@apache.org.
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"} );
[18/36] incubator-trafficcontrol git commit: Added apache license to
added files
Posted by da...@apache.org.
Added apache license to added files
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/fcd93ba7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/fcd93ba7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/fcd93ba7
Branch: refs/heads/master
Commit: fcd93ba76c090c52bf458497abfe95a209118005
Parents: e6a3122
Author: peryder <pe...@cisco.com>
Authored: Mon Dec 5 18:52:37 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall-new | 13 +++++++++++++
traffic_ops/install/lib/BuildPerlDeps.pm | 5 +++--
traffic_ops/install/lib/InstallUtils.pm | 11 +++++++++++
traffic_ops/install/lib/ProfileCleanup.pm | 14 ++++++++++++++
4 files changed, 41 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/fcd93ba7/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
index cb4cc56..2d22fcf 100755
--- a/traffic_ops/install/bin/postinstall-new
+++ b/traffic_ops/install/bin/postinstall-new
@@ -1,4 +1,17 @@
#!/usr/bin/perl
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/fcd93ba7/traffic_ops/install/lib/BuildPerlDeps.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/BuildPerlDeps.pm b/traffic_ops/install/lib/BuildPerlDeps.pm
index e127d07..7c20845 100644
--- a/traffic_ops/install/lib/BuildPerlDeps.pm
+++ b/traffic_ops/install/lib/BuildPerlDeps.pm
@@ -1,4 +1,5 @@
#!/usr/bin/perl
+
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -13,10 +14,10 @@
# limitations under the License.
#
-use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/lib/perl5 /opt/traffic_ops/app/lib);
-
package BuildPerlDeps;
+use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/lib/perl5 /opt/traffic_ops/app/lib);
+
use InstallUtils qw{ :all };
use base qw{ Exporter };
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/fcd93ba7/traffic_ops/install/lib/InstallUtils.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/InstallUtils.pm b/traffic_ops/install/lib/InstallUtils.pm
index a30042f..452a4d9 100644
--- a/traffic_ops/install/lib/InstallUtils.pm
+++ b/traffic_ops/install/lib/InstallUtils.pm
@@ -1,6 +1,17 @@
+#!/usr/bin/perl
+
#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
#
package InstallUtils;
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/fcd93ba7/traffic_ops/install/lib/ProfileCleanup.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/ProfileCleanup.pm b/traffic_ops/install/lib/ProfileCleanup.pm
index 0baecb7..eab10a1 100644
--- a/traffic_ops/install/lib/ProfileCleanup.pm
+++ b/traffic_ops/install/lib/ProfileCleanup.pm
@@ -1,3 +1,17 @@
+#!/usr/bin/perl
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
package ProfileCleanup;
[36/36] incubator-trafficcontrol git commit: ran perltidy
Posted by da...@apache.org.
ran perltidy
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/2ab71fdd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/2ab71fdd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/2ab71fdd
Branch: refs/heads/master
Commit: 2ab71fdd0958f32401f860e0bab4765908b6ac09
Parents: 230aa7c
Author: peter.w.ryder <pe...@gmail.com>
Authored: Thu Jan 12 15:14:46 2017 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall | 10 +++++-----
traffic_ops/install/lib/InstallUtils.pm | 2 +-
traffic_ops/install/lib/ProfileCleanup.pm | 24 ++++++++++++------------
3 files changed, 18 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2ab71fdd/traffic_ops/install/bin/postinstall
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall b/traffic_ops/install/bin/postinstall
index 2f6f3d7..0f187b8 100755
--- a/traffic_ops/install/bin/postinstall
+++ b/traffic_ops/install/bin/postinstall
@@ -58,7 +58,7 @@ my $post_install_cfg = "/opt/traffic_ops/install/data/json/post_install.json";
my $logFile = "/var/log/traffic_ops/postinstall.log";
# debug mode
-my $debug = 0;
+my $debug = 0;
# log file for cpan output
my $cpanLogFile = "/var/log/traffic_ops/cpan.log";
@@ -721,7 +721,7 @@ sub main {
chdir("/opt/traffic_ops/install/bin");
# if reconfigure is set then rebuild the perl deps
- if ( $reconfigure ) {
+ if ($reconfigure) {
my $rc = BuildPerlDeps::build( 1, $cpanLogFile );
if ( $rc != 0 ) {
errorOut("Failed to install perl dependencies, check the console output and rerun postinstall once you've resolved the error");
@@ -756,8 +756,8 @@ sub main {
InstallUtils::writeJson( $post_install_cfg, $paramconf );
# if reconfigure is set then setup the database
- if ( $reconfigure ) {
- if ( $automatic ) {
+ if ($reconfigure) {
+ if ($automatic) {
setupDatabase( $todbconf, $opensslConfFile, $opensslconf->{genCert} );
}
else {
@@ -770,7 +770,7 @@ sub main {
InstallUtils::logger( "Waiting for Traffic Ops to start", "info" );
- if (-f $post_install_cfg) {
+ if ( -f $post_install_cfg ) {
$parameters = InstallUtils::readJson($post_install_cfg);
}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2ab71fdd/traffic_ops/install/lib/InstallUtils.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/InstallUtils.pm b/traffic_ops/install/lib/InstallUtils.pm
index 555ba84..7ba24d5 100644
--- a/traffic_ops/install/lib/InstallUtils.pm
+++ b/traffic_ops/install/lib/InstallUtils.pm
@@ -241,7 +241,7 @@ sub readJson {
sub writeJson {
my $file = shift;
open( my $fh, '>', $file ) or die("open(): $!");
- logger("Writing json to $file", "info");
+ logger( "Writing json to $file", "info" );
foreach my $data (@_) {
my $json_text = JSON->new->utf8->pretty->encode($data);
print $fh $json_text, "\n";
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2ab71fdd/traffic_ops/install/lib/ProfileCleanup.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/ProfileCleanup.pm b/traffic_ops/install/lib/ProfileCleanup.pm
index 4885a11..d9828cc 100644
--- a/traffic_ops/install/lib/ProfileCleanup.pm
+++ b/traffic_ops/install/lib/ProfileCleanup.pm
@@ -135,7 +135,7 @@ sub profile_import_single {
}
sub import_profiles {
- my $toUri = shift;
+ my $toUri = shift;
my $adminconf = shift;
my $profileDir = shift;
@@ -226,25 +226,25 @@ sub profiles_exist {
sub add_custom_profiles {
my $custom_profile_dir = shift;
- my $adminconf = shift;
- my $toUri = shift;
+ my $adminconf = shift;
+ my $toUri = shift;
- return if (! -e $custom_profile_dir );
+ return if ( !-e $custom_profile_dir );
- opendir(DH, $custom_profile_dir) || return;
+ opendir( DH, $custom_profile_dir ) || return;
my @profiles = readdir(DH);
closedir(DH);
- @profiles = grep(/^profile\..*\.traffic_ops$/, @profiles);
+ @profiles = grep( /^profile\..*\.traffic_ops$/, @profiles );
- return if (scalar @profiles == 0);
+ return if ( scalar @profiles == 0 );
- my $toUser = $adminconf->{tmAdminUser};
- my $toPass = $adminconf->{tmAdminPw};
- my $toCookie = get_traffic_ops_cookie($toUri, $toUser, $toPass);
+ my $toUser = $adminconf->{tmAdminUser};
+ my $toPass = $adminconf->{tmAdminPw};
+ my $toCookie = get_traffic_ops_cookie( $toUri, $toUser, $toPass );
foreach my $profile (@profiles) {
- print "\nimport profile ". $custom_profile_dir . $profile . "\n\n";
- profile_import_single($custom_profile_dir . $profile, $toUri, $toCookie);
+ print "\nimport profile " . $custom_profile_dir . $profile . "\n\n";
+ profile_import_single( $custom_profile_dir . $profile, $toUri, $toCookie );
}
}
[13/36] incubator-trafficcontrol git commit: Added logging and
outputs config file which can be used as input
Posted by da...@apache.org.
Added logging and outputs config file which can be used as input
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/4a2657bb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/4a2657bb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/4a2657bb
Branch: refs/heads/master
Commit: 4a2657bbba5564ce55161f8aecc87f24baedb264
Parents: bac2db2
Author: peryder <pe...@cisco.com>
Authored: Tue Nov 22 16:27:35 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall-new | 294 +++++++++++++--------------
1 file changed, 137 insertions(+), 157 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/4a2657bb/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
index 83e6d63..b97d58d 100755
--- a/traffic_ops/install/bin/postinstall-new
+++ b/traffic_ops/install/bin/postinstall-new
@@ -9,6 +9,7 @@ use warnings;
use Safe;
use JSON;
+use POSIX;
use File::Basename qw{dirname};
use File::Path qw{make_path};
use InstallUtils qw{ :all };
@@ -18,8 +19,41 @@ use Scalar::Util qw(looks_like_number);
use Getopt::Long;
+# paths of the output configuration files
+our $databaseConfFile = "testdb.conf";
+our $dbConfFile = "testdbconf.yml";
+our $cdnConfFile = "testcdn.conf";
+our $ldapConfFile = "testldap.conf";
+our $usersConfFile = "testusers.json";
+our $profilesConfFile = "testprofiles.json";
+
+# log file for the installer
+our $logFile = "/var/log/traffic_ops/postinstall.log";
+
+# configuration file output with answers which can be used as input to postinstall
+our $outputConfigFile = "/var/log/traffic_ops/configuration_file.json";
+
sub errorOut {
- die @_;
+ logger( @_, "error" );
+ die;
+}
+
+# outputs logging messages to terminal and log file
+sub logger {
+ my $output = shift;
+ my $type = shift;
+
+ my $message = $output . "\n";
+
+ # if in debug mode or message is more critical than info print to console
+ if ( $::debug || ( defined $type && $type ne "" && $type ne "info" ) ) {
+ print($message);
+ }
+
+ # output to log file
+ open my $fh, '>>', $::logFile or errorOut("Couldn't open log file");
+ print $fh localtime . ": " . uc($type) . ' ' . $message;
+ close $fh;
}
sub getDbDriver {
@@ -31,6 +65,12 @@ sub getInstallPath {
return join( '/', "/tmp/traffic_ops", $relPath );
}
+# given a var to the hash of config_var and question, will return the question
+sub getConfigQuestion {
+ my $var = shift;
+ return ( keys $var )[0] eq "config_var" ? ( keys $var )[1] : ( keys $var )[0];
+}
+
# 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
# fileName: The name of the output config file given by the input config file
@@ -46,32 +86,11 @@ sub getField {
my $fileName = shift;
# if there is no config file and not in automatic mode prompt for all questions with default answers
- if ( $::inputFile eq "" && !$::automatic ) {
+ if ( !$::inputFile && !$::automatic ) {
return promptUser( $question, $config_answer );
}
- # if answer provided in config file use it
- if ($config_answer) {
- return $config_answer;
- }
- else {
- # if no config value and not in automatic mode prompt user
- if ( !$::automatic ) {
- return promptUser($question);
- }
-
- # if no answer given in input file attempt to use default answer
- foreach my $var ( @{ $::defaultInputs->{$fileName} } ) {
- if ( defined $var->{$question} && $var->{$question} ne "" ) {
- return $var->{$question};
- }
- }
-
- #No way of getting answer
- errorOut("No config answer given for question \'$question\'\n");
- }
-
- errorOut("error: end of function");
+ return $config_answer;
}
# userInput: The entire input config file which is either user input or the defaults
@@ -87,27 +106,22 @@ sub getConfig {
my %config;
if ( !defined $userInput->{$fileName} ) {
- print "Error: No $fileName found in config\n";
+ logger( "No $fileName found in config", "error" );
}
- if ($::debug) {
- print "===========$fileName===========\n";
- }
+ logger( "===========$fileName===========", "info" );
+ my $counter = 0;
foreach my $var ( @{ $userInput->{$fileName} } ) {
- my $question = (
- ( keys $var )[0] eq "config_var"
- ? ( keys $var )[1]
- : ( keys $var )[0]
- );
- my $answer = $config{ $var->{"config_var"} } =
- getField( $question, $var->{$question}, $fileName );
+ my $question = getConfigQuestion($var);
+
+ my $answer = $config{ $var->{"config_var"} } = getField( $question, $var->{$question}, $fileName );
$config{ $var->{"config_var"} } = $answer;
- if ($::debug) {
- print "$question: $answer\n";
- }
+ logger( "$question: $answer", "info" );
+
+ $counter++;
}
return %config;
}
@@ -120,27 +134,26 @@ sub getConfig {
# Generates a config file for the database based on the questions and answers in the input config file
sub generateDbConf {
- my $userInput = shift;
- my $dbFileName = shift;
- my $toDBFileName = shift;
- my $dbAccessFileName = shift;
+ my $userInput = shift;
+ my $dbFileName = shift;
+ my $toDBFileName = shift;
my %dbconf = getConfig( $userInput, $dbFileName );
make_path( dirname($dbFileName), { mode => 0755 } );
writeJson( $dbFileName, \%dbconf );
+ logger( "Database configuration has been saved", "info" );
# broken out into separate file/config area
my %todbconf = getConfig( $userInput, $toDBFileName );
# No YAML library installed, but this is a simple file..
- open( my $fh, '>', $dbAccessFileName )
- or errorOut("Can't write to $dbAccessFileName $!");
+ 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";
print $fh " driver: ", getDbDriver() . "\n";
- print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{root_user}/$dbconf{root_passwd}\n";
+ print $fh " open: tcp:$dbconf{hostname}:$dbconf{port}*$dbconf{dbname}/$dbconf{user}/$dbconf{password}\n";
close $fh;
return \%todbconf;
@@ -155,26 +168,21 @@ sub generateCdnConf {
my $userInput = shift;
my $fileName = shift;
- # First, read existing one -- already loaded with a bunch of stuff
- my $cdnConf = Safe->new->rdo($fileName)
- or errorOut("Error loading $fileName: $@");
-
- my %cdnconf = getConfig( $userInput, $fileName );
+ my %cdnConfiguration = getConfig( $userInput, $fileName );
- if ( !looks_like_number( $cdnconf{keepSecrets} ) ) {
- errorOut("Error: Number of secrets to keep must be a number\n");
+ # First, read existing one -- already loaded with a bunch of stuff
+ my $cdnConf;
+ if ( -e $fileName ) {
+ $cdnConf = Safe->new->rdo($fileName) or errorOut("Error loading $fileName: $@");
}
-
- if ( lc $cdnconf{genSecret} =~ /^y(?:es)?/ ) {
+ if ( lc $cdnConfiguration{genSecret} =~ /^y(?:es)?/ ) {
my @secrets = @{ $cdnConf->{secrets} };
my $newSecret = randomWord();
unshift @secrets, randomWord();
- if ( $cdnconf{keepSecrets} > 0
- && $#secrets > $cdnconf{keepSecrets} - 1 )
- {
+ if ( $cdnConfiguration{keepSecrets} > 0 && $#secrets > $cdnConfiguration{keepSecrets} - 1 ) {
# Shorten the array to requested length
- $#secrets = $cdnconf{keepSecrets} - 1;
+ $#secrets = $cdnConfiguration{keepSecrets} - 1;
}
}
writePerl( $fileName, $cdnConf );
@@ -192,30 +200,17 @@ sub generateLdapConf {
my $useLdap = $userInput->{$fileName}[0]->{"Do you want to set up LDAP?"};
if ( $useLdap eq "no" || $useLdap eq "n" ) {
- if ($::debug) {
- print "Not setting up ldap\n";
- }
+ logger( "Not setting up ldap", "info" );
+
return;
}
my %ldapConf = getConfig( $userInput, $fileName );
- if ( $::debug && $ldapConf{setupLdap} eq "no" ) {
- print "Not setting up ldap\n";
- return;
- }
-
make_path( dirname($fileName), { mode => 0755 } );
writeJson( $fileName, \%ldapConf );
}
-sub generatePostInstallConf {
- my $userInput = shift;
- my $fileName = shift;
-
- my $userIn = $userInput->{$fileName};
-}
-
sub generateUsersConf {
my $userInput = shift;
my $fileName = shift;
@@ -236,24 +231,14 @@ sub generateProfilesDir {
my $userIn = $userInput->{$fileName};
}
+# check default values for missing config_var parameter
sub sanityCheckDefaults {
foreach my $file ( ( keys $::defaultInputs ) ) {
foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
- my $question = (
- ( keys $defaultValue )[0] eq "config_var"
- ? ( keys $defaultValue )[1]
- : ( keys $defaultValue )[0]
- );
- if ( !defined $defaultValue->{$question}
- || $defaultValue->{$question} eq "" )
- {
- errorOut( "Error: question \'$question\' in file \'$file\' has no default answer\n" );
- }
+ my $question = getConfigQuestion($defaultValue);
- if ( !defined $defaultValue->{"config_var"}
- || $defaultValue->{"config_var"} eq "" )
- {
- errorOut( "Error: question \'$question\' in file \'$file\' has no config_var" );
+ if ( !defined $defaultValue->{"config_var"} || $defaultValue->{"config_var"} eq "" ) {
+ errorOut("Question \'$question\' in file \'$file\' has no config_var");
}
}
}
@@ -273,7 +258,7 @@ sub sanityCheckConfig {
foreach my $file ( ( keys $::defaultInputs ) ) {
if ( !defined $userInput->{$file} ) {
- print "Warning: File \'$file\' found in defaults but not config file\n";
+ logger( "File \'$file\' found in defaults but not config file", "warn" );
next;
}
@@ -288,32 +273,30 @@ sub sanityCheckConfig {
# if the question is not found in the config file add it from defaults
if ( !$found ) {
- print "Warning: Value " . Dumper($defaultValue) . "found in defaults but not in \'$file\'\n";
+ logger( "Value " . Dumper($defaultValue) . "found in defaults but not in \'$file\'", "warn" );
- my $question = (
- ( keys $defaultValue )[0] eq "config_var"
- ? ( keys $defaultValue )[1]
- : ( keys $defaultValue )[0]
- );
+ my $question = getConfigQuestion($defaultValue);
my %temp;
- # if not in automatic mode add the question without default answer
- if ( !$::automatic ) {
- %temp = (
- "config_var" => $defaultValue->{"config_var"},
- $question => ""
- );
- }
+ # in automatic mode add the missing question with default answer
+ if ($::automatic) {
+ logger( "Adding question \'$question\' with default answer \'$defaultValue->{$question}\'", "info" );
- # if in automatic mode add question with default answer
- else {
%temp = (
"config_var" => $defaultValue->{"config_var"},
$question => $defaultValue->{$question}
);
}
+ # in interactive mode prompt the user for answer to missing question
+ else {
+ logger( "Prompting user for answer", "info" );
+
+ my $answer = promptUser( $question, $defaultValue->{$question} );
+
+ %temp = ( "config_var" => $defaultValue->{"config_var"}, $question => $answer );
+ }
push $userInput->{$file}, \%temp;
$diffs++;
@@ -321,13 +304,12 @@ sub sanityCheckConfig {
}
}
- if ( $::debug && $diffs == 0 ) {
- print "File sanity check complete - found $diffs differences\n";
- }
+ 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 );
+}
- if ( $diffs > 0 ) {
- print "File sanity check complete - found $diffs difference(s)\n";
- }
+sub writeOutputConf {
+ writeJson( $::outputConfigFile, \%::outputConf );
}
# A function which returns the default inputs data structure. These questions and answers will be used if there is no
@@ -335,43 +317,43 @@ sub sanityCheckConfig {
sub getDefaults {
return {
- "testdb.conf" => [
+ $::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,
"config_var" => "port"
},
{
- "Root database user" => "root",
- "config_var" => "root_user"
+ "Traffic Ops database user" => "traffic_ops",
+ "config_var" => "user"
},
{
- "Root database password" => "default",
- "config_var" => "root_passwd"
+ "Password for Traffic Ops database user" => "default",
+ "config_var" => "password"
}
],
- "testtodb.conf" => [
+ $::dbConfFile => [
{
- "Traffic Ops database user" => "root",
- "config_var" => "dbAdminUser"
+ "Database server root (admin) user" => "root",
+ "config_var" => "dbAdminUser"
},
{
- "Password for Traffic Ops database user" => "default",
- "config_var" => "dbAdminPw"
+ "Password for database server admin" => "default",
+ "config_var" => "dbAdminPw"
}
],
- "testcdn.conf" => [
+ $::cdnConfFile => [
{
"Generate a new secret?" => "yes",
"config_var" => "genSecret"
@@ -381,7 +363,7 @@ sub getDefaults {
"config_var" => "keepSecrets"
}
],
- "testldap.conf" => [
+ $::ldapConfFile => [
{
"Do you want to set up LDAP?" => "no",
"config_var" => "setupLdap"
@@ -403,8 +385,7 @@ sub getDefaults {
"config_var" => "search_base"
}
],
- "testpost_install.json" => [],
- "testusers.json" => [
+ $::usersConfFile => [
{
"Administration username for Traffic Ops" => "admin",
"config_var" => "tmAdminUser"
@@ -414,7 +395,7 @@ sub getDefaults {
"config_var" => "tmAdminPw"
}
],
- "testprofiles/" => []
+ $::profilesConfFile => []
};
}
@@ -431,20 +412,20 @@ sub main {
our $debug = 0;
my $help = 0;
+ my $usageString = "Usage: postinstall [-a] [-d] -cfile=[config_file]\n";
+
GetOptions(
- "cfile=s" => \$inputFile,
- "c=s" => \$inputFile,
- "a" => \$automatic,
- "d" => \$debug,
- "h" => \$help,
- "help" => \$help
- ) or die("Error in command line arguments");
+ "cfile=s" => \$inputFile,
+ "automatic" => \$automatic,
+ "debug" => \$debug,
+ "help" => \$help
+ ) or die($usageString);
# stores the default questions and answers
our $defaultInputs = getDefaults();
if ($help) {
- print "Usage: postinstall [-a] [-d] -cfile=[config_file]\n";
+ print $usageString;
exit(0);
}
@@ -456,46 +437,45 @@ sub main {
print "Running in automatic mode\n";
}
- # used to store the questions and answers -
- # will either be input config file or defaults
+ logger( "Starting postinstall", "info" );
+
+ # used to store the questions and answers provided by the user
my $userInput;
if ( $::inputFile eq "" ) {
- print "No input file given - using defaults\n";
+ print "No input file given - using defaults\n" if ($::debug);
$userInput = $::defaultInputs;
}
else {
- print "Using input file $::inputFile\n";
+ print "Using input file $::inputFile\n" if ($::debug);
- if ( !-e $::inputFile ) {
- errorOut("Error: file \'$::inputFile\' not found\n");
- }
+ # check if the input file exists
+ errorOut("File \'$::inputFile\' not found") if ( !-e $::inputFile );
+ # read and store the input file
$userInput = readJson($::inputFile);
}
- # check the defaults if running them automatically
- if ( $::inputFile eq "" && $::automatic ) {
- sanityCheckDefaults();
- }
+ # sanity check the defaults if running them automatically
+ sanityCheckDefaults();
- # check the input config file against the defaults
- # to check for missing questions
- if ( $inputFile ne "" ) {
- sanityCheckConfig($userInput);
- }
+ # check the input config file against the defaults to check for missing questions
+ sanityCheckConfig($userInput) if ( $inputFile ne "" );
+
+ writeJson( $outputConfigFile, $userInput );
# The generator functions handle checking input/default/automatic mode
# todbconf will be used later when setting up the database
- my $todbconf = generateDbConf( $userInput, 'testdb.conf', 'testtodb.conf', 'testdbconf.yml' );
- generateCdnConf( $userInput, 'testcdn.conf' );
- generateLdapConf( $userInput, 'testldap.conf' );
- generatePostInstallConf( $userInput, 'testpost_install.json' );
- generateUsersConf( $userInput, 'testusers.json' );
- generateProfilesDir( $userInput, 'testprofiles/' );
+ generateDbConf( $userInput, $::databaseConfFile, $::dbConfFile );
+ generateCdnConf( $userInput, $::cdnConfFile );
+ generateLdapConf( $userInput, $::ldapConfFile );
+ generateUsersConf( $userInput, $::usersConfFile );
+ generateProfilesDir( $userInput, $::profilesConfFile );
}
main;
+logger( "Postinstall complete\n", "info" );
+
# vi:syntax=perl
[31/36] incubator-trafficcontrol git commit: Added description to
database.conf
Posted by da...@apache.org.
Added description to database.conf
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/2778409e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/2778409e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/2778409e
Branch: refs/heads/master
Commit: 2778409efa0d8c86dd9335742f11b2b158e9d999
Parents: c83a26b
Author: peryder <pe...@cisco.com>
Authored: Mon Dec 19 14:56:31 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall-new | 2 +-
traffic_ops/install/lib/ProfileCleanup.pm | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2778409e/traffic_ops/install/bin/postinstall-new
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall-new b/traffic_ops/install/bin/postinstall-new
index d345663..08ba7a7 100755
--- a/traffic_ops/install/bin/postinstall-new
+++ b/traffic_ops/install/bin/postinstall-new
@@ -162,7 +162,7 @@ sub generateDbConf {
my $toDBFileName = shift;
my %dbconf = getConfig( $userInput, $dbFileName );
-
+ $dbconf{"description"} = "$dbconf{type} database on $dbconf{hostname}:$dbconf{port}";
make_path( dirname($dbFileName), { mode => 0755 } );
writeJson( $dbFileName, \%dbconf );
logger( "Database configuration has been saved", "info" );
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2778409e/traffic_ops/install/lib/ProfileCleanup.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/ProfileCleanup.pm b/traffic_ops/install/lib/ProfileCleanup.pm
index 1e6edf9..3f7ce4a 100644
--- a/traffic_ops/install/lib/ProfileCleanup.pm
+++ b/traffic_ops/install/lib/ProfileCleanup.pm
@@ -27,6 +27,7 @@ our %EXPORT_TAGS = ( all => \@EXPORT_OK );
sub profile_replace {
my ($profile) = @_;
my $profile_bak = $profile . ".bak";
+ logger("Replacing parameters in profile: $profile", "info");
rename( $profile, $profile_bak ) or die("rename(): $!");
open( my $fh, '<', $profile_bak ) or die("open(): $!");
open( my $ofh, '>', $profile ) or die("open(): $!");
[21/36] incubator-trafficcontrol git commit: Formatted input.json
Posted by da...@apache.org.
Formatted input.json
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/ca4b10ae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/ca4b10ae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/ca4b10ae
Branch: refs/heads/master
Commit: ca4b10ae8274258aee3c53188038762929d1b4f4
Parents: 832a50f
Author: peryder <pe...@cisco.com>
Authored: Wed Dec 7 10:11:17 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/input.json | 326 ++++++++++++++++----------------
1 file changed, 164 insertions(+), 162 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/ca4b10ae/traffic_ops/install/bin/input.json
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/input.json b/traffic_ops/install/bin/input.json
index 40430e9..9978acb 100644
--- a/traffic_ops/install/bin/input.json
+++ b/traffic_ops/install/bin/input.json
@@ -1,162 +1,164 @@
-{
- "/opt/traffic_ops/app/conf/production/database.conf": [
- {
- "Database type": "mysql",
- "config_var": "type"
- },
- {
- "Database name": "traffic_ops_db",
- "config_var": "dbname"
- },
- {
- "Database server hostname IP or FQDN": "localhost",
- "config_var": "hostname"
- },
- {
- "Database port number": "3306",
- "config_var": "port"
- },
- {
- "Traffic Ops database user": "traffic_ops",
- "config_var": "user"
- },
- {
- "Traffic Ops database password": "default",
- "config_var": "password",
- "hidden": "1"
- }
- ],
- "/opt/traffic_ops/app/db/dbconf.yml": [
- {
- "Database server root (admin) username": "root",
- "config_var": "dbAdminUser"
- },
- {
- "Database server admin password": "default",
- "config_var": "dbAdminPw",
- "hidden": "1"
- }
- ],
- "/opt/traffic_ops/app/conf/cdn.conf": [
- {
- "Generate a new secret?": "yes",
- "config_var": "genSecret"
- },
- {
- "Number of secrets to keep?": "10",
- "config_var": "keepSecrets"
- }
- ],
- "/opt/traffic_ops/app/conf/ldap.conf": [
- {
- "Do you want to set up LDAP?": "no",
- "config_var": "setupLdap"
- },
- {
- "LDAP server hostname": "",
- "config_var": "hostname"
- },
- {
- "LDAP Admin DN": "",
- "config_var": "admin_dn"
- },
- {
- "LDAP Admin Password": "",
- "config_var": "password",
- "hidden": "1"
- },
- {
- "LDAP Search Base": "",
- "config_var": "search_base"
- }
- ],
- "/opt/traffic_ops/install/data/json/users.json": [
- {
- "Administration username for Traffic Ops": "root",
- "config_var": "tmAdminUser"
- },
- {
- "Password for the admin user": "default",
- "config_var": "tmAdminPw",
- "hidden": "1"
- }
- ],
- "/opt/traffic_ops/install/data/profiles/": [],
- "/opt/traffic_ops/install/bin/openssl_configuration.json": [
- {
- "Country Name (2 letter code)": "XX",
- "config_var": "country"
- },
- {
- "State or Province Name (full name)": "Default State",
- "config_var": "state"
- },
- {
- "Locality Name (eg, city)": "Default City",
- "config_var": "locality"
- },
- {
- "Organization Name (eg, company)": "Default Company Ltd",
- "config_var": "company"
- },
- {
- "Organizational Unit Name (eg, section)": "",
- "config_var": "org_unit"
- },
- {
- "Common Name (eg, your name or your server's hostname)": "example.com",
- "config_var": "common_name"
- },
- {
- "RSA Passphrase": "password",
- "config_var": "rsaPassword",
- "hidden": "1"
- }
- ],
- "/opt/traffic_ops/install/data/json/profiles.json": [
- {
- "Traffic Ops url": "https://localhost",
- "config_var": "tm.url"
- },
- {
- "Human-readable CDN Name. (No whitespace, please)": "kabletown_cdn",
- "config_var": "cdn_name"
- },
- {
- "Health Polling Interval (milliseconds)": "8000",
- "config_var": "health_polling_int"
- },
- {
- "DNS sub-domain for which your CDN is authoritative": "cdn1.kabletown.net",
- "config_var": "dns_subdomain"
- },
- {
- "TLD SOA admin": "traffic_ops",
- "config_var": "soa_admin"
- },
- {
- "TrafficServer Drive Prefix": "/dev/sd",
- "config_var": "driver_prefix"
- },
- {
- "TrafficServer RAM Drive Prefix": "/dev/ram",
- "config_var": "ram_drive_prefix"
- },
- {
- "TrafficServer RAM Drive Letters (comma separated)": "0,1,2,3,4,5,6,7",
- "config_var": "ram_drive_letters"
- },
- {
- "Health Threshold Load Average": "25",
- "config_var": "health_thresh_load_avg"
- },
- {
- "Health Threshold Available Bandwidth in Kbps": "1750000",
- "config_var": "health_thresh_kbps"
- },
- {
- "Traffic Server Health Connection Timeout (milliseconds)": "2000",
- "config_var": "health_connect_timeout"
- }
- ]
-}
+{
+ "/opt/traffic_ops/app/conf/production/database.conf":[
+ {
+ "Database type":"mysql",
+ "config_var":"type"
+ },
+ {
+ "Database name":"traffic_ops_db",
+ "config_var":"dbname"
+ },
+ {
+ "Database server hostname IP or FQDN":"localhost",
+ "config_var":"hostname"
+ },
+ {
+ "Database port number":"3306",
+ "config_var":"port"
+ },
+ {
+ "Traffic Ops database user":"traffic_ops",
+ "config_var":"user"
+ },
+ {
+ "Traffic Ops database password":"default",
+ "config_var":"password",
+ "hidden":"1"
+ }
+ ],
+ "/opt/traffic_ops/app/db/dbconf.yml":[
+ {
+ "Database server root (admin) username":"root",
+ "config_var":"dbAdminUser"
+ },
+ {
+ "Database server admin password":"default",
+ "config_var":"dbAdminPw",
+ "hidden":"1"
+ }
+ ],
+ "/opt/traffic_ops/app/conf/cdn.conf":[
+ {
+ "Generate a new secret?":"yes",
+ "config_var":"genSecret"
+ },
+ {
+ "Number of secrets to keep?":"10",
+ "config_var":"keepSecrets"
+ }
+ ],
+ "/opt/traffic_ops/app/conf/ldap.conf":[
+ {
+ "Do you want to set up LDAP?":"no",
+ "config_var":"setupLdap"
+ },
+ {
+ "LDAP server hostname":"",
+ "config_var":"hostname"
+ },
+ {
+ "LDAP Admin DN":"",
+ "config_var":"admin_dn"
+ },
+ {
+ "LDAP Admin Password":"",
+ "config_var":"password",
+ "hidden":"1"
+ },
+ {
+ "LDAP Search Base":"",
+ "config_var":"search_base"
+ }
+ ],
+ "/opt/traffic_ops/install/data/json/users.json":[
+ {
+ "Administration username for Traffic Ops":"root",
+ "config_var":"tmAdminUser"
+ },
+ {
+ "Password for the admin user":"default",
+ "config_var":"tmAdminPw",
+ "hidden":"1"
+ }
+ ],
+ "/opt/traffic_ops/install/data/profiles/":[
+
+ ],
+ "/opt/traffic_ops/install/bin/openssl_configuration.json":[
+ {
+ "Country Name (2 letter code)":"XX",
+ "config_var":"country"
+ },
+ {
+ "State or Province Name (full name)":"Default State",
+ "config_var":"state"
+ },
+ {
+ "Locality Name (eg, city)":"Default City",
+ "config_var":"locality"
+ },
+ {
+ "Organization Name (eg, company)":"Default Company Ltd",
+ "config_var":"company"
+ },
+ {
+ "Organizational Unit Name (eg, section)":"",
+ "config_var":"org_unit"
+ },
+ {
+ "Common Name (eg, your name or your server's hostname)":"example.com",
+ "config_var":"common_name"
+ },
+ {
+ "RSA Passphrase":"password",
+ "config_var":"rsaPassword",
+ "hidden":"1"
+ }
+ ],
+ "/opt/traffic_ops/install/data/json/profiles.json":[
+ {
+ "Traffic Ops url":"https://localhost",
+ "config_var":"tm.url"
+ },
+ {
+ "Human-readable CDN Name. (No whitespace, please)":"kabletown_cdn",
+ "config_var":"cdn_name"
+ },
+ {
+ "Health Polling Interval (milliseconds)":"8000",
+ "config_var":"health_polling_int"
+ },
+ {
+ "DNS sub-domain for which your CDN is authoritative":"cdn1.kabletown.net",
+ "config_var":"dns_subdomain"
+ },
+ {
+ "TLD SOA admin":"traffic_ops",
+ "config_var":"soa_admin"
+ },
+ {
+ "TrafficServer Drive Prefix":"/dev/sd",
+ "config_var":"driver_prefix"
+ },
+ {
+ "TrafficServer RAM Drive Prefix":"/dev/ram",
+ "config_var":"ram_drive_prefix"
+ },
+ {
+ "TrafficServer RAM Drive Letters (comma separated)":"0,1,2,3,4,5,6,7",
+ "config_var":"ram_drive_letters"
+ },
+ {
+ "Health Threshold Load Average":"25",
+ "config_var":"health_thresh_load_avg"
+ },
+ {
+ "Health Threshold Available Bandwidth in Kbps":"1750000",
+ "config_var":"health_thresh_kbps"
+ },
+ {
+ "Traffic Server Health Connection Timeout (milliseconds)":"2000",
+ "config_var":"health_connect_timeout"
+ }
+ ]
+}
\ No newline at end of file
[24/36] incubator-trafficcontrol git commit: Added apache license to
postinstall-new-integrated
Posted by da...@apache.org.
Added apache license to postinstall-new-integrated
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/70545613
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/70545613
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/70545613
Branch: refs/heads/master
Commit: 70545613b5f66d35429a9f9b205a0a12d4067829
Parents: 831d58d
Author: peryder <pe...@cisco.com>
Authored: Wed Dec 7 10:22:34 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall-new-integrated | 14 ++++++++++++++
1 file changed, 14 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/70545613/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 cc6ec82..9972daa 100755
--- a/traffic_ops/install/bin/postinstall-new-integrated
+++ b/traffic_ops/install/bin/postinstall-new-integrated
@@ -1,5 +1,19 @@
#!/usr/bin/perl
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/install/lib/perl5 /opt/traffic_ops/app/local/lib/perl5 /opt/traffic_ops/app/lib);
$ENV{PATH} = "/opt/traffic_ops/install/bin:$ENV{PATH}";
$ENV{PERL5LIB} = "/opt/traffic_ops/install/lib:/opt/traffic_ops/install/lib/perl5:/opt/traffic_ops/app/local/lib/perl5:/opt/traffic_ops/app/lib";
[17/36] incubator-trafficcontrol git commit: Fixed dependencies not
being downloaded by adding -y to yum install
Posted by da...@apache.org.
Fixed dependencies not being downloaded by adding -y to yum install
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/e6a31225
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/e6a31225
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/e6a31225
Branch: refs/heads/master
Commit: e6a3122520af7bfe353ea6917f296375b5d7a009
Parents: 0ab8be7
Author: peryder <pe...@cisco.com>
Authored: Mon Dec 5 14:13:13 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall-new-integrated | 3 +--
traffic_ops/install/lib/BuildPerlDeps.pm | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/e6a31225/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 3bfb712..dbf0791 100755
--- a/traffic_ops/install/bin/postinstall-new-integrated
+++ b/traffic_ops/install/bin/postinstall-new-integrated
@@ -18,7 +18,6 @@ use ProfileCleanup qw { :all };
use Digest::SHA1 qw(sha1_hex);
use Data::Dumper qw(Dumper);
use Scalar::Util qw(looks_like_number);
-
use Getopt::Long;
# paths of the output configuration files
@@ -50,7 +49,7 @@ my $dumpDefaults;
# log file for the installer
our $logFile = "/var/log/traffic_ops/postinstall.log";
-# maximum size the log file should be before rotating it - rotating it copies the current log
+# maximum size the uncompressed log file should be before rotating it - rotating it copies the current log
# file to the same name appended with .bkp replacing the old backup if any is there
my $maxLogSize = 1000000; #bytes
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/e6a31225/traffic_ops/install/lib/BuildPerlDeps.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/BuildPerlDeps.pm b/traffic_ops/install/lib/BuildPerlDeps.pm
index b3126bc..e127d07 100644
--- a/traffic_ops/install/lib/BuildPerlDeps.pm
+++ b/traffic_ops/install/lib/BuildPerlDeps.pm
@@ -56,7 +56,7 @@ EOF
}
logger( "Installing dependencies", "info" );
- $result = execCommand( "/usr/bin/yum", "install", @dependencies );
+ $result = execCommand( "/usr/bin/yum", "-y", "install", @dependencies );
if ( $result != 0 ) {
errorOut("Dependency installation failed, look through the output and correct the problem");
}
[34/36] incubator-trafficcontrol git commit: Removed global vars and
made many minor improvements
Posted by da...@apache.org.
Removed global vars and made many minor improvements
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/230aa7c0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/230aa7c0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/230aa7c0
Branch: refs/heads/master
Commit: 230aa7c0735312d0a35c1f76f8ca5f1991640368
Parents: d775c03
Author: peter.w.ryder <pe...@gmail.com>
Authored: Thu Jan 12 15:10:00 2017 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/bin/postinstall | 293 +++++++++++----------
traffic_ops/install/lib/BuildPerlDeps.pm | 32 ++-
traffic_ops/install/lib/GenerateCert.pm | 26 +-
traffic_ops/install/lib/InstallUtils.pm | 21 +-
traffic_ops/install/lib/ProfileCleanup.pm | 199 +++++++++------
traffic_ops/install/lib/WebDep.pm | 337 +++++++++++++------------
6 files changed, 493 insertions(+), 415 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/230aa7c0/traffic_ops/install/bin/postinstall
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall b/traffic_ops/install/bin/postinstall
index 1092338..2f6f3d7 100755
--- a/traffic_ops/install/bin/postinstall
+++ b/traffic_ops/install/bin/postinstall
@@ -25,53 +25,66 @@ use Safe;
use POSIX;
use File::Basename qw{dirname};
use File::Path qw{make_path};
-use InstallUtils qw{ :all };
-use BuildPerlDeps qw{ :all };
-use GenerateCert qw{ :all };
-use ProfileCleanup qw { :all };
use Digest::SHA1 qw(sha1_hex);
use Data::Dumper qw(Dumper);
use Scalar::Util qw(looks_like_number);
use Getopt::Long;
+use InstallUtils;
+use BuildPerlDeps;
+use GenerateCert qw{ :all };
+use ProfileCleanup;
+
# paths of the output configuration files
-our $databaseConfFile = "/opt/traffic_ops/app/conf/production/database.conf";
-our $dbConfFile = "/opt/traffic_ops/app/db/dbconf.yml";
-our $cdnConfFile = "/opt/traffic_ops/app/conf/cdn.conf";
-our $ldapConfFile = "/opt/traffic_ops/app/conf/ldap.conf";
-our $usersConfFile = "/opt/traffic_ops/install/data/json/users.json";
-our $profilesConfFile = "/opt/traffic_ops/install/data/profiles/";
-our $opensslConfFile = "/opt/traffic_ops/install/data/json/openssl_configuration.json";
-our $paramConfFile = "/opt/traffic_ops/install/data/json/profiles.json";
+my $databaseConfFile = "/opt/traffic_ops/app/conf/production/database.conf";
+my $dbConfFile = "/opt/traffic_ops/app/db/dbconf.yml";
+my $cdnConfFile = "/opt/traffic_ops/app/conf/cdn.conf";
+my $ldapConfFile = "/opt/traffic_ops/app/conf/ldap.conf";
+my $usersConfFile = "/opt/traffic_ops/install/data/json/users.json";
+my $profilesConfFile = "/opt/traffic_ops/install/data/profiles/";
+my $opensslConfFile = "/opt/traffic_ops/install/data/json/openssl_configuration.json";
+my $paramConfFile = "/opt/traffic_ops/install/data/json/profiles.json";
-our $profile_dir = "/opt/traffic_ops/install/data/profiles/";
-our $post_install_cfg = "/opt/traffic_ops/install/data/json/post_install.json";
+my $custom_profile_dir = $profilesConfFile . "custom";
-our $reconfigure_defaults = "/opt/traffic_ops/.reconfigure_defaults";
+# stores parameters for traffic ops config
+my $parameters;
-our $parameters;
+# location of traffic ops profiles
+my $profileDir = "/opt/traffic_ops/install/data/profiles/";
+my $post_install_cfg = "/opt/traffic_ops/install/data/json/post_install.json";
-# 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";
+# log file for the installer
+my $logFile = "/var/log/traffic_ops/postinstall.log";
+
+# debug mode
+my $debug = 0;
+
+# log file for cpan output
+my $cpanLogFile = "/var/log/traffic_ops/cpan.log";
# whether or not to reconfigure traffic ops
-my $reconfigure;
+my $reconfigure = 0;
-# whether to create a config file with default values
-my $dumpDefaults;
+# used to check for .reconfigure_defaults file for backwards compatability
+my $reconfigure_defaults = "/opt/traffic_ops/.reconfigure_defaults";
-# log file for the installer
-our $logFile = "/var/log/traffic_ops/postinstall.log";
+# 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";
# maximum size the uncompressed log file should be before rotating it - rotating it copies the current log
# file to the same name appended with .bkp replacing the old backup if any is there
-my $maxLogSize = 1000000; #bytes
+my $maxLogSize = 10000000; #bytes
-# log file for cpan - this log becomes large and is rotated every install
-our $cpanLogFile = "/var/log/traffic_ops/cpan.log";
+# whether to create a config file with default values
+my $dumpDefaults;
# configuration file output with answers which can be used as input to postinstall
-our $outputConfigFile = "/var/log/traffic_ops/configuration_file.json";
+my $outputConfigFile = "/opt/traffic_ops/install/bin/configuration_file.json";
+
+my $inputFile = "";
+my $automatic = 0;
+my $defaultInputs;
sub getDbDriver {
return "mymysql";
@@ -105,7 +118,7 @@ sub getField {
my $hidden = shift;
# if there is no config file and not in automatic mode prompt for all questions with default answers
- if ( !$::inputFile && !$::automatic ) {
+ if ( !$inputFile && !$automatic ) {
# if hidden then dont show password in terminal
if ($hidden) {
@@ -132,10 +145,10 @@ sub getConfig {
my %config;
if ( !defined $userInput->{$fileName} ) {
- logger( "No $fileName found in config", "error" );
+ InstallUtils::logger( "No $fileName found in config", "error" );
}
- logger( "===========$fileName===========", "info" );
+ InstallUtils::logger( "===========$fileName===========", "info" );
foreach my $var ( @{ $userInput->{$fileName} } ) {
my $question = getConfigQuestion($var);
@@ -144,7 +157,7 @@ sub getConfig {
$config{ $var->{"config_var"} } = $answer;
if ( !$hidden ) {
- logger( "$question: $answer", "info" );
+ InstallUtils::logger( "$question: $answer", "info" );
}
}
return %config;
@@ -164,8 +177,8 @@ sub generateDbConf {
my %dbconf = getConfig( $userInput, $dbFileName );
$dbconf{"description"} = "$dbconf{type} database on $dbconf{hostname}:$dbconf{port}";
make_path( dirname($dbFileName), { mode => 0755 } );
- writeJson( $dbFileName, \%dbconf );
- logger( "Database configuration has been saved", "info" );
+ InstallUtils::writeJson( $dbFileName, \%dbconf );
+ InstallUtils::logger( "Database configuration has been saved", "info" );
# broken out into separate file/config area
my %todbconf = getConfig( $userInput, $toDBFileName );
@@ -191,22 +204,22 @@ sub generateCdnConf {
my %cdnConfiguration = getConfig( $userInput, $fileName );
- # First, read existing one -- already loaded with a bunch of stuff
+ # 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: $@");
}
if ( lc $cdnConfiguration{genSecret} =~ /^y(?:es)?/ ) {
my @secrets = @{ $cdnConf->{secrets} };
- my $newSecret = randomWord();
- unshift @secrets, randomWord();
+ my $newSecret = InstallUtils::randomWord();
+ unshift @secrets, InstallUtils::randomWord();
if ( $cdnConfiguration{keepSecrets} > 0 && $#secrets > $cdnConfiguration{keepSecrets} - 1 ) {
# Shorten the array to requested length
$#secrets = $cdnConfiguration{keepSecrets} - 1;
}
}
- writePerl( $fileName, $cdnConf );
+ InstallUtils::writePerl( $fileName, $cdnConf );
}
# userInput: The entire input config file which is either user input or the defaults
@@ -221,14 +234,14 @@ sub generateLdapConf {
my $useLdap = $userInput->{$fileName}[0]->{"Do you want to set up LDAP?"};
if ( !lc $useLdap =~ /^y(?:es)?/ ) {
- logger( "Not setting up ldap", "info" );
+ InstallUtils::logger( "Not setting up ldap", "info" );
return;
}
my %ldapConf = getConfig( $userInput, $fileName );
make_path( dirname($fileName), { mode => 0755 } );
- writeJson( $fileName, \%ldapConf );
+ InstallUtils::writeJson( $fileName, \%ldapConf );
}
sub generateUsersConf {
@@ -241,7 +254,7 @@ sub generateUsersConf {
$user{username} = $config{tmAdminUser};
$user{password} = sha1_hex( $config{tmAdminPw} );
- writeJson( $fileName, \%user );
+ InstallUtils::writeJson( $fileName, \%user );
$user{password} = $config{tmAdminPw};
return \%user;
}
@@ -258,16 +271,16 @@ sub generateOpenSSLConf {
my $fileName = shift;
if ( !defined $userInput->{$fileName} ) {
- logger( "No OpenSSL Configuration - questions will be asked", "info" );
+ InstallUtils::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 );
+ InstallUtils::writeJson( $fileName, my %emptyConfig );
return;
}
my %config = getConfig( $userInput, $fileName );
- writeJson( $fileName, \%config );
+ InstallUtils::writeJson( $fileName, \%config );
return \%config;
}
@@ -276,14 +289,14 @@ sub generateParamConf {
my $fileName = shift;
my %config = getConfig( $userInput, $fileName );
- writeJson( $fileName, \%config );
+ InstallUtils::writeJson( $fileName, \%config );
return \%config;
}
# check default values for missing config_var parameter
sub sanityCheckDefaults {
- foreach my $file ( ( keys $::defaultInputs ) ) {
- foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
+ foreach my $file ( ( keys $defaultInputs ) ) {
+ foreach my $defaultValue ( @{ $defaultInputs->{$file} } ) {
my $question = getConfigQuestion($defaultValue);
if ( !defined $defaultValue->{"config_var"}
@@ -304,13 +317,13 @@ sub sanityCheckConfig {
my $userInput = shift;
my $diffs = 0;
- foreach my $file ( ( keys $::defaultInputs ) ) {
+ foreach my $file ( ( keys $defaultInputs ) ) {
if ( !defined $userInput->{$file} ) {
- logger( "File '$file' found in defaults but not config file", "warn" );
+ InstallUtils::logger( "File '$file' found in defaults but not config file", "warn" );
$userInput->{$file} = [];
}
- foreach my $defaultValue ( @{ $::defaultInputs->{$file} } ) {
+ foreach my $defaultValue ( @{ $defaultInputs->{$file} } ) {
my $found = 0;
foreach my $configValue ( @{ $userInput->{$file} } ) {
@@ -322,21 +335,21 @@ sub sanityCheckConfig {
# if the question is not found in the config file add it from defaults
if ( !$found ) {
my $question = getConfigQuestion($defaultValue);
- logger( "Question '$question' found in defaults but not in '$file'", "warn" );
+ InstallUtils::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) {
+ if ($automatic) {
$answer = $defaultValue->{$question};
- logger( "Adding question '$question' with default answer " . ( $hidden ? "" : "'$answer'" ), "info" );
+ InstallUtils::logger( "Adding question '$question' with default answer " . ( $hidden ? "" : "'$answer'" ), "info" );
}
# in interactive mode prompt the user for answer to missing question
else {
- logger( "Prompting user for answer", "info" );
+ InstallUtils::logger( "Prompting user for answer", "info" );
if ($hidden) {
$answer = promptPasswordVerify($question);
}
@@ -361,7 +374,7 @@ sub sanityCheckConfig {
}
}
- logger( "File sanity check complete - found $diffs difference" . ( $diffs == 1 ? "" : "s" ), "info" );
+ InstallUtils::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
@@ -369,7 +382,7 @@ sub sanityCheckConfig {
sub getDefaults {
return {
- $::databaseConfFile => [
+ $databaseConfFile => [
{
"Database type" => "mysql",
"config_var" => "type"
@@ -396,7 +409,7 @@ sub getDefaults {
"hidden" => "true"
}
],
- $::dbConfFile => [
+ $dbConfFile => [
{
"Database server root (admin) user" => "root",
"config_var" => "dbAdminUser"
@@ -407,7 +420,7 @@ sub getDefaults {
"hidden" => "true"
}
],
- $::cdnConfFile => [
+ $cdnConfFile => [
{
"Generate a new secret?" => "yes",
"config_var" => "genSecret"
@@ -417,7 +430,7 @@ sub getDefaults {
"config_var" => "keepSecrets"
}
],
- $::ldapConfFile => [
+ $ldapConfFile => [
{
"Do you want to set up LDAP?" => "no",
"config_var" => "setupLdap"
@@ -440,7 +453,7 @@ sub getDefaults {
"config_var" => "search_base"
}
],
- $::usersConfFile => [
+ $usersConfFile => [
{
"Administration username for Traffic Ops" => "admin",
"config_var" => "tmAdminUser"
@@ -451,8 +464,8 @@ sub getDefaults {
"hidden" => "true"
}
],
- $::profilesConfFile => [],
- $::opensslConfFile => [
+ $profilesConfFile => [],
+ $opensslConfFile => [
{
"Do you want to generate a certificate?" => "yes",
"config_var" => "genCert"
@@ -487,7 +500,7 @@ sub getDefaults {
"hidden" => "true"
}
],
- $::paramConfFile => [
+ $paramConfFile => [
{
"Traffic Ops url" => "https://localhost",
"config_var" => "tm.url"
@@ -550,61 +563,61 @@ sub setupDatabase {
#
# Call mysql initialization script.
#
- logger( "Creating database with user: $todbconf->{dbAdminUser}", "info" );
- my $result = execCommand( "/opt/traffic_ops/install/bin/create_db", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
+ InstallUtils::logger( "Creating database with user: $todbconf->{dbAdminUser}", "info" );
+ my $result = InstallUtils::execCommand( "/opt/traffic_ops/install/bin/create_db", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
if ( $result != 0 ) {
errorOut("Failed to create the database");
}
- logger( "Setting up database", "info" );
+ InstallUtils::logger( "Setting up database", "info" );
chdir("/opt/traffic_ops/app");
- $result = execCommand( "/usr/bin/perl", "db/admin.pl", "--env=production", "setup" );
+ $result = InstallUtils::execCommand( "/usr/bin/perl", "db/admin.pl", "--env=production", "setup" );
if ( $result != 0 ) {
errorOut("Database initialization failed");
}
else {
- logger( "Database initialization succeeded", "info" );
+ InstallUtils::logger( "Database initialization succeeded", "info" );
}
- $result = execCommand( "/opt/traffic_ops/install/bin/dataload", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
+ $result = InstallUtils::execCommand( "/opt/traffic_ops/install/bin/dataload", $todbconf->{dbAdminUser}, $todbconf->{dbAdminPw} );
if ( $result != 0 ) {
- logger( "Failed to load seed data", "error" );
+ InstallUtils::logger( "Failed to load seed data", "error" );
}
- logger( "Downloading MaxMind data", "info" );
+ InstallUtils::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 = InstallUtils::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" );
+ InstallUtils::logger( "Failed to download MaxMind data", "error" );
}
- logger( "Copying coverage zone file to public dir", "info" );
- $result = execCommand("/bin/mv /opt/traffic_ops/app/public/coverage-zone.json .");
+ InstallUtils::logger( "Copying coverage zone file to public dir", "info" );
+ $result = InstallUtils::execCommand("/bin/mv /opt/traffic_ops/app/public/coverage-zone.json .");
if ( $result != 0 ) {
- logger( "Failed to copy coverage zone file", "error" );
+ InstallUtils::logger( "Failed to copy coverage zone file", "error" );
}
if ( lc $genCert =~ /^y(?:es)?/ ) {
if ( -x "/usr/bin/openssl" ) {
- logger( "Installing SSL Certificates", "info" );
+ InstallUtils::logger( "Installing SSL Certificates", "info" );
$result = GenerateCert::createCert($opensslconf);
if ( $result != 0 ) {
errorOut("SSL Certificate Installation failed");
}
else {
- logger( "SSL Certificates have been installed", "info" );
+ InstallUtils::logger( "SSL Certificates have been installed", "info" );
}
}
else {
- logger( "Unable to install SSL certificates as openssl is not installed", "error" );
- logger( "Install openssl and then run /opt/traffic_ops/install/bin/generateCert to install SSL certificates", "error" );
+ InstallUtils::logger( "Unable to install SSL certificates as openssl is not installed", "error" );
+ InstallUtils::logger( "Install openssl and then run /opt/traffic_ops/install/bin/generateCert to install SSL certificates", "error" );
exit 4;
}
}
else {
- logger("Not generating openssl certification", "info");
+ InstallUtils::logger( "Not generating openssl certification", "info" );
}
}
@@ -612,17 +625,15 @@ sub setupDatabase {
# -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
+# -r - Reconfigure: Whether or not to reconfigure the database and check perl dependencies - This will recreate 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 = "";
- our $automatic = 0;
- our $debug = 0;
my $help = 0;
+ # help string
my $usageString = "Usage: postinstall [-a] [-debug] [-defaults] [-r] -cfile=[config_file]\n";
GetOptions(
@@ -635,11 +646,11 @@ sub main {
) or die($usageString);
# stores the default questions and answers
- our $defaultInputs = getDefaults();
+ $defaultInputs = getDefaults();
if ($help) {
print $usageString;
- exit(0);
+ return;
}
# check if the user running postinstall is root
@@ -647,37 +658,39 @@ sub main {
errorOut("You must run this script as the root user");
}
+ InstallUtils::initLogger( $debug, $logFile );
+
if ( -f "$logFile.gz" ) {
- execCommand( "/bin/gunzip", "$logFile.gz" );
+ InstallUtils::execCommand( "/bin/gunzip", "$logFile.gz" );
}
- logger( "Starting postinstall", "info" );
+ InstallUtils::logger( "Starting postinstall", "info" );
- logger( "Debug is on", "info" );
+ InstallUtils::logger( "Debug is on", "info" );
- if ($::automatic) {
- logger( "Running in automatic mode", "info" );
+ if ($automatic) {
+ InstallUtils::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" );
+ InstallUtils::logger( "$reconfigure_file file is depreprecated - please remove and rerun postinstall", "error" );
return;
}
if ($dumpDefaults) {
- logger( "Writing default configuration file to $outputConfigFile", "info" );
- writeJson( $outputConfigFile, $::defaultInputs );
+ InstallUtils::logger( "Writing default configuration file to $outputConfigFile", "info" );
+ InstallUtils::writeJson( $outputConfigFile, $defaultInputs );
return;
}
- logger( "Postinstall " . ( defined $reconfigure ? "in" : "not" ) . " in reconfigure mode", "info" );
+ InstallUtils::logger( "Postinstall " . ( defined $reconfigure ? "in" : "not" ) . " in reconfigure mode", "info" );
- rotateLog($cpanLogFile);
+ InstallUtils::rotateLog($cpanLogFile);
- if ( -s $::logFile > $maxLogSize ) {
- logger( "Postinstall log above max size of $maxLogSize bytes - rotating", "info" );
+ if ( -s $logFile > $maxLogSize ) {
+ InstallUtils::logger( "Postinstall log above max size of $maxLogSize bytes - rotating", "info" );
rotateLog($logFile);
}
@@ -685,18 +698,18 @@ sub main {
my $userInput;
# if no input file provided use the defaults
- if ( $::inputFile eq "" ) {
- logger( "No input file given - using defaults", "info" );
- $userInput = $::defaultInputs;
+ if ( $inputFile eq "" ) {
+ InstallUtils::logger( "No input file given - using defaults", "info" );
+ $userInput = $defaultInputs;
}
else {
- logger( "Using input file $::inputFile", "info" );
+ InstallUtils::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);
+ $userInput = InstallUtils::readJson($inputFile);
}
# sanity check the defaults if running them automatically
@@ -707,13 +720,13 @@ sub main {
chdir("/opt/traffic_ops/install/bin");
- # if the reconfigure file exists or reconfigure is set then rebuild the perl deps
- if ( -f $reconfigure_file || $reconfigure ) {
- my $rc = BuildPerlDeps::build(1);
+ # if reconfigure is set then rebuild the perl deps
+ if ( $reconfigure ) {
+ my $rc = BuildPerlDeps::build( 1, $cpanLogFile );
if ( $rc != 0 ) {
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" );
+ $rc = InstallUtils::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");
}
@@ -723,7 +736,7 @@ sub main {
if ( $rc != 0 ) {
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" );
+ $rc = InstallUtils::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");
}
@@ -732,48 +745,54 @@ sub main {
# The generator functions handle checking input/default/automatic mode
# todbconf will be used later when setting up the database
- my $todbconf = generateDbConf( $userInput, $::databaseConfFile, $::dbConfFile );
- generateCdnConf( $userInput, $::cdnConfFile );
- generateLdapConf( $userInput, $::ldapConfFile );
- my $adminconf = generateUsersConf( $userInput, $::usersConfFile );
- generateProfilesDir( $userInput, $::profilesConfFile );
- my $opensslconf = generateOpenSSLConf( $userInput, $::opensslConfFile );
- my $paramconf = generateParamConf( $userInput, $::paramConfFile );
-
- # if the reconfigure file exists or the reconfigure command line arg is set then setup the database
- if ( -f $reconfigure_file || $reconfigure ) {
- if ($::automatic) {
- setupDatabase( $todbconf, $::opensslConfFile, $opensslconf->{genCert} );
+ my $todbconf = generateDbConf( $userInput, $databaseConfFile, $dbConfFile );
+ generateCdnConf( $userInput, $cdnConfFile );
+ generateLdapConf( $userInput, $ldapConfFile );
+ my $adminconf = generateUsersConf( $userInput, $usersConfFile );
+ my $custom_profile = generateProfilesDir( $userInput, $profilesConfFile );
+ my $opensslconf = generateOpenSSLConf( $userInput, $opensslConfFile );
+ my $paramconf = generateParamConf( $userInput, $paramConfFile );
+
+ InstallUtils::writeJson( $post_install_cfg, $paramconf );
+
+ # if reconfigure is set then setup the database
+ if ( $reconfigure ) {
+ if ( $automatic ) {
+ setupDatabase( $todbconf, $opensslConfFile, $opensslconf->{genCert} );
}
else {
setupDatabase( $todbconf, 0, $opensslconf->{genCert} );
}
}
- # remove the reconfigure file if it exists
- if ( -f $reconfigure_file ) {
- logger( "Removing reconfigure file", "info" );
- unlink($reconfigure_file);
- }
+ InstallUtils::logger( "Starting Traffic Ops", "info" );
+ InstallUtils::execCommand("/sbin/service traffic_ops start");
+
+ InstallUtils::logger( "Waiting for Traffic Ops to start", "info" );
- logger( "Starting Traffic Ops", "info" );
- execCommand("/sbin/service traffic_ops start");
+ if (-f $post_install_cfg) {
+ $parameters = InstallUtils::readJson($post_install_cfg);
+ }
- logger( "Waiting for Traffic Ops to start", "info" );
+ if ( !ProfileCleanup::profiles_exist( $adminconf, $paramconf->{"tm.url"}, $parameters, $reconfigure_defaults, $reconfigure ) ) {
+ InstallUtils::logger( "Creating default profiles...", "info" );
+ ProfileCleanup::replace_profile_templates( $paramconf, $adminconf, $post_install_cfg, $parameters, $profileDir );
+ ProfileCleanup::import_profiles( $paramconf->{"tm.url"}, $adminconf, $profileDir );
- if ( !profiles_exist( $adminconf, $paramconf->{"tm.url"} ) ) {
- logger( "Creating default profiles...", "info" );
- replace_profile_templates($paramconf);
- import_profiles($adminconf);
- profiles_exist( $adminconf, $paramconf->{"tm.url"} ); # call again to create $reconfigure_defaults file if import was successful
+ # call again to create $reconfigure_defaults file if import was successful
+ ProfileCleanup::profiles_exist( $adminconf, $paramconf->{"tm.url"}, $parameters, $reconfigure_defaults, $reconfigure );
}
else {
- logger( "Not creating default profiles", "info" );
+ InstallUtils::logger( "Not creating default profiles", "info" );
+ }
+
+ if ( $custom_profile =~ /^y(?:es)?/ ) {
+ ProfileCleanup::add_custom_profiles( $custom_profile_dir, $adminconf, $parameters->{"tm.url"} );
}
- logger("Postinstall complete");
+ InstallUtils::logger("Postinstall complete");
- execCommand( "/bin/gzip", "$logFile" );
+ InstallUtils::execCommand( "/bin/gzip", "$logFile" );
}
main;
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/230aa7c0/traffic_ops/install/lib/BuildPerlDeps.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/BuildPerlDeps.pm b/traffic_ops/install/lib/BuildPerlDeps.pm
index 5566b73..2bf5eed 100644
--- a/traffic_ops/install/lib/BuildPerlDeps.pm
+++ b/traffic_ops/install/lib/BuildPerlDeps.pm
@@ -17,6 +17,9 @@ use lib qw(/opt/traffic_ops/install/lib /opt/traffic_ops/lib/perl5 /opt/traffic_
package BuildPerlDeps;
+use strict;
+use warnings;
+
use InstallUtils qw{ :all };
use base qw{ Exporter };
@@ -24,7 +27,8 @@ our @EXPORT_OK = qw{ build };
our %EXPORT_TAGS = ( all => \@EXPORT_OK );
sub build {
- my $opt_i = shift;
+ my $opt_i = shift;
+ my $cpanLogFile = shift;
my @dependencies = ( "expat-devel", "mod_ssl", "mkisofs", "libpcap", "libpcap-devel", "libcurl", "libcurl-devel", "mysql-server", "mysql-devel", "openssl", "openssl-devel", "cpan", "gcc", "make", "pkgconfig", "automake", "autoconf", "libtool", "gettext", "libidn-devel" );
@@ -46,7 +50,7 @@ EOF
errorOut("You must run this script as the root user");
}
- logger( $msg, "info" );
+ InstallUtils::logger( $msg, "info" );
chdir("/opt/traffic_ops/app");
@@ -55,43 +59,45 @@ EOF
errorOut("You must install 'yum'");
}
- logger( "Installing dependencies", "info" );
- $result = execCommand( "/usr/bin/yum", "-y", "install", @dependencies );
+ InstallUtils::logger( "Installing dependencies", "info" );
+ $result = InstallUtils::execCommand( "/usr/bin/yum", "-y", "install", @dependencies );
if ( $result != 0 ) {
errorOut("Dependency installation failed, look through the output and correct the problem");
}
- logger( "Building perl modules", "info" );
+ InstallUtils::logger( "Building perl modules", "info" );
- $result = execCommand( "/usr/bin/cpan", "pi_custom_log=" . $::cpanLogFile, "-if", "YAML" );
+ $result = InstallUtils::execCommand( "/usr/bin/cpan", "pi_custom_log=" . $cpanLogFile, "-if", "YAML" );
if ( $result != 0 ) {
errorOut("Failed to install YAML, look through the output and correct the problem");
}
- $result = execCommand( "/usr/bin/cpan", "pi_custom_log=" . $::cpanLogFile, "-if", "MIYAGAWA/Carton-v1.0.15.tar.gz" );
+ $result = InstallUtils::execCommand( "/usr/bin/cpan", "pi_custom_log=" . $cpanLogFile, "-if", "MIYAGAWA/Carton-v1.0.15.tar.gz" );
if ( $result != 0 ) {
errorOut("Failed to install Carton, look through the output and correct the problem");
}
}
- $result = execCommand( "/usr/local/bin/carton", "install" );
+ $result = InstallUtils::execCommand( "/usr/local/bin/carton", "install" );
if ( $result != 0 ) {
errorOut("Failure to build required perl modules, check the output and correct the problem");
}
if ( !-s "/opt/traffic_ops/lib/perl5" ) {
- logger( "Linking perl libraries...", "info" );
+ InstallUtils::logger( "Linking perl libraries...", "info" );
if ( !-d "/opt/traffic_ops/lib" ) {
mkdir("/opt/traffic_ops/lib");
}
symlink( "/opt/traffic_ops/app/local/lib/perl5", "/opt/traffic_ops/lib/perl5" );
- execCommand( "/bin/chown", "-R", "trafops:trafops", "/opt/traffic_ops/lib" );
+ InstallUtils::execCommand( "/bin/chown", "-R", "trafops:trafops", "/opt/traffic_ops/lib" );
}
- logger( "Installing perl scripts", "info" );
+ InstallUtils::logger( "Installing perl scripts", "info" );
chdir("/opt/traffic_ops/app/local/bin");
- my $rc = execCommand( "/bin/cp", "-R", ".", "/opt/traffic_ops/app/bin" );
+ my $rc = InstallUtils::execCommand( "/bin/cp", "-R", ".", "/opt/traffic_ops/app/bin" );
if ( $rc != 0 ) {
- logger( "Failed to copy perl scripts to /opt/traffic_ops/app/bin", "error" );
+ InstallUtils::logger( "Failed to copy perl scripts to /opt/traffic_ops/app/bin", "error" );
}
return 0;
}
+
+1;
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/230aa7c0/traffic_ops/install/lib/GenerateCert.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/GenerateCert.pm b/traffic_ops/install/lib/GenerateCert.pm
index 8fb1a11..ef2bb46 100644
--- a/traffic_ops/install/lib/GenerateCert.pm
+++ b/traffic_ops/install/lib/GenerateCert.pm
@@ -97,7 +97,7 @@ sub writeCdn_conf {
# Returns the OpenSSL exit code.
sub execOpenssl {
my ( $description, @args ) = @_;
- logger( $description, "info" );
+ InstallUtils::logger( $description, "info" );
my $result = 1;
while ( $result != 0 ) {
$result = InstallUtils::execCommand( "openssl", @args );
@@ -120,12 +120,12 @@ sub createCert {
my $opensslconf = shift;
if ( !defined $opensslconf ) {
- logger( "No input file - running openssl configuration in interactive mode", "info" );
+ InstallUtils::logger( "No input file - running openssl configuration in interactive mode", "info" );
}
- logger( $msg, "info" );
+ InstallUtils::logger( $msg, "info" );
- logger( "Postinstall SSL Certificate Creation", "info" );
+ InstallUtils::logger( "Postinstall SSL Certificate Creation", "info" );
my $params;
my $passphrase;
@@ -145,7 +145,7 @@ sub createCert {
if ( execOpenssl( "Generating an RSA Private Server Key", "genrsa", "-des3", "-out", "server.key", "-passout", "pass:$passphrase", "1024" ) != 0 ) {
exit 1;
}
- logger( "The server key has been generated", "info" );
+ InstallUtils::logger( "The server key has been generated", "info" );
if ($params) {
if ( execOpenssl( "Creating a Certificate Signing Request (CSR)", "req", "-new", "-key", "server.key", "-out", "server.csr", "-passin", "pass:$passphrase", "-subj", $params ) != 0 ) {
@@ -158,21 +158,21 @@ sub createCert {
}
}
- logger( "The Certificate Signing Request has been generated", "info" );
+ InstallUtils::logger( "The Certificate Signing Request has been generated", "info" );
InstallUtils::execCommand( "/bin/mv", "server.key", "server.key.orig" );
if ( execOpenssl( "Removing the pass phrase from the server key", "rsa", "-in", "server.key.orig", "-out", "server.key", "-passin", "pass:$passphrase" ) != 0 ) {
exit 1;
}
- logger( "The pass phrase has been removed from the server key", "info" );
+ InstallUtils::logger( "The pass phrase has been removed from the server key", "info" );
if ( execOpenssl( "Generating a Self-signed certificate", "x509", "-req", "-days", "365", "-in", "server.csr", "-signkey", "server.key", "-out", "server.crt" ) != 0 ) {
exit 1;
}
- logger( "A server key and self signed certificate has been generated", "info" );
+ InstallUtils::logger( "A server key and self signed certificate has been generated", "info" );
- logger( "Installing the server key and server certificate", "info" );
+ InstallUtils::logger( "Installing the server key and server certificate", "info" );
my $result = InstallUtils::execCommand( "/bin/cp", "server.key", "$key" );
if ( $result != 0 ) {
@@ -185,8 +185,8 @@ sub createCert {
errorOut("Failed to install the private server key");
}
- logger( "The private key has been installed", "info" );
- logger( "Installing the self signed certificate", "info" );
+ InstallUtils::logger( "The private key has been installed", "info" );
+ InstallUtils::logger( "Installing the self signed certificate", "info" );
$result = InstallUtils::execCommand( "/bin/cp", "server.crt", "$cert" );
@@ -201,7 +201,7 @@ sub createCert {
errorOut("Failed to install the self signed certificate");
}
- logger( "Saving the self signed csr", "info" );
+ InstallUtils::logger( "Saving the self signed csr", "info" );
$result = InstallUtils::execCommand( "/bin/cp", "server.csr", "$csr" );
if ( $result != 0 ) {
@@ -223,7 +223,7 @@ sub createCert {
EOF
- logger( $msg, "info" );
+ InstallUtils::logger( $msg, "info" );
return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/230aa7c0/traffic_ops/install/lib/InstallUtils.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/InstallUtils.pm b/traffic_ops/install/lib/InstallUtils.pm
index a4f0266..555ba84 100644
--- a/traffic_ops/install/lib/InstallUtils.pm
+++ b/traffic_ops/install/lib/InstallUtils.pm
@@ -41,6 +41,14 @@ use base qw{ Exporter };
our @EXPORT_OK = qw{ execCommand randomWord promptUser promptRequired promptPassword promptPasswordVerify trim readJson writeJson writePerl errorOut logger rotateLog};
our %EXPORT_TAGS = ( all => \@EXPORT_OK );
+my $logFile;
+my $debug;
+
+sub initLogger {
+ $debug = shift;
+ $logFile = shift;
+}
+
sub execCommand {
my ( $command, @args ) = @_;
@@ -94,7 +102,7 @@ sub rotateLog {
my $logFileName = shift;
if ( !-f $logFileName ) {
- logger( "Log file '$logFileName' does not exist - not rotating log", "error" );
+ logger( "Log file '$logFileName' does not exist - not rotating log", "warn" );
return;
}
@@ -117,7 +125,7 @@ sub logger {
}
# if in debug mode or message is more critical than info print to console
- if ( $::debug || ( defined $type && $type ne "" && $type ne "info" ) ) {
+ if ( $debug || ( defined $type && $type ne "" && $type ne "info" ) ) {
print($message);
}
@@ -125,12 +133,12 @@ sub logger {
my $fh;
my $result = 0;
if ( defined $customLogFile && $customLogFile ne "" ) {
- open $fh, '>>', $customLogFile or die("Couldn't open log file '$::customLogFile'");
+ open $fh, '>>', $customLogFile or die("Couldn't open log file '$customLogFile'");
$result = 1;
}
else {
- if ($::logFile) {
- open $fh, '>>', $::logFile or die("Couldn't open log file '$::logFile'");
+ if ($logFile) {
+ open( $fh, '>>', $logFile ) or die("Couldn't open log file '$logFile'");
$result = 1;
}
}
@@ -233,6 +241,7 @@ sub readJson {
sub writeJson {
my $file = shift;
open( my $fh, '>', $file ) or die("open(): $!");
+ logger("Writing json to $file", "info");
foreach my $data (@_) {
my $json_text = JSON->new->utf8->pretty->encode($data);
print $fh $json_text, "\n";
@@ -251,3 +260,5 @@ sub writePerl {
print $fh $dumper->Terse(1)->Dump();
close $fh;
}
+
+1;
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/230aa7c0/traffic_ops/install/lib/ProfileCleanup.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/ProfileCleanup.pm b/traffic_ops/install/lib/ProfileCleanup.pm
index 3f7ce4a..4885a11 100644
--- a/traffic_ops/install/lib/ProfileCleanup.pm
+++ b/traffic_ops/install/lib/ProfileCleanup.pm
@@ -16,40 +16,46 @@
package ProfileCleanup;
+use warnings;
+use strict;
+
use InstallUtils qw{ :all };
use WWW::Curl::Easy;
use LWP::UserAgent;
use base qw{ Exporter };
-our @EXPORT_OK = qw{ replace_profile_templates import_profiles profiles_exist };
+our @EXPORT_OK = qw{ replace_profile_templates import_profiles profiles_exist add_custom_profiles };
our %EXPORT_TAGS = ( all => \@EXPORT_OK );
sub profile_replace {
- my ($profile) = @_;
+ my $profile = shift;
+ my $adminconf = shift;
+ my $parameters = shift;
+
my $profile_bak = $profile . ".bak";
- logger("Replacing parameters in profile: $profile", "info");
+ InstallUtils::logger( "Replacing parameters in profile: $profile", "info" );
rename( $profile, $profile_bak ) or die("rename(): $!");
open( my $fh, '<', $profile_bak ) or die("open(): $!");
open( my $ofh, '>', $profile ) or die("open(): $!");
while (<$fh>) {
- s/{{.TmUrl}}/$::parameters->{'tm.url'}/g;
- s/{{.TmInfoUrl}}/$::parameters->{"tminfo.url"}/g;
- s/{{.TmInstanceName}}/$::parameters->{"cdnname"}/g;
- s/{{.GeolocationPollingUrl}}/$::parameters->{"geolocation.polling.url"}/g;
- s/{{.Geolocation6PollingUrl}}/$::parameters->{"geolocation6.polling.url"}/g;
- s/{{.TmUrl}}/$::parameters->{'tm.url'}/g;
+ s/{{.TmUrl}}/$parameters->{'tm.url'}/g;
+ s/{{.TmInfoUrl}}/$parameters->{"tminfo.url"}/g;
+ s/{{.TmInstanceName}}/$parameters->{"cdnname"}/g;
+ s/{{.GeolocationPollingUrl}}/$parameters->{"geolocation.polling.url"}/g;
+ s/{{.Geolocation6PollingUrl}}/$parameters->{"geolocation6.polling.url"}/g;
+ s/{{.TmUrl}}/$parameters->{'tm.url'}/g;
s/{{.TmToolName}}/Traffic Ops/g;
- s/{{.HealthPollingInterval}}/$::parameters->{"health.polling.interval"}/g;
- s/{{.CoveragezonePollingUrl}}/$::parameters->{"coveragezone.polling.url"}/g;
- s/{{.DomainName}}/$::parameters->{"domainname"}/g;
- s/{{.TldSoaAdmin}}/$::parameters->{"tld.soa.admin"}/g;
- s/{{.DrivePrefix}}/$::parameters->{"Drive_Prefix"}/g;
- s/{{.HealthThresholdLoadavg}}/$::parameters->{"health.threshold.loadavg"}/g;
- s/{{.HealthThresholdAvailableBandwidthInKbps}}/$::parameters->{"health.threshold.availableBandwidthInKbps"}/g;
- s/{{.RAMDrivePrefix}}/$::parameters->{"RAM_Drive_Prefix"}/g;
- s/{{.RAMDriveLetters}}/$::parameters->{"RAM_Drive_Letters"}/g;
- s/{{.HealthConnectionTimeout}}/$::parameters->{"health.connection.timeout"}/g;
- s#{{.CronOrtSyncds}}#*/15 * * * * root /opt/ort/traffic_ops_ort.pl syncds warn $::parameters->{'tm.url'} $tmAdminUser:$tmAdminPw > /tmp/ort/syncds.log 2>&1#g;
+ s/{{.HealthPollingInterval}}/$parameters->{"health.polling.interval"}/g;
+ s/{{.CoveragezonePollingUrl}}/$parameters->{"coveragezone.polling.url"}/g;
+ s/{{.DomainName}}/$parameters->{"domainname"}/g;
+ s/{{.TldSoaAdmin}}/$parameters->{"tld.soa.admin"}/g;
+ s/{{.DrivePrefix}}/$parameters->{"Drive_Prefix"}/g;
+ s/{{.HealthThresholdLoadavg}}/$parameters->{"health.threshold.loadavg"}/g;
+ s/{{.HealthThresholdAvailableBandwidthInKbps}}/$parameters->{"health.threshold.availableBandwidthInKbps"}/g;
+ s/{{.RAMDrivePrefix}}/$parameters->{"RAM_Drive_Prefix"}/g;
+ s/{{.RAMDriveLetters}}/$parameters->{"RAM_Drive_Letters"}/g;
+ s/{{.HealthConnectionTimeout}}/$parameters->{"health.connection.timeout"}/g;
+ s#{{.CronOrtSyncds}}#*/15 * * * * root /opt/ort/traffic_ops_ort.pl syncds warn $parameters->{'tm.url'} $adminconf->{tmAdminUser}:$adminconf->{tmAdminPw} > /tmp/ort/syncds.log 2>&1#g;
print $ofh $_;
}
close $fh;
@@ -58,30 +64,34 @@ sub profile_replace {
}
sub replace_profile_templates {
- my $conf = shift;
-
- $::parameters->{'tm.url'} = $conf->{"tm.url"};
- $::parameters->{"tminfo.url"} = "$::parameters->{'tm.url'}/info";
- $::parameters->{"cdnname"} = $conf->{"cdn_name"};
- $::parameters->{"geolocation.polling.url"} = "$::parameters->{'tm.url'}/routing/GeoIP2-City.mmdb.gz";
- $::parameters->{"geolocation6.polling.url"} = "$::parameters->{'tm.url'}/routing/GeoIP2-Cityv6.mmdb.gz";
- $::parameters->{"health.polling.interval"} = $conf->{"health_polling_int"};
- $::parameters->{"coveragezone.polling.url"} = "$::parameters->{'tm.url'}/routing/coverage-zone.json";
- $::parameters->{"domainname"} = $conf->{"dns_subdomain"};
- $::parameters->{"tld.soa.admin"} = $conf->{"soa_admin"};
- $::parameters->{"Drive_Prefix"} = $conf->{"driver_prefix"};
- $::parameters->{"RAM_Drive_Prefix"} = $conf->{"ram_drive_prefix"};
- $::parameters->{"RAM_Drive_Letters"} = $conf->{"ram_drive_letters"};
- $::parameters->{"health.threshold.loadavg"} = $conf->{"health_thresh_load_avg"};
- $::parameters->{"health.threshold.availableBandwidthInKbps"} = $conf->{"health_thresh_kbps"};
- $::parameters->{"health.connection.timeout"} = $conf->{"health_connect_timeout"};
-
- profile_replace( $::profile_dir . "profile.global.traffic_ops" );
- profile_replace( $::profile_dir . "profile.traffic_monitor.traffic_ops" );
- profile_replace( $::profile_dir . "profile.traffic_router.traffic_ops" );
- profile_replace( $::profile_dir . "profile.trafficserver_edge.traffic_ops" );
- profile_replace( $::profile_dir . "profile.trafficserver_mid.traffic_ops" );
- writeJson( $::post_install_cfg, $::parameters );
+ my $conf = shift;
+ my $adminconf = shift;
+ my $post_install_cfg = shift;
+ my $parameters = shift;
+ my $profileDir = shift;
+
+ $parameters->{'tm.url'} = $conf->{"tm.url"};
+ $parameters->{"tminfo.url"} = "$parameters->{'tm.url'}/info";
+ $parameters->{"cdnname"} = $conf->{"cdn_name"};
+ $parameters->{"geolocation.polling.url"} = "$parameters->{'tm.url'}/routing/GeoIP2-City.mmdb.gz";
+ $parameters->{"geolocation6.polling.url"} = "$parameters->{'tm.url'}/routing/GeoIP2-Cityv6.mmdb.gz";
+ $parameters->{"health.polling.interval"} = $conf->{"health_polling_int"};
+ $parameters->{"coveragezone.polling.url"} = "$parameters->{'tm.url'}/routing/coverage-zone.json";
+ $parameters->{"domainname"} = $conf->{"dns_subdomain"};
+ $parameters->{"tld.soa.admin"} = $conf->{"soa_admin"};
+ $parameters->{"Drive_Prefix"} = $conf->{"driver_prefix"};
+ $parameters->{"RAM_Drive_Prefix"} = $conf->{"ram_drive_prefix"};
+ $parameters->{"RAM_Drive_Letters"} = $conf->{"ram_drive_letters"};
+ $parameters->{"health.threshold.loadavg"} = $conf->{"health_thresh_load_avg"};
+ $parameters->{"health.threshold.availableBandwidthInKbps"} = substr( $conf->{"health_thresh_kbps"}, 0, 1 ) eq ">" ? "" : ">" . $conf->{"health_thresh_kbps"};
+ $parameters->{"health.connection.timeout"} = $conf->{"health_connect_timeout"};
+
+ profile_replace( $profileDir . "profile.global.traffic_ops", $adminconf, $parameters );
+ profile_replace( $profileDir . "profile.traffic_monitor.traffic_ops", $adminconf, $parameters );
+ profile_replace( $profileDir . "profile.traffic_router.traffic_ops", $adminconf, $parameters );
+ profile_replace( $profileDir . "profile.trafficserver_edge.traffic_ops", $adminconf, $parameters );
+ profile_replace( $profileDir . "profile.trafficserver_mid.traffic_ops", $adminconf, $parameters );
+ writeJson( $post_install_cfg, $parameters );
}
# Takes the Traffic Ops URI, user, and password.
@@ -117,54 +127,59 @@ sub get_traffic_ops_cookie {
# Takes the filename of a Traffic Ops (TO) profile to import, the TO URI, and the TO login cookie
sub profile_import_single {
my ( $profileFilename, $uri, $trafficOpsCookie ) = @_;
- logger( "Importing Profiles with: " . "curl -v -k -X POST -H \"Cookie: mojolicious=$trafficOpsCookie\" -F \"filename=$profileFilename\" -F \"profile_to_import=\@$profileFilename\" $uri/profile/doImport", "info" );
- my $rc = execCommand("curl -v -k -X POST -H \"Cookie: mojolicious=$trafficOpsCookie\" -F \"filename=$profileFilename\" -F \"profile_to_import=\@$profileFilename\" $uri/profile/doImport");
+ InstallUtils::logger( "Importing Profiles with: " . "curl -v -k -X POST -H \"Cookie: mojolicious=$trafficOpsCookie\" -F \"filename=$profileFilename\" -F \"profile_to_import=\@$profileFilename\" $uri/profile/doImport", "info" );
+ my $rc = InstallUtils::execCommand("curl -v -k -X POST -H \"Cookie: mojolicious=$trafficOpsCookie\" -F \"filename=$profileFilename\" -F \"profile_to_import=\@$profileFilename\" $uri/profile/doImport");
if ( $rc != 0 ) {
- logger( "Failed to import Traffic Ops profile, check the console output and rerun postinstall once you've resolved the error", "error" );
+ InstallUtils::logger( "Failed to import Traffic Ops profile, check the console output and rerun postinstall once you've resolved the error", "error" );
}
}
sub import_profiles {
- my $config = shift;
- logger( "Importing profiles...", "info" );
+ my $toUri = shift;
+ my $adminconf = shift;
+ my $profileDir = shift;
- my $toUri = $::parameters->{'tm.url'};
- my $toUser = $config->{"username"};
- my $toPass = $config->{"password"};
+ InstallUtils::logger( "Importing profiles...", "info" );
+
+ my $toUser = $adminconf->{"username"};
+ my $toPass = $adminconf->{"password"};
my $toCookie = get_traffic_ops_cookie( $toUri, $toUser, $toPass );
- logger( "Got cookie: " . $toCookie, "info" );
+ InstallUtils::logger( "Got cookie: " . $toCookie, "info" );
# \todo use an array?
- logger( "Importing Global profile...", "info" );
- profile_import_single( $::profile_dir . "profile.global.traffic_ops", $toUri, $toCookie );
- logger( "Importing Traffic Monitor profile...", "info" );
- profile_import_single( $::profile_dir . "profile.traffic_monitor.traffic_ops", $toUri, $toCookie );
- logger( "Importing Traffic Router profile...", "info" );
- profile_import_single( $::profile_dir . "profile.traffic_router.traffic_ops", $toUri, $toCookie );
- logger( "Importing TrafficServer Edge profile...", "info" );
- profile_import_single( $::profile_dir . "profile.trafficserver_edge.traffic_ops", $toUri, $toCookie );
- logger( "Importing TrafficServer Mid profile...", "info" );
- profile_import_single( $::profile_dir . "profile.trafficserver_mid.traffic_ops", $toUri, $toCookie );
- logger( "Finished Importing Profiles.", "info" );
+ InstallUtils::logger( "Importing Global profile...", "info" );
+ profile_import_single( $profileDir . "profile.global.traffic_ops", $toUri, $toCookie );
+ InstallUtils::logger( "Importing Traffic Monitor profile...", "info" );
+ profile_import_single( $profileDir . "profile.traffic_monitor.traffic_ops", $toUri, $toCookie );
+ InstallUtils::logger( "Importing Traffic Router profile...", "info" );
+ profile_import_single( $profileDir . "profile.traffic_router.traffic_ops", $toUri, $toCookie );
+ InstallUtils::logger( "Importing TrafficServer Edge profile...", "info" );
+ profile_import_single( $profileDir . "profile.trafficserver_edge.traffic_ops", $toUri, $toCookie );
+ InstallUtils::logger( "Importing TrafficServer Mid profile...", "info" );
+ profile_import_single( $profileDir . "profile.trafficserver_mid.traffic_ops", $toUri, $toCookie );
+ InstallUtils::logger( "Finished Importing Profiles.", "info" );
}
sub profiles_exist {
- my $config = shift;
- my $tmurl = shift;
-
- if ( -f $::reconfigure_defaults ) {
- logger( "Default profiles were previously created. Remove " . $::reconfigure_defaults . " to create again", "warn" );
+ my $config = shift;
+ my $tmurl = shift;
+ my $parameters = shift;
+ my $reconfigure_defaults = shift;
+ my $reconfigure = shift;
+
+ if ( -f $reconfigure_defaults ) {
+ InstallUtils::logger( "Default profiles were previously created. Remove " . $reconfigure_defaults . " to create again", "warn" );
return 1;
}
- $::parameters->{'tm.url'} = $tmurl;
+ $parameters->{'tm.url'} = $tmurl;
- logger( "Checking profiles at $tmurl using username " . $config->{"username"}, "info" );
+ InstallUtils::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"} );
+ my $uri = $parameters->{'tm.url'};
+ my $toCookie = get_traffic_ops_cookie( $parameters->{'tm.url'}, $config->{"username"}, $config->{"password"} );
my $profileEndpoint = "/api/1.2/profiles.json";
@@ -175,7 +190,7 @@ sub profiles_exist {
my $resp = $ua->request($req);
if ( !$resp->is_success ) {
- logger( "Error checking if profiles exist: " . $resp->status_line, "error" );
+ InstallUtils::logger( "Error checking if profiles exist: " . $resp->status_line, "error" );
return 1; # return true, so we don't attempt to create profiles
}
my $message = $resp->decoded_content;
@@ -184,12 +199,12 @@ sub profiles_exist {
if ( ( !defined $profiles->{"response"} )
|| ( ref $profiles->{"response"} ne 'ARRAY' ) )
{
- logger( "Error checking if profiles exist: invalid JSON: $message", "error" );
+ InstallUtils::logger( "Error checking if profiles exist: invalid JSON: $message", "error" );
return 1; # return true, so we don't attempt to create profiles
}
my $num_profiles = scalar( @{ $profiles->{"response"} } );
- logger( "Existing Profile Count: $num_profiles", "info" );
+ InstallUtils::logger( "Existing Profile Count: $num_profiles", "info" );
my %initial_profiles = (
"INFLUXDB" => 1,
@@ -200,11 +215,37 @@ sub profiles_exist {
my $profiles_response = $profiles->{"response"};
foreach my $profile (@$profiles_response) {
if ( !exists $initial_profiles{ $profile->{"name"} } ) {
- logger( "Found existing profile (" . $profile->{"name"} . ")", "info" );
- open( my $reconfigure_defaults_file, '>', $::reconfigure_defaults ) or die("Failed to open() $reconfigure_defaults: $!");
- close($reconfigure_defaults_file);
+ InstallUtils::logger( "Found existing profile (" . $profile->{"name"} . ")", "info" );
+ open( my $reconfigure_defaults, '>', $reconfigure ) or die("Failed to open() $reconfigure_defaults: $!");
+ close($reconfigure_defaults);
return 1;
}
}
return 0;
}
+
+sub add_custom_profiles {
+ my $custom_profile_dir = shift;
+ my $adminconf = shift;
+ my $toUri = shift;
+
+ return if (! -e $custom_profile_dir );
+
+ opendir(DH, $custom_profile_dir) || return;
+ my @profiles = readdir(DH);
+ closedir(DH);
+ @profiles = grep(/^profile\..*\.traffic_ops$/, @profiles);
+
+ return if (scalar @profiles == 0);
+
+ my $toUser = $adminconf->{tmAdminUser};
+ my $toPass = $adminconf->{tmAdminPw};
+ my $toCookie = get_traffic_ops_cookie($toUri, $toUser, $toPass);
+
+ foreach my $profile (@profiles) {
+ print "\nimport profile ". $custom_profile_dir . $profile . "\n\n";
+ profile_import_single($custom_profile_dir . $profile, $toUri, $toCookie);
+ }
+}
+
+1;
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/230aa7c0/traffic_ops/install/lib/WebDep.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/WebDep.pm b/traffic_ops/install/lib/WebDep.pm
index e7db9b6..edf25fb 100644
--- a/traffic_ops/install/lib/WebDep.pm
+++ b/traffic_ops/install/lib/WebDep.pm
@@ -1,6 +1,7 @@
package WebDep;
#
+# Copyright 2015 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -30,205 +31,205 @@ my @columns = qw{name version cdn_location compression filename source_dir final
# class method returns list of WebDep objects loaded from file
sub getDeps {
- my $class = shift;
-
- my $webdeps_file = shift;
- my @deps;
- open my $fh, '<', $webdeps_file or die "Can't open $webdeps_file\n";
-
- # final_dir within webdeps_file are absolute or relative to directory that file is in
- my $oldcwd = getcwd();
- my $webdeps_dir = dirname($webdeps_file);
- chdir($webdeps_dir);
- while (<$fh>) {
-
- # comments only if line starts with #
- next if /^#/;
- chomp;
- my @parts = split( /\s*,\s*/, $_ );
- my $obj = bless {}, $class;
- for my $attrib (@columns) {
- $obj->{$attrib} = shift @parts;
- }
- $obj->{filename} =~ s{^/}{};
- $obj->{source_dir} =~ s{/$}{};
- $obj->{source_dir} =~ s{/$}{};
-
- my $final_dir = $obj->{final_dir};
- if ( !-d $final_dir ) {
- print "Making dir: $final_dir\n";
- mkpath($final_dir);
- }
- $obj->{final_dir} = abs_path($final_dir);
- push( @deps, $obj );
- }
- chdir($oldcwd);
- return @deps;
+ my $class = shift;
+
+ my $webdeps_file = shift;
+ my @deps;
+ open my $fh, '<', $webdeps_file or die "Can't open $webdeps_file\n";
+
+ # final_dir within webdeps_file are absolute or relative to directory that file is in
+ my $oldcwd = getcwd();
+ my $webdeps_dir = dirname($webdeps_file);
+ chdir($webdeps_dir);
+ while (<$fh>) {
+
+ # comments only if line starts with #
+ next if /^#/;
+ chomp;
+ my @parts = split( /\s*,\s*/, $_ );
+ my $obj = bless {}, $class;
+ for my $attrib (@columns) {
+ $obj->{$attrib} = shift @parts;
+ }
+ $obj->{filename} =~ s{^/}{};
+ $obj->{source_dir} =~ s{/$}{};
+ $obj->{source_dir} =~ s{/$}{};
+
+ my $final_dir = $obj->{final_dir};
+ if ( !-d $final_dir ) {
+ print "Making dir: $final_dir\n";
+ mkpath($final_dir);
+ }
+ $obj->{final_dir} = abs_path($final_dir);
+ push( @deps, $obj );
+ }
+ chdir($oldcwd);
+ return @deps;
}
sub getSrcFileName {
- my $self = shift;
- my @parts;
- push @parts, $self->{source_dir} if $self->{source_dir} ne '';
- push @parts, $self->{filename};
- return join( '/', @parts );
+ my $self = shift;
+ my @parts;
+ push @parts, $self->{source_dir} if $self->{source_dir} ne '';
+ push @parts, $self->{filename};
+ return join( '/', @parts );
}
sub getDestFileName {
- my $self = shift;
- return join( '/', $self->{final_dir}, $self->{filename} );
+ my $self = shift;
+ return join( '/', $self->{final_dir}, $self->{filename} );
}
sub getDownloadContent {
- my $self = shift;
- my ( $response_body, $err ) = _getDownloadContent( $self->{cdn_location} );
- return ( $response_body, $err );
+ my $self = shift;
+ my ( $response_body, $err ) = _getDownloadContent( $self->{cdn_location} );
+ return ( $response_body, $err );
}
sub getContent {
- my $self = shift;
- my ( $content, $err ) = $self->getDownloadContent();
- if ( defined $err ) {
- die "$err\n";
- }
- my $srcfn = $self->getSrcFileName();
- if ( !exists $self->{content} ) {
- if ( $self->{compression} eq 'zip' ) {
-
- #print "Unzipping $srcfn\n";
- my $u = IO::Uncompress::Unzip->new( \$content ) or die "IO::Uncompress::Unzip failed: $UnzipError\n";
- my $found;
- while ( $u->nextStream() > 0 && !$u->eof() ) {
- my $name = $u->getHeaderInfo()->{Name};
- if ( $name eq $srcfn ) {
- $found = $name;
- last;
- }
- }
- if ( !defined $found ) {
- die "$srcfn not found in " . $self->{cdn_location} . "\n";
- }
-
- undef $/; # slurp mode
- $content = <$u>;
- $u->close();
- }
-
- $self->{content} = $content;
- }
- return $self->{content};
+ my $self = shift;
+ my ( $content, $err ) = $self->getDownloadContent();
+ if ( defined $err ) {
+ die "$err\n";
+ }
+ my $srcfn = $self->getSrcFileName();
+ if ( !exists $self->{content} ) {
+ if ( $self->{compression} eq 'zip' ) {
+
+ #print "Unzipping $srcfn\n";
+ my $u = IO::Uncompress::Unzip->new( \$content ) or die "IO::Uncompress::Unzip failed: $UnzipError\n";
+ my $found;
+ while ( $u->nextStream() > 0 && !$u->eof() ) {
+ my $name = $u->getHeaderInfo()->{Name};
+ if ( $name eq $srcfn ) {
+ $found = $name;
+ last;
+ }
+ }
+ if ( !defined $found ) {
+ die "$srcfn not found in " . $self->{cdn_location} . "\n";
+ }
+
+ undef $/; # slurp mode
+ $content = <$u>;
+ $u->close();
+ }
+
+ $self->{content} = $content;
+ }
+ return $self->{content};
}
sub needsUpdating {
- my $self = shift;
- my $fn = $self->getDestFileName();
+ my $self = shift;
+ my $fn = $self->getDestFileName();
- # checksum and compare
- open my $fh, '<', $fn or die "Can't open existing file: $fn\n";
- my $md5_existing = md5_hex(<$fh>);
- close $fh;
+ # checksum and compare
+ open my $fh, '<', $fn or die "Can't open existing file: $fn\n";
+ my $md5_existing = md5_hex(<$fh>);
+ close $fh;
- my $md5_new = md5_hex( $self->getContent() );
- my $needsUpdating = ( $md5_new ne $md5_existing );
- return $needsUpdating;
+ my $md5_new = md5_hex( $self->getContent() );
+ my $needsUpdating = ( $md5_new ne $md5_existing );
+ return $needsUpdating;
}
sub update {
- my $self = shift;
- my $err;
- my $srcfn = $self->getSrcFileName();
- my $destfn = $self->getDestFileName();
- my $action = "";
-
- # download archive
- if ( -f $destfn ) {
- if ( !$self->needsUpdating() ) {
- $action = "Kept";
- return ( $action, $err );
- }
-
- # exists but needs to be replaced
- $action = "Replaced";
- }
- else {
- $action = "Created";
- }
- my $content = $self->getContent();
- open my $ofh, '>', $destfn or $err = "Can't write to $destfn";
- if ( !defined $err ) {
- print $ofh $content;
- close $ofh;
- }
- return ( $action, $err );
+ my $self = shift;
+ my $err;
+ my $srcfn = $self->getSrcFileName();
+ my $destfn = $self->getDestFileName();
+ my $action = "";
+
+ # download archive
+ if ( -f $destfn ) {
+ if ( !$self->needsUpdating() ) {
+ $action = "Kept";
+ return ( $action, $err );
+ }
+
+ # exists but needs to be replaced
+ $action = "Replaced";
+ }
+ else {
+ $action = "Created";
+ }
+ my $content = $self->getContent();
+ open my $ofh, '>', $destfn or $err = "Can't write to $destfn";
+ if ( !defined $err ) {
+ print $ofh $content;
+ close $ofh;
+ }
+ return ( $action, $err );
}
####################################################################
# Utilities
sub execCommand {
- my ( $command, @args ) = @_;
- my $pid = fork();
- my $result = 0;
-
- if ( $pid == 0 ) {
- exec( $command, @args );
- exit 0;
- }
- else {
- wait;
- $result = $?;
- if ( $result != 0 ) {
- print "ERROR executing: $command, args: " . join( ' ', @args ) . "\n";
- }
- }
- return $result;
+ my ( $command, @args ) = @_;
+ my $pid = fork();
+ my $result = 0;
+
+ if ( $pid == 0 ) {
+ exec( $command, @args );
+ exit 0;
+ }
+ else {
+ wait;
+ $result = $?;
+ if ( $result != 0 ) {
+ print "ERROR executing: $command, args: " . join( ' ', @args ) . "\n";
+ }
+ }
+ return $result;
}
sub curlMe {
- my $url = shift;
- my $curl = WWW::Curl::Easy->new;
- my $response_body;
- my $err; # undef if no error
-
- $curl->setopt( CURLOPT_VERBOSE, 0 );
- if ( $url =~ m/https/ ) {
- $curl->setopt( CURLOPT_SSL_VERIFYHOST, 0 );
- $curl->setopt( CURLOPT_SSL_VERIFYPEER, 0 );
- }
- $curl->setopt( CURLOPT_IPRESOLVE, 1 );
- $curl->setopt( CURLOPT_FOLLOWLOCATION, 1 );
- $curl->setopt( CURLOPT_CONNECTTIMEOUT, 5 );
- $curl->setopt( CURLOPT_TIMEOUT, 15 );
- $curl->setopt( CURLOPT_HEADER, 0 );
- $curl->setopt( CURLOPT_URL, $url );
- $curl->setopt( CURLOPT_WRITEDATA, \$response_body );
- my $retcode = $curl->perform;
- my $response_code = $curl->getinfo(CURLINFO_HTTP_CODE);
-
- if ( $response_code != 200 ) {
- $err = "Got HTTP $response_code response for '$url'";
- }
- elsif ( length($response_body) == 0 ) {
- $err = "URL: $url returned empty!!";
- }
- return ( $response_body, $err );
+ my $url = shift;
+ my $curl = WWW::Curl::Easy->new;
+ my $response_body;
+ my $err; # undef if no error
+
+ $curl->setopt( CURLOPT_VERBOSE, 0 );
+ if ( $url =~ m/https/ ) {
+ $curl->setopt( CURLOPT_SSL_VERIFYHOST, 0 );
+ $curl->setopt( CURLOPT_SSL_VERIFYPEER, 0 );
+ }
+ $curl->setopt( CURLOPT_IPRESOLVE, 1 );
+ $curl->setopt( CURLOPT_FOLLOWLOCATION, 1 );
+ $curl->setopt( CURLOPT_CONNECTTIMEOUT, 5 );
+ $curl->setopt( CURLOPT_TIMEOUT, 15 );
+ $curl->setopt( CURLOPT_HEADER, 0 );
+ $curl->setopt( CURLOPT_URL, $url );
+ $curl->setopt( CURLOPT_WRITEDATA, \$response_body );
+ my $retcode = $curl->perform;
+ my $response_code = $curl->getinfo(CURLINFO_HTTP_CODE);
+
+ if ( $response_code != 200 ) {
+ $err = "Got HTTP $response_code response for '$url'";
+ }
+ elsif ( length($response_body) == 0 ) {
+ $err = "URL: $url returned empty!!";
+ }
+ return ( $response_body, $err );
}
{
- # cache cdn locs -- some files extracted from same downloaded archive
- my %content_for;
-
- sub _getDownloadContent {
- my $cdnloc = shift;
- my $err;
- if ( !exists $content_for{$cdnloc} ) {
- my $response_body;
- ( $response_body, $err ) = curlMe($cdnloc);
- $content_for{$cdnloc} = $response_body;
- }
-
- # could be undef indicating previous error
- return ( $content_for{$cdnloc}, $err );
- }
+ # cache cdn locs -- some files extracted from same downloaded archive
+ my %content_for;
+
+ sub _getDownloadContent {
+ my $cdnloc = shift;
+ my $err;
+ if ( !exists $content_for{$cdnloc} ) {
+ my $response_body;
+ ( $response_body, $err ) = curlMe($cdnloc);
+ $content_for{$cdnloc} = $response_body;
+ }
+
+ # could be undef indicating previous error
+ return ( $content_for{$cdnloc}, $err );
+ }
}
1;
[16/36] incubator-trafficcontrol git commit: Removed comcast
copyright line
Posted by da...@apache.org.
Removed comcast copyright line
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/0ab8be76
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/0ab8be76
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/0ab8be76
Branch: refs/heads/master
Commit: 0ab8be76f6934fd4a8961d3425647dc19df219f8
Parents: c265743
Author: peryder <pe...@cisco.com>
Authored: Fri Dec 2 14:28:25 2016 -0500
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Jan 27 09:52:53 2017 -0700
----------------------------------------------------------------------
traffic_ops/install/lib/BuildPerlDeps.pm | 2 --
traffic_ops/install/lib/GenerateCert.pm | 2 --
2 files changed, 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0ab8be76/traffic_ops/install/lib/BuildPerlDeps.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/BuildPerlDeps.pm b/traffic_ops/install/lib/BuildPerlDeps.pm
index 302d5c3..b3126bc 100644
--- a/traffic_ops/install/lib/BuildPerlDeps.pm
+++ b/traffic_ops/install/lib/BuildPerlDeps.pm
@@ -1,7 +1,5 @@
#!/usr/bin/perl
#
-# Copyright 2015 Comcast Cable Communications Management, LLC
-#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0ab8be76/traffic_ops/install/lib/GenerateCert.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/install/lib/GenerateCert.pm b/traffic_ops/install/lib/GenerateCert.pm
index efdcc96..0d4a458 100644
--- a/traffic_ops/install/lib/GenerateCert.pm
+++ b/traffic_ops/install/lib/GenerateCert.pm
@@ -1,8 +1,6 @@
#!/usr/bin/perl
#
-# Copyright 2015 Comcast Cable Communications Management, LLC
-#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at