-
Notifications
You must be signed in to change notification settings - Fork 3
/
UninstallHPCC.sh
executable file
·174 lines (129 loc) · 4.34 KB
/
UninstallHPCC.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
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
#!/bin/bash
#echo "logfile:"$1
#
#---------------------------------
#
# Import functions if not exists
#
# Git branch settings, etc
. ./settings.sh
# StopHpcc() function
declare -f -F StopHpcc> /dev/null
if [ $? -ne 0 ]
then
. ./utils.sh
fi
# WriteLog() function
declare -f -F WriteLog > /dev/null
if [ $? -ne 0 ]
then
. ./timestampLogger.sh
fi
# -----------------------------------------------------
#
# Safe Uninstall HPCC Systems
#
#
UninstallHPCC()
(
logFile=$1
if [[ "$2." == "." ]]
then
wipeOut=0
else
wipeOut=$2
fi
WriteLog "In UninstallHPCC()..." "$logFile"
#WriteLog "Params ($#): $@" "$logFile"
WriteLog "[$( caller )] $*" "$logFile"
#WriteLog "BASH_SOURCE: ${BASH_SOURCE[@]}" "$logFile"
#WriteLog "BASH_LINENO: ${BASH_LINENO[@]}" "$logFile"
#WriteLog "FUNCNAME: ${FUNCNAME[@]}" "$logFile"
WriteLog "Uninstall HPCC started ($0)" "$logFile"
WriteLog "Log file: ${logFile}" "$logFile"
WriteLog "Wipe out: ${wipeOut}" "$logFile"
uninstallFailed=FALSE
if [[ $wipeOut -eq 1 && -f /opt/HPCCSystems/sbin/complete-uninstall.sh ]]
then
WriteLog "Stop HPCC Platform before remove it." "$logFile"
StopHpcc "$logFile"
WriteLog "Use 'complete-uninstall.sh' to remove HPCC." "$logFile"
# Check '-p' parameter
purge=$( /opt/HPCCSystems/sbin/complete-uninstall.sh -h | while read l; do [[ "${l}" =~ "-p, " ]] && echo "-p"; done )
sudo /opt/HPCCSystems/sbin/complete-uninstall.sh $purge >> "$logFile" 2>&1
[ $? -ne 0 ] && uninstallFailed=TRUE
else
if [ $wipeOut -eq 0 ]
then
WriteLog "Remove HPCC but keep data." "$logFile"
StopHpcc "$logFile"
else
WriteLog "It seems HPCC Systems isn't istalled." "$logFile"
# Check if any log directory left
if [[ -d /var/log/HPCCSystems ]]
then
logDirLeft=( $( find /var/log/HPCCSystems/ -iname 'my*' -type d ) )
if [[ ${#logDirLeft[@]} -ne 0 ]]
then
WriteLog "It seems some log directory left. Remove them." "$logFile"
sudo rm -rf ${logDirLeft[*]}
fi
fi
fi
# ( ${PKG_QRY_CMD} hpccsystems-platform ) | grep hpcc | grep -v grep |
# while read hpcc_package
# do
# WriteLog "HPCC package:"${hpcc_package} "$logFile"
#
# sudo ${PKG_REM_CMD} $hpcc_package >> "$logFile" 2>&1
#
# [ $? -ne 0 ] && uninstallFailed=TRUE
# done
( ${PKG_QRY_CMD} hpccsystems-platform ) | grep hpcc > /dev/null 2>&1
if [ $? -eq 0 ]
then
WriteLog "Can't remove HPCC package: ${hpcc_package}" "$logFile"
uninstallFailed=TRUE
fi
fi
ret=0
getent passwd hppc >/dev/null 2>&1 && ret=1
if [[ ${ret} -eq 1 ]]
then
WriteLog "hpcc user still exists" "$logFile"
fi
WriteLog "Check if any hpcc owned process is running" "$logFile"
query="thor|roxie|d[af][fslu]|ecl[s|c|\s|a][g|c]|sase|topo|gdb"
res=$(pgrep -l "${query}" 2>&1 )
if [ -n "$res" ]
then
WriteLog "res:${res}" "$logFile"
res=$( sudo pkill -9 -e -c "${query}" )
WriteLog "res:${res}" "$logFile"
# Give it some time
sleep 1m
res=$(pgrep -l "${query}" 2>&1 )
WriteLog "After pkill res:${res}" "$logFile"
else
WriteLog "There is no leftover process" "$logFile"
fi
if [ "$uninstallFailed" = "TRUE" ]
then
echo "TestResult:FAILED" >> uninstall.summary
WriteLog "Uninstall HPCC-Platform FAILED" "$logFile"
else
echo "TestResult:PASSED" >> uninstall.summary
WriteLog "Uninstall HPCC-Platform PASSED" "$logFile"
if [ -f /etc/HPCCSystems/environment.xml ]
then
WriteLog "Remove environment.xml to ensure clean, out-of-box environment." "$logFile"
sudo rm /etc/HPCCSystems/environment.xml
fi
fi
WriteLog "Generate port usage summary file." "$logFile"
portUsage="$( ss -antp4 2>&1 )"
echo -e "Used ports before HPCC started:\n ${portUsage}" > usedPort.summary
#WriteLog "Used ports before HPCC started:\n ${portUsage}\n----------------------" "$logFile"
)
# call arguments verbatim:
#"$@"