-
Notifications
You must be signed in to change notification settings - Fork 21
/
esg-purge.sh
executable file
·269 lines (238 loc) · 7.59 KB
/
esg-purge.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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/bin/sh
#
# esg-purge.sh
#
# This script is intended for sourcing, not direct execution. It
# creates a series of esg-purge functions to return a system to a
# pre-install state and clears relevant environment variables. (The
# environment variables will *only* be cleared from a source, not
# execution, which is why it is done this way).
#
# If you want to purge in a single command, you may wish to set up an
# alias to:
# source /usr/local/esgf/installer/esg-purge.sh && esg-purge all
#
# Run the following command before running this script:
# /usr/local/bin/esg-node --stop
#
# Clear relevant environment variables:
unset JAVA_HOME
unset PGHOME
unset PGHOST
unset PGPORT
unset PGUSER
unset X509_CERT_DIR
unset X509_USER_CERT
unset X509_USER_KEY
DATETIME=$(date +'%Y%m%d.%H')
esg-purge () {
PURGEMODE=$1
case $PURGEMODE in
fast|default)
esg-purge-base
esg-purge-cdat
esg-purge-globus
esg-purge-las
esg-purge-postgres
esg-purge-tomcat
;;
all)
# This part is the same as default
esg-purge-base
esg-purge-cdat
esg-purge-globus
esg-purge-las
esg-purge-postgres
esg-purge-tomcat
esg-purge-slcs
# ... but we add ...
esg-purge-utils
esg-purge-workbench
esg-purge-final
;;
cdat)
esg-purge-cdat
;;
globus)
esg-purge-globus
;;
las)
esg-purge-las
;;
more)
# This part is the same as default
esg-purge-base
esg-purge-cdat
esg-purge-globus
esg-purge-las
esg-purge-postgres
esg-purge-tomcat
# ... but we add ...
esg-purge-workbench
;;
postgres)
esg-purge-postgres
;;
thredds)
esg-purge-thredds
;;
tomcat)
esg-purge-tomcat
;;
tools)
esg-purge-utils
;;
workbench)
esg-purge-workbench
;;
*)
echo "You must specify a valid purge mode!"
echo "If you are doing a rebuild of the same version, you can try 'esg-purge fast'"
echo "Otherwise, run 'esg-purge all'"
return 1
;;
esac
}
esg-purge-base () {
# WARNING: ensure that any mounts are gone from /esg before this
# stage.
#
# The default esg.ini file uses esg_dataroot, so we'll try
# to unmount that first. If esg.ini was changed, there may be
# others.
if [ -d /esg/gridftp_root ] ; then
for mount in $(grep /esg/gridftp_root /proc/mounts | cut -d' ' -f2) ; do
umount -f $mount
done
fi
rm -rf /esg
rm -rf /etc/certs
rm -f /etc/esg.env
rm -rf /etc/esgfcerts
rm -f /etc/httpd/conf/esgf-httpd.conf
rm -rf /etc/tempcerts
rm -rf /opt/esgf
rm -rf /tmp/inputpipe /tmp/outputpipe
rm -f /usr/local/bin/add_checksums_to_map.sh
rm -rf /usr/local/cog
rm -rf /var/www/.python-eggs
# We want to potentially preserve certificates, as they may be
# annoying to recreate and sign.
if [ -f /etc/hostcert.pem ] ; then
echo "WARNING: preserving /etc/hostcert.pem to /tmp/hostcert-$DATETIME.pem"
mv -f /etc/hostcert.pem /tmp/hostcert-$DATETIME.pem
fi
if [ -f /etc/hostkey.pem ] ; then
echo "WARNING: preserving /etc/hostkey.pem to /tmp/hostkey-$DATETIME.pem"
mv -f /etc/hostcert.pem /tmp/hostcert-$DATETIME.pem
fi
# We don't need to preserve the certificate signing request
rm -f /etc/hostcert_request.pem
# WARNING: if $HOME has been reset from /root during an install
# run, these directories could show up in a different place!
rm -rf /root/.cache
rm -rf /root/.python-eggs
# These can potentially be symlinks back to git repositories for
# development. Remove only if they are regular files.
find /usr/local/bin -type f -iname esg-\* -exec rm -f {} \+
find /usr/local/bin -type f -iname esgf-\* -exec rm -f {} \+
find /usr/local/bin -type f -iname jar_security_scan -exec rm -f {} \+
find /usr/local/bin -type f -iname setup-autoinstall -exec rm -f {} \+
# The globs may fail here with no targets, thus || true
rm -rf /usr/local/esgf* || true
rm -rf /usr/local/esgf-solr-* || true
rm -rf /usr/local/solr* || true
rm -rf /usr/local/esgf-node-manager
# Solr may leave stuck java processes. Kill them with extreme prejudice
pkill -9 -f 'java.*/usr/local/solr'
}
esg-purge-cdat () {
yum remove -y cdat uvcdat
rm -rf /usr/local/cdat /usr/local/uvcdat /usr/local/conda /usr/local/cmip6-cmor-tables
}
esg-purge-final () {
# Final cleanup -- anything that prints warning or informational
# message for the user should happen here so they don't get
# scrolled off the screen.
rm -f /etc/yum.repos.d/esgf.repo
rm -f /usr/local/etc/esg-autoinstall.template
if [ -f /usr/local/etc/esg-autoinstall.conf ] ; then
echo "WARNING: not removing autoinstall configuration file /usr/local/etc/esg-autoinstall.conf"
echo "If you want a pristine environment, remove it manually."
fi
}
esg-purge-globus () {
yum remove -y globus\* myproxy\*
rm -rf /etc/esgfcerts
rm -f /etc/globus-host-ssl.conf
rm -f /etc/globus-user-ssl.conf
rm -f /etc/grid-security.conf
rm -rf /etc/globus* || true
rm -rf /etc/grid-security
rm -rf /etc/gridftp* || true
rm -f /etc/logrotate.d/globus-connect-server
rm -rf /etc/myproxy* || true
rm -rf /etc/pam.d/myproxy
rm -f /etc/pam_pgsql.conf
rm -f /etc/pam_pgsql.conf.tmpl.bak
rm -f /etc/rc.d/init.d/globus-gridftp-* || true
rm -rf $HOME/.globus
rm -rf /root/.globus
rm -rf /usr/local/globus
rm -rf /usr/local/gsoap
rm -rf /usr/share/myproxy
rm -rf /var/lib/globus
rm -rf /var/lib/globus-connect-server
rm -rf /var/lib/myproxy
}
esg-purge-las () {
rm -rf /usr/local/ferret
rm -rf /usr/local/ferret_data
# The glob may fail here with no targets, thus || true
rm -rf /usr/local/las-esg* || true
}
esg-purge-postgres () {
yum remove -y postgresql postgresql-libs postgresql-server \
postgresql94 postgresql94-libs postgresql94-server postgresql94-devel
# esg-node --stop may not actually cause Postgresql to exit
# properly, so force-kill all remaining instances
pkill -9 -u postgres
rm -rf /usr/local/pgsql
rm -rf /var/lib/pgsql
# The installation of CDAT creates databases and tables, so
# purging postgres but leaving CDAT will always result in invalid
# assumptions on the part of the installer.
esg-purge-cdat
}
esg-purge-thredds() {
# Sometimes it's useful to purge just Thredds without purging all
# of Tomcat
rm -rf /usr/local/tomcat/webapps/thredds
}
esg-purge-tomcat () {
# esg-node --stop may not actually cause Tomcat to exit properly,
# so force-kill all remaining instances
pkill -9 -u tomcat
rm -f /etc/logrotate.d/esgf_tomcat
# The glob may fail here with no targets, thus || true
rm -rf /usr/local/tomcat* /usr/local/apache-tomcat* || true
# Tomcat may leave stuck java processes. Kill them with extreme prejudice
pkill -9 -f 'java.*/usr/local/tomcat'
}
esg-purge-utils () {
# These are relatively safe elements that increase build time to clean
rm -rf /usr/local/{ant,apache-ant-*}
rm -rf /usr/local/curl
rm -rf /usr/local/geoip
rm -rf /usr/local/git
rm -rf /usr/local/openssl
rm -rf /usr/local/jdk1.*
rm -f /usr/local/java
}
esg-purge-slcs() {
rm -rf /usr/local/src/esgf-slcs-server-playbook
rm -rf /usr/local/esgf-slcs/server
}
esg-purge-workbench() {
rm -rf /usr/local/src/esgf/workbench
}