forked from puppetlabs/support-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
st0287_check_db_table_sizes.sh
59 lines (53 loc) · 1.68 KB
/
st0287_check_db_table_sizes.sh
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
#!/bin/bash
# shellcheck disable=SC2068
# Puppet Task Name: ST0287_Check_DB_Table_Sizes
declare PT_dbname
dbname=$PT_dbname
declare PT__installdir
source "$PT__installdir/bash_task_helper/files/task_helper.sh"
function getdbTables() {
path=$1
dbname=$2
service=$3
shift 3
dblist=("$@")
if [ "$dbname" != 'all' ]; then
echo "${service} service detected, will continue to run against ${dbname}."
su - "$service" -s /bin/bash -c "$path -d $dbname -c '\di+;'"
else
echo "${service} service detected, will continue to run against ${dblist[*]}."
for db in ${dblist[@]};
do
su - "$service" -s /bin/bash -c "$path -d $db -c '\di+;'"
done
fi
}
#Determine if PE or OSP Postgres
if puppet resource service pe-postgresql | grep -q running; then
postgresservice="pe-postgres"
if [ -z "$dbname" ]; then
dbname="pe-puppetdb"
fi
elif puppet resource service postgresql-* | grep -q running; then
postgresservice="postgres"
if [ -z "$dbname" ]; then
dbname="puppetdb"
fi
else
task-succeed "success - Node not running pe-postgresql or postgresql service, please select node which is."
fi
#Run for the correct environment
case "${postgresservice}" in
pe-postgres)
echo "Found PE-Postgres"
pedbnames='pe-puppetdb pe-postgres pe-classifier pe-rbac pe-activity pe-orchestrator postgres'
getdbTables "/opt/puppetlabs/server/bin/psql" "${dbname}" "${postgresservice}" "${pedbnames}"
;;
postgres)
echo "Found Postgres"
getdbTables "psql" "${dbname}" "${postgresservice}" "puppetdb"
;;
*)
task-fail "Cannot Determine if Puppet Enterprise or Puppet Open Source"
esac
task-succeed "success - Task completed"