-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpostgres-vaccum-reindex.sh
63 lines (50 loc) · 1.89 KB
/
postgres-vaccum-reindex.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
60
61
62
#!/bin/bash
echo -e "\n** NOTE: Please ensure that there are no tasks running in satellite server or no activities going on as satellite services will be down when this maintenance activity is going on. ***\n"
read -p "Do you want to proceed further ? [ Hit y to start or n to quit ] : " confirm ;
if [ $confirm == 'n' ] || [ $confirm == 'no' ] || [ $confirm == 'N' ] || [ $confirm == 'NO' ] || [ $confirm == 'No' ]
then
echo -e "\n Cancelling the script execution now.. \n"
exit 1
elif [ $confirm == 'y' ] || [ $confirm == 'yes' ] || [ $confirm == 'Y' ] || [ $confirm == 'YES' ] || [ $confirm == 'Yes' ]
then
rpm -q satellite &>/dev/null && SAT='TRUE' || SAT='FALSE'
if [[ $SAT == 'TRUE' ]]
then
echo -e "\n--> Stopping all Satellite services now....... \n"
foreman-maintain service stop
echo -e "\n--> Starting postgresql service now........... \n"
systemctl start postgresql
echo -e "\n--> Checking status of postgresql service..... "
systemctl is-active postgresql &> /dev/null && STAT='active' || STAT='dead'
echo -e "***** $STAT"
if [[ $STAT != 'active' ]]
then
echo -e "\nCheck and fix the postgres service.\n"
exit 1;
else
echo -e "\n--> Vaccuming postgres database................ \n"
runuser -u postgres -- vacuumdb -afz
if [ $? -eq '0' ]
then
sleep 4
echo -e "\n--> Re-indexing postgres database.............. \n"
runuser -u postgres -- reindexdb -a
sleep 4
else
echo -e "\nCheck and fix the error with vacuuming.\n"
exit 1;
fi
fi
echo -e "\n--> Restarting all satellite services....... \n"
foreman-maintain service restart
sleep 6
echo -e "\n--> Checking satellite health............... \n"
foreman-maintain service status -b
echo -e "\n\n"
hammer ping
echo " "
fi
else
echo -e "\n Please provide a valid input i.e. either yes or no. \n"
exit 1
fi