Commit fba24ada authored by iSergio's avatar iSergio
Browse files

Add pg pool host configuration

parent 7e3303aa
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ function recovery () {
    fi
    
    # Stop primary pgpool (is necessary!)
    su $PG_USER -c "ssh $PRIMARY_HOST 'pgpool -m fast stop'"
    su $PG_USER -c "ssh $PRIMARY_HOST 'pgpool -m fast stop && rm -rf /var/log/pgpool/*'"
    # Stop primary database (not necessary(check))
    su $PG_USER -c "ssh $PRIMARY_HOST 'pg_ctl stop -m fast -D $PG_DATA'"
    su $PG_USER -c "ssh $PRIMARY_HOST 'rm -rf $PG_WAL/*'"
+15 −8
Original line number Diff line number Diff line
@@ -22,10 +22,11 @@ PG_DATAS=()
PG_WALS=()
PG_CONFS=()
PG_HBAS=()
PG_POOLS=()

# For userfrendly function to fill arrays of parameters
function add_pg_host () {
    if [[ $# != 7 ]]; then
    if [[ $# != 8 ]]; then
        echo "Wrong function parameters count!"
        exit 1
    fi
@@ -36,11 +37,12 @@ function add_pg_host () {
    PG_WALS+=($5)
    PG_CONFS+=($6)
    PG_HBAS+=($7)
    PG_POOLS+=($8)
}

# Prepare hosts
add_pg_host "$PGSQL_PRIMARY_HOST" "5433" "postgres" "/var/lib/pgsql/data" "/var/lib/pgsql/backups" "/var/lib/pgsql/data/postgresql.conf" "/var/lib/pgsql/data/pg_hba.conf"
add_pg_host "$PGSQL_STANDBY_HOST" "5433" "postgres" "/var/lib/pgsql/data" "/var/lib/pgsql/backups" "/var/lib/pgsql/data/postgresql.conf" "/var/lib/pgsql/data/pg_hba.conf"
add_pg_host "$PGSQL_PRIMARY_HOST" "5433" "postgres" "/var/lib/pgsql/data" "/var/lib/pgsql/backups" "/var/lib/pgsql/data/postgresql.conf" "/var/lib/pgsql/data/pg_hba.conf" "$PGPOOL_PRIMARY_HOST"
add_pg_host "$PGSQL_STANDBY_HOST" "5433" "postgres" "/var/lib/pgsql/data" "/var/lib/pgsql/backups" "/var/lib/pgsql/data/postgresql.conf" "/var/lib/pgsql/data/pg_hba.conf" "$PGPOOL_STANDBY_HOST"

# Configure postgres users access via ssh by RSA keys
function exchange_rsa_keys () {
@@ -55,6 +57,7 @@ function exchange_rsa_keys () {
    for (( i = 1; i < ${#PG_HOSTS[*]}; i++ )); do
        PG_HOST=${PG_HOSTS[$i]}
        PG_USER=${PG_USERS[$i]}
        PG_POOL=${PG_POOLS[$i]}
        echo "Exchange keys ${PG_USERS[0]}@${PG_HOSTS[0]} <---> $PG_USER@$PG_HOST"
        # Configure slave
        su ${PG_USERS[0]} -c 'cat $HOME/master_rsa' | ssh $PG_USER@$PG_HOST '
@@ -65,7 +68,9 @@ function exchange_rsa_keys () {
                chmod 400 $HOME/.ssh/master_rsa &&
                chown '$PG_USER':'$PG_USER' $HOME/.ssh/master_rsa &&
                printf "Host '${PG_HOSTS[0]}'\n\tHostName '${PG_HOSTS[0]}'\n\tIdentityFile ~/.ssh/master_rsa\n\n" >> $HOME/.ssh/config &&
                printf "Host '${PG_POOLS[0]}'\n\tHostName '${PG_POOLS[0]}'\n\tIdentityFile ~/.ssh/master_rsa\n\n" >> $HOME/.ssh/config &&
                ssh-keyscan '${PG_HOSTS[0]}' >> $HOME/.ssh/known_hosts &&
                ssh-keyscan '${PG_POOLS[0]}' >> $HOME/.ssh/known_hosts &&
                rm -rf /tmp/postgresql.trigger && 
                rm -rf $HOME/slave_'$i'_rsa* &&
                ssh-keygen -q -t rsa -P "" -f $HOME/slave_'$i'_rsa &&
@@ -75,7 +80,9 @@ function exchange_rsa_keys () {
        chown ${PG_USERS[0]}:${PG_USERS[0]} `su ${PG_USERS[0]} -c 'echo $HOME/.ssh/ -R'`
        su ${PG_USER[0]} -c 'chmod 400 $HOME/.ssh/slave_'$i'_rsa'
        su ${PG_USERS[0]} -c 'ssh-keyscan '$PG_HOST' >> $HOME/.ssh/known_hosts'
        su ${PG_USERS[0]} -c 'ssh-keyscan '$PG_POOL' >> $HOME/.ssh/known_hosts'
        su ${PG_USERS[0]} -c 'printf "Host '${PG_HOST}'\n\tHostName '${PG_HOST}'\n\tIdentityFile ~/.ssh/slave_'$i'_rsa\n\n" >> $HOME/.ssh/config'
        su ${PG_USERS[0]} -c 'printf "Host '${PG_POOL}'\n\tHostName '${PG_POOL}'\n\tIdentityFile ~/.ssh/slave_'$i'_rsa\n\n" >> $HOME/.ssh/config'
    done
}