diff options
Diffstat (limited to 'pgaas/src/stage/opt/app/pgaas/etc/do-post-install-config')
-rw-r--r-- | pgaas/src/stage/opt/app/pgaas/etc/do-post-install-config | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/pgaas/src/stage/opt/app/pgaas/etc/do-post-install-config b/pgaas/src/stage/opt/app/pgaas/etc/do-post-install-config new file mode 100644 index 0000000..87689ef --- /dev/null +++ b/pgaas/src/stage/opt/app/pgaas/etc/do-post-install-config @@ -0,0 +1,157 @@ +#!/bin/bash +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this code 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. + +echo "================ $0 ================" +id +set -x + +die() +{ + echo "$@" 1>&2 + echo $0: "$@" + umask 022 + echo $0: "$@" >> /tmp/pgaas-failures + exit 1 +} + +[ -n "$CFGDIR" ] || die "CFGDIR is not set" +[ -n "$ONAP" ] || die "ONAP is not set" +[ -n "$NOTONAP" ] || die "NOTONAP is not set" + +if [ -d ${INSTALL_ROOT}/opt/app/postgresql-9.5.2 ] +then PGDIR=${INSTALL_ROOT}/opt/app/postgresql-9.5.2 +elif [ -d ${INSTALL_ROOT}/usr/lib/postgresql/9.6 ] +then PGDIR=${INSTALL_ROOT}/usr/lib/postgresql/9.6 +elif [ -d ${INSTALL_ROOT}/usr/lib/postgresql/9.5 ] +then PGDIR=${INSTALL_ROOT}/usr/lib/postgresql/9.5 +else die PostgreSQL bin directory not found +fi +export PGDIR +export DBROOT=/dbroot/pgdata/main +export PATH=$PATH:${INSTALL_ROOT}/opt/app/pgaas/bin + +$CFGDIR/etc/makecerts + +cat $CFGDIR/lib/profile.additions >> ~postgres/.profile + +# Determine which system is the master. +# For central, we look first in /var/config/DCAE/chef/*-postgres.conf. +# If we don't find that, we look at the pgnodes list and pick the first one. +# For edge, we ignore /var/config/DCAE/chef/*-postgres.conf and go directly to the pgnodes list. +# Each edge site has its own master. +clustertype=$( ${INSTALL_ROOT}/opt/app/cdf/bin/getpropvalue -n cluster ) +ismaster=no + +case $clustertype in + central ) + CONFDIR1=/var/config/DCAE/chef + CONFDIR2=/tmp + CONFCOUNT1=$(ls $CONFDIR1/*-postgres.conf 2>/dev/null | wc -l) + CONFCOUNT2=$(ls $CONFDIR2/*-postgres.conf 2>/dev/null | wc -l) + CONFCOUNTBOTH=$(ls $CONFDIR1/*-postgres.conf $CONFDIR2/*-postgres.conf 2>/dev/null | wc -l) + + if [ $CONFCOUNTBOTH -eq 0 ] + then + # not OpenDCAE/ONAP, but it's better if we STILL require a pgaas-postgres.conf file. + die "No xyz-postgres.conf files were found in $CONFDIR1 or $CONFDIR2" + # Alternatively, the following code MIGHT work: + # ismaster=yes + # PGNODES=$( ${INSTALL_ROOT}/opt/app/cdf/bin/getpropvalue -n pgnodes ) + # export MASTER=$( gen-repmgr-info -n "$PGNODES" -m ) + else + if [ $CONFCOUNT1 -eq 1 ] + then CONFDIR=$CONFDIR1 + elif [ $CONFCOUNT2 -eq 1 ] + then CONFDIR=$CONFDIR2 + else CONFDIR= + fi + if [ -n "$CONFDIR" ] + then # OpenDCAE/ONAP + # We need the value of master from xyz-postgres.conf + umask 077 + TMP=$(mktemp /tmp/tmp.pi1.XXXXXXXXXX) + trap 'rm -f $TMP' 0 1 2 3 15 + cat $CONFDIR/*-postgres.conf | + sed -e 's/ *: */="/' -e 's/[ ]*$/"/' -e 's/=""/="/' -e 's/""$/"/' > $TMP + . $TMP + case "$master" in + `hostname` | `hostname -f` ) ismaster=yes ;; + *?* ) ismaster=no ;; + '' ) die "master is not set in $CONF" ;; + esac + PGNODES=$( ${INSTALL_ROOT}/opt/app/cdf/bin/getpropvalue -n pgnodes ) + export MASTER=$( gen-repmgr-info -n "$PGNODES" -M "$master" ) + [ -n "$MASTER" ] || die "Cannot determine master system. $CONF has '$master' (from env.yaml), which cannot be found in pgnodes." + else + if [ $CONFCOUNT1 -gt 1 ] + then die "More than one postgres.conf was found in $CONFDIR1: $(ls $CONFDIR1/*-postgres.conf 2>&1)" + elif [ $CONFCOUNT2 -gt 1 ] + then die "More than one postgres.conf was found in $CONFDIR2: $(ls $CONFDIR2/*-postgres.conf 2>&1)" + fi + fi + fi + ;; + edge ) + host=$( hostname -f ) + PGNODES=$( ${INSTALL_ROOT}/opt/app/cdf/bin/getpropvalue -n pgnodes ) + export MASTER=$( gen-repmgr-info -n "$PGNODES" -C $host ) + case $MASTER in + '' ) die "Cannot determine master system. Does cdf.cfg have pgnodes= in it? Is $host listed as a site?" ;; + DEFAULT ) ismaster=yes MASTER=$host ;; + esac + ;; +esac + +ssh_and_cdf_okay=no + +if pgrep postgres +then pkill postgres +fi + +case $ismaster in + yes ) # master + $CFGDIR/etc/create-ssh-master && + $CFGDIR/etc/create-cdf-master && + ssh_and_cdf_okay=yes + ;; + + no ) # secondary + $CFGDIR/etc/create-ssh-secondary && + $CFGDIR/etc/create-cdf-secondary && + touch $CFGDIR/lib/ignore-database-reconfiguration # prevent dcae_admin_db.py from looking at json DB reconfigurations && + ssh_and_cdf_okay=yes + ;; +esac + +[ "$ssh_and_cdf_okay" = yes ] || die "Could not set up ssh or cdf" + +$CFGDIR/etc/common-db-tasks +# check if we have a database already +if [ ! -s $DBROOT/PG_VERSION ] +then + # need to create it + case $ismaster in + yes ) $CFGDIR/etc/create-db-master ;; + no ) $CFGDIR/etc/create-db-secondary ;; + esac +else + # need to update it + case $ismaster in + yes ) $CFGDIR/etc/update-db-master ;; + no ) + $CFGDIR/etc/create-db-secondary # use repmgr clone even if secondary previously existed + # $CFGDIR/etc/update-db-secondary + ;; + esac +fi |