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/04/11 21:43:46 UTC

[3/4] incubator-trafficcontrol git commit: [TC-228] postinstall and INSTALL.md updates

[TC-228] postinstall and INSTALL.md updates

INSTALL.md
- Changed manual installation approach for non-containered postgres

postinstall
- Set reconfigure to 1, always init database
- Set debug to 1, always output so the end user sees what is
     happening
- set the goose needed driver to "postgres" instead of "Pg"
- changed question default: "Database server root (admin) user"
     name from "root" to "postgres"
- set PGUSER and PGPASSWORD in env to login to the postgres
     superuser account
- update traffic_ops database table with the "admin" user name
     and password provided by user (after initdb)


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/f08a1c2a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/f08a1c2a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/f08a1c2a

Branch: refs/heads/master
Commit: f08a1c2a20266d67ed1a0c778180b6da99426096
Parents: 9e0e808
Author: Jeff Martin <ma...@gmail.com>
Authored: Tue Apr 11 15:06:55 2017 -0400
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Tue Apr 11 15:42:58 2017 -0600

----------------------------------------------------------------------
 traffic_ops/INSTALL.md              | 47 +++++++++++-------------------
 traffic_ops/install/bin/postinstall | 49 ++++++++++++++++++++++++--------
 2 files changed, 53 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/f08a1c2a/traffic_ops/INSTALL.md
----------------------------------------------------------------------
diff --git a/traffic_ops/INSTALL.md b/traffic_ops/INSTALL.md
index 4b41fb9..91f5921 100644
--- a/traffic_ops/INSTALL.md
+++ b/traffic_ops/INSTALL.md
@@ -21,7 +21,13 @@ Instructions are here: https://yum.postgresql.org/
 
 ### on the host:
 
-   $ sudo yum install postgresql96-server
+    $ sudo su -
+    # yum install postgresql96-server
+    $ su - postgres
+    $ /usr/pgsql-9.6/bin/initdb -A md5 -W #-W forces the user to provide a superuser (postgres) password
+    $ exit
+    # systemctl start postgresql-9.6
+    # systemctl status postgresql-9.6
 
 ### -or- in a container
 
@@ -67,9 +73,9 @@ Run migration from existing mysql-based `traffic_ops`
 
     $ sudo yum install traffic_ops
 
-## Install `go` and `gcc` (required for `goose` and some `Perl` modules)
+## Install `go` and `git` (required for `goose` and some `Perl` modules)
 
-    $ sudo yum install go gcc
+    $ sudo yum install git go
     
 ## Install Perl modules
 
@@ -85,40 +91,19 @@ We need to tell carton where it is so the `DBD::Pg` module is installed correctl
 
 ## Install goose
 
-    $ sudo GOPATH=/tmp GOBIN=/usr/local/bin go get bitbucket.org/liamstask/goose/cmd/goose
-
-
-## Modify `traffic_ops` configuration
-
-- `/opt/traffic_ops/app/db`
-   - `dbconf.yml` 
-      - modify "production" line to match user/pass from env file above
-- `/opt/traffic_ops/app/conf`
-   - `cdn.conf` 
-      - set workers to desired value (96 is far too high for dev environment -- 15 is suggested)
-      - change `to.base_url` to appropriate FQDN or IP address
-   - `ldap.conf`
-      - add ldap server credentials if needed
-   - `production/database.conf`
-      - modify to match user/pass from env file above
-   - `production/riak.conf`, `production/influxdb.conf`
-      - add appropriate user/password
-   - `production/log4perl.conf`
-      - if logging data needed,  change ERROR to DEBUG on first line
+    $ sudo GOPATH=/usr/local go get bitbucket.org/liamstask/goose/cmd/goose
 
-## Initialize the db
 
-    $ cd /opt/traffic_ops/app
-    $ PERL5LIB=$(pwd)/lib:$(pwd)/local/lib/perl5 db/admin.pl --env=production setup
-    
 ## Install any extensions needed
 
    - install in /opt/traffic_ops_extensions
    
 ## Install `openssl` certs (or use this to generate them)
 
-   - `sudo /opt/traffic_ops/install/bin/generateCert`
-   
-## Install web dependencies
+   $ sudo /opt/traffic_ops/install/bin/generateCert
 
-   - `sudo /opt/traffic_ops/install/bin/download_web_deps`
+## as the root user run postinstall
+    $ sudo su -
+    # export POSTGRES_HOME=/usr/pgsql-9.6
+    # export GOPATH=/usr/local
+    # /opt/traffic_ops/install/bin/postinstall

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/f08a1c2a/traffic_ops/install/bin/postinstall
----------------------------------------------------------------------
diff --git a/traffic_ops/install/bin/postinstall b/traffic_ops/install/bin/postinstall
index 024a659..eae17d6 100755
--- a/traffic_ops/install/bin/postinstall
+++ b/traffic_ops/install/bin/postinstall
@@ -59,13 +59,13 @@ 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 = 1;
 
 # log file for cpan output
 my $cpanLogFile = "/var/log/traffic_ops/cpan.log";
 
 # whether or not to reconfigure traffic ops
-my $reconfigure = 0;
+my $reconfigure = 1;
 
 # used to check for .reconfigure_defaults file for backwards compatability
 my $reconfigure_defaults = "/opt/traffic_ops/.reconfigure_defaults";
@@ -180,10 +180,16 @@ sub generateDbConf {
     # broken out into separate file/config area
     my %todbconf = getConfig( $userInput, $toDBFileName );
 
+    # Check if the Postgres db is used and set the driver to be "postgres"
+    my $dbDriver = $dbconf{type};
+    if ( $dbconf{type} eq "Pg" ) {
+        $dbDriver = "postgres";
+    }
+
     # 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: $dbconf{type}\n";
+    print $fh "    driver: $dbDriver\n";
     print $fh "    open: host=$dbconf{hostname} port=$dbconf{port} user=$dbconf{user} password=$dbconf{password} dbname=$dbconf{dbname} sslmode=disable\n";
     close $fh;
 
@@ -398,7 +404,7 @@ sub getDefaults {
         ],
         $dbConfFile => [
             {
-                "Database server root (admin) user" => "root",
+                "Database server root (admin) user" => "postgres",
                 "config_var"                        => "dbAdminUser"
             },
             {
@@ -552,26 +558,35 @@ sub getDefaults {
 # opensslconf: The openssl configuration if any
 
 sub setupDatabase {
-    my $todbconf     = shift;
-    my $opensslconf  = shift;
-    my $setupMaxmind = shift;
+    my $todbconf         = shift;
+    my $opensslconf      = shift;
+    my $setupMaxmind     = shift;
     my $databaseConfFile = shift;
 
-    my $dbconf = InstallUtils::readJson( $databaseConfFile );
+    my $dbconf = InstallUtils::readJson($databaseConfFile);
+
+    # Check if the Postgres db is used and set the admin database to be "postgres"
+    my $dbName = $dbconf{type};
+    if ( $dbconf{type} eq "Pg" ) {
+        $dbName = "postgres";
+    }
 
-    my $dsn = sprintf( "DBI:%s:dbname=%s", $dbconf->{"type"}, $dbconf->{"dbname"} );
+    my $dsn = sprintf( "DBI:%s:dbname=%s", $dbconf->{"type"}, $dbName );
     my $dbh = DBI->connect( $dsn, $todbconf->{"dbAdminUser"}, $todbconf->{"dbAdminPw"} );
     if ($dbh) {
-        InstallUtils::logger("Database connection succeeded", "info");
+        InstallUtils::logger( "Database connection succeeded", "info" );
+
         # Success!
         $dbh->disconnect();
     }
     else {
-        InstallUtils::logger("Error connecting to database", "error");
-        exit(-1)
+        InstallUtils::logger( "Error connecting to database", "error" );
+        exit(-1);
     }
 
     InstallUtils::logger( "Setting up database", "info" );
+    $ENV{PGUSER}     = $todbconf->{"dbAdminUser"};
+    $ENV{PGPASSWORD} = $todbconf->{"dbAdminPw"};
     chdir("/opt/traffic_ops/app");
     my $result = InstallUtils::execCommand( "/usr/bin/perl", "db/admin.pl", "--env=production", "setup" );
 
@@ -763,6 +778,16 @@ sub main {
     # if reconfigure is set then setup the database
     if ($reconfigure) {
         setupDatabase( $todbconf, $opensslconf, $todbconf->{"maxmind"}, $databaseConfFile );
+
+        ## Create the tm_user
+        my $dbconf      = InstallUtils::readJson($databaseConfFile);
+        my $dsn         = sprintf( "DBI:%s:dbname=%s", $dbconf->{"type"}, $dbconf->{"dbname"} );
+        my $dbh         = DBI->connect( $dsn, $todbconf->{"dbAdminUser"}, $todbconf->{"dbAdminPw"} );
+        my $sha1_passwd = sha1_hex( $adminconf->{"password"} );
+        my $sub_string  = sprintf( "('%s', 4, '%s')", $adminconf->{"username"}, $sha1_passwd, $sha1_passwd );
+
+        $dbh->do("insert into tm_user (username, role, local_passwd) values $sub_string");
+
     }
 
     InstallUtils::logger( "Starting Traffic Ops", "info" );