aboutsummaryrefslogtreecommitdiffstats
path: root/pgaas/src/stage/opt/app/pgaas/bin/pgaas-verify-install
blob: f80ea2a962a531bf8fd3933239ba192ad81fcab6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/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. 


die()
{
    exec 1>&2
    echo "$@"
    logger --stderr --priority local1.error --tag "DCAE" "$@"
    exit 1
}

usage()
{
    exec 1>&2
    [ $# -gt 0 ] && echo "$@"
    b=$(basename $0)
    echo "Usage: $b [-v]"
    echo "$b runs a variety of tests on the PG VM and database"
    echo "It should be run as root or postgres."
    echo "If run as root, it will do additional tests that are"
    echo "not possible as a normal user. If not run as root or"
    echo "postgres, other tests may fail."
    echo " -v verbose"
    echo " -P do not print VERIFIED"
    exit 1
}

PRINTVERIFIED=:
while getopts Pv c
do
    case $c in
        P ) PRINTVERIFIED=false ;;
        v ) set -x ;;
        '?' ) usage ;;
    esac
done
shift `expr $OPTIND - 1`

# this can be run as root
ROOT=false
case `id` in
    *"(root)"* ) ROOT=true ;;
    *"(postgres)"* )  ;;
    * ) echo "$0 should be run as either root or postgres" ;;
esac

VERIFIEDCOUNT=0
FAILEDCOUNT=0
TOTALCOUNT=0

verified()
{
    (( VERIFIEDCOUNT = VERIFIEDCOUNT + 1 ))
    (( TOTALCOUNT = TOTALCOUNT + 1 ))
    $PRINTVERIFIED && echo "VERIFIED: $@"
}

failed()
{
    (( FAILEDCOUNT = FAILEDCOUNT + 1 ))
    (( TOTALCOUNT = TOTALCOUNT + 1 ))
    echo "FAILED: $@"
}

tabtext()
{
    echo "$@" | sed 's/^/	/'
}

HOSTNAME=$(hostname -f)

################################################################
################        things set up by        ################
################           openstack            ################
################################################################

case $HOSTNAME in
    *.*.* ) verified "hostname has a FQDN" ;;
    * ) failed "hostname does not have a FQDN" ;;
esac

################################################################
################        things set up by        ################
################    controller dcae_install     ################
################################################################

#### user dcae is no longer used
#### if grep '^dcae:' /etc/passwd > /dev/null
#### then verified "dcae user exists"
#### else failed "dcae user does not exist"
#### fi
#### if $ROOT
#### then
####     if [ -s /etc/sudoers.d/dcae-postgres ]
####     then verified "dcae can sudo to postgres"
####     else failed "dcae cannot sudo to postgres"
####     fi
#### fi

SHOWDF=false
for i in /opt/tools /opt/logs /dbroot/pgdata /dbroot/pglogs /dbroot/pgbackup
do
    if df -h 2>&1 | grep " $i"'$' > /dev/null
    then verified "$i has its own filesystem"
    else failed "$i does not have its own filesystem"; SHOWDF=true
    fi
done
$SHOWDF && tabtext "$(df -h 2>&1)"

if grep '^postgres:' /etc/passwd > /dev/null
then verified "postgres user exists"
else failed "postgres user does not exist"
fi

################################################################
################        things set up by        ################
################          cdf package           ################
################################################################

if [ -d /opt/app/cdf ]
then verified "/opt/app/cdf is present"
else failed "/opt/app/cdf is present"
fi

cdfcall=$(/opt/app/cdf/bin/getpropvalue -n foo 2>&1)
case "$cdfcall" in
    *Configuration?property*must?be?defined* ) verified "CDF is installed and working" ;;
    * ) failed "CDF is not installed and working"; tabtext "$cdfcall" ;;
esac

################################################################
################        things set up by        ################
################        pgaas-prep step         ################
################################################################

if grep "^pgnodes=.*$HOSTNAME" /opt/app/cdf/lib/cdf.cfg > /dev/null
then verified "HOSTNAME is part of cluster (cdf.cfg pgnodes)"
else failed "HOSTNAME is not part of cluster (cdf.cfg pgnodes)"
fi

# check for certificate presence goes here

if [ -s /lib/systemd/system/pgaas-idns.service ]
then verified "found pgaas-idns service properly installed for Ubuntu 16"
elif [ -s /etc/init/pgaas-idns.conf ]
then verified "found pgaas-idns service properly installed for Ubuntu 14"
else failed "pgaas-idns service has not been installed properly"
fi

if ps -ef | grep '[i]DNS-responder' > /dev/null
then verified "iDNS-responder is running"
    if ps -fu postgres | grep '[i]DNS-responder' > /dev/null
    then verified "iDNS-responder is running as postgres"
    else failed "iDNS-responder is running, but not as postgres"
    fi
else failed "postgres does not have a logger process running"
fi

if [ -d /var/run/postgresql ]
then verified "/var/run/postgresql exists"
else failed "/var/run/postgresql does not exist"
fi

if [ -s /etc/logrotate.d/pgaas ]
then verified "/etc/logrotate.d/pgaas has been installed"
else failed "/etc/logrotate.d/pgaas has not been installed"
fi


################################################################
################        things set up by        ################
################       pgaas-config step        ################
################################################################

if ps -fu postgres | grep "[p]ostgres: logger process" > /dev/null
then verified "postgres is running"
else failed "postgres does not have a logger process running"
fi

if pgrep repmgrd > /dev/null
then verified "repmgrd is running"
else failed "repmgrd is not running"
fi

if [ -f /opt/app/pgaas/bin/runpsqll ]
then
    verified "/opt/app/pgaas/bin/runpsqll is installed"
    roles=$( /opt/app/pgaas/bin/runpsqll "select rolname from pg_roles" )
    case "$roles" in
        *repmgr* ) verified "postgres repmgr role name is present" ;;
        * ) failed "postgres repmgr role name was not added"; tabtext "$roles" ;;
    esac
    rolcount=$( /opt/app/pgaas/bin/runpsqll "select count(rolname) from pg_roles" | awk 'NF > 0 {print $1}' )
    case $rolcount in
        1 | 2 ) failed "no additional postgresql role names have been added"; tabtext "$roles" ;;
        * ) verified "additional postgresql role names have been added" ;;
    esac
    dxpgtemporal=$( /opt/app/pgaas/bin/runpsqll "select count(extname) from pg_extension where extname = 'temporal_tables'" | awk 'NF > 0 {print $1}' )
    case $dxpgtemporal in
	1 ) verified "temporal_tables extension has been added" ;;
	* ) failed "temporal_tables extension has not been added" ;;
    esac
else
    failed "/opt/app/pgaas/bin/runpsqll is not installed"
fi

if [ -f /opt/app/pgaas/bin/check_cluster ]
then
    verified "/opt/app/pgaas/bin/check_cluster is installed"
    ckcl=$( /opt/app/pgaas/bin/check_cluster 2>&1 )
    case $ckcl in
        *No?such?file?or?directory* ) failed "check_cluster not found"; tabtext "$ckcl" ;;
        *ERROR* ) failed "check_cluster returned error:"; tabtext "$ckcl" ;;
        *WARNING* ) failed "check_cluster returned a warning:"; tabtext "$ckcl" ;;
        * ) verified "check_cluster succeeded" ;;
    esac
else
    failed "/opt/app/pgaas/bin/check_cluster is not installed"
fi

echo "$VERIFIEDCOUNT tests passed, $FAILEDCOUNT tests failed, $TOTALCOUNT total tests run"