-
Notifications
You must be signed in to change notification settings - Fork 3
/
deployProd.sh
executable file
·348 lines (313 loc) · 14.2 KB
/
deployProd.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/bin/sh
### This script downloads a CMSWEB deployment tag and then use the Deploy script
### with the arguments provided in the command line to deploy WMAgent in a VOBox.
###
### It deploys the agent, apply all the required patches (TODO they must be defined
### in the code), populate the resource-control database, apply final tweaks to
### the configuration and finally, download and create some utilitarian cronjobs.
###
### You also can choose whether you want to separate the WMAgent from the Couchdb
### deployment. By default Couch databases will be available in /data partition.
### Unless there is a /data1 partition and you select to use it.
###
### If you are deploying a testbed agent (with "testbed" in the team name), it will
### point to cmsweb-testbed DBSUrl.
###
### Usage: deployProd.sh -h
### Usage: -w <wma_version> WMAgent version (tag) available in the WMCore repository
### Usage: -c <cmsweb_tag> CMSWEB deployment tag used for the WMAgent deployment
### Usage: -t <team_name> Team name in which the agent should be connected to
### Usage: -s <scram_arch> The RPM architecture (defaults to slc5_amd64_gcc461)
### Usage: -r <repository> Comp repository to look for the RPMs (defaults to comp=comp)
### Usage: -p <patches> List of PR numbers in double quotes and space separated (e.g., "5906 5934 5922")
### Usage: -n <agent_number> Agent number to be set when more than 1 agent connected to the same team (defaults to 0)
### Usage:
### Usage: deployProd.sh -w <wma_version> -c <cmsweb_tag> -t <team_name> [-s <scram_arch>] [-r <repository>] [-n <agent_number>]
### Usage: Example: sh deployProd.sh -w 1.0.7.pre10 -c HG1506c -t production -p "5757 5932" -n 2
### Usage: Example: sh deployProd.sh -w 1.0.5.patch2 -c HG1504d -t testbed-cmssrv113 -s slc6_amd64_gcc481 -r comp=comp.pre
### Usage:
### TODO:
### - automatize the clean up of the old agent
BASE_DIR=/data/srv
DEPLOY_DIR=$BASE_DIR/wmagent
ENV_FILE=/data/admin/wmagent/env.sh
CURRENT=/data/srv/wmagent/current
MANAGE=/data/srv/wmagent/current/config/wmagent/
HOSTNAME=`hostname`
# These values may be overwritten by the arguments provided in the command line
WMA_ARCH=slc5_amd64_gcc461
REPO="comp=comp"
AG_NUM=0
FLAVOR=mysql
### Usage function: print the usage of the script
usage()
{
perl -ne '/^### Usage:/ && do { s/^### ?//; print }' < $0
exit 1
}
### Help function: print help for this script
help()
{
perl -ne '/^###/ && do { s/^### ?//; print }' < $0
exit 0
}
### Cleanup function: it cleans up the oracle database
cleanup_oracle()
{
cd $CURRENT/config/wmagent/
cat > clean-oracle.sql << EOT
BEGIN
FOR cur_rec IN (SELECT object_name, object_type
FROM user_objects
WHERE object_type IN
('TABLE',
'VIEW',
'PACKAGE',
'PROCEDURE',
'FUNCTION',
'SEQUENCE'
))
LOOP
BEGIN
IF cur_rec.object_type = 'TABLE'
THEN
EXECUTE IMMEDIATE 'DROP '
|| cur_rec.object_type
|| ' "'
|| cur_rec.object_name
|| '" CASCADE CONSTRAINTS';
ELSE
EXECUTE IMMEDIATE 'DROP '
|| cur_rec.object_type
|| ' "'
|| cur_rec.object_name
|| '"';
END IF;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ( 'FAILED: DROP '
|| cur_rec.object_type
|| ' "'
|| cur_rec.object_name
|| '"'
);
END;
END LOOP;
END;
/
EOT
while true; do
tmpf=`mktemp`
./manage db-prompt < clean-oracle.sql > $tmpf
if grep -iq "PL/SQL procedure successfully completed" $tmpf; then
break
fi
done
rm -f $tmpf
echo -e "PURGE RECYCLEBIN;\nselect tname from tab;" > purging.sql
./manage db-prompt < purging.sql
rm -f clean-oracle.sql purging.sql
echo "Done!" && echo
}
for arg; do
case $arg in
-h) help ;;
-w) WMA_TAG=$2; shift; shift ;;
-c) CMSWEB_TAG=$2; shift; shift ;;
-t) TEAMNAME=$2; shift; shift ;;
-s) WMA_ARCH=$2; shift; shift ;;
-r) REPO=$2; shift; shift ;;
-p) PATCHES=$2; shift; shift ;;
-n) AG_NUM=$2; shift; shift ;;
-*) usage ;;
esac
done
if [[ -z $WMA_TAG ]] || [[ -z $CMSWEB_TAG ]] || [[ -z $TEAMNAME ]]; then
usage
exit 1
fi
source $ENV_FILE;
MATCH_ORACLE_USER=`cat $WMAGENT_SECRETS_LOCATION | grep ORACLE_USER | sed s/ORACLE_USER=//`
if [ "x$MATCH_ORACLE_USER" != "x" ]; then
FLAVOR=oracle
fi
if [[ "$HOSTNAME" == *cern.ch ]]; then
MYPROXY_CREDNAME="amaltaroCERN"
elif [[ "$HOSTNAME" == *fnal.gov ]]; then
MYPROXY_CREDNAME="amaltaroFNAL"
else
echo "Sorry, I don't know this network domain name"
exit 1
fi
#DATA_SIZE=`df -h | grep '/data1' | awk '{print $2}'`
DATA_SIZE=`lsblk -o SIZE,MOUNTPOINT | grep ' /data1' | awk '{print $1}'`
if [[ -z $DATA_SIZE ]]; then
DATA1=false
else
echo "Partition /data1 available! Total size: $DATA_SIZE"
sleep 0.5
while true; do
read -p "Would you like to deploy couchdb in this /data1 partition (yes/no)? " yn
case $yn in
[Y/y]* ) DATA1=true; break;;
[N/n]* ) DATA1=false; break;;
* ) echo "Please answer yes or no.";;
esac
done
fi && echo
echo "Starting new agent deployment with the following data:"
echo " - WMAgent version: $WMA_TAG"
echo " - CMSWEB tag : $CMSWEB_TAG"
echo " - Team name : $TEAMNAME"
echo " - WMAgent Arch : $WMA_ARCH"
echo " - Repository : $REPO"
echo " - Agent number : $AG_NUM"
echo " - DB Flavor : $FLAVOR"
echo " - Use /data1 : $DATA1" && echo
mkdir -p $DEPLOY_DIR || true
cd $BASE_DIR
rm -rf deployment deployment.zip deployment-${CMSWEB_TAG};
set -e
wget -nv -O deployment.zip --no-check-certificate https://github.com/dmwm/deployment/archive/$CMSWEB_TAG.zip
unzip -q deployment.zip
cd deployment-$CMSWEB_TAG
set +e
### Patching Couchdb1.6
echo -e "\n*** Applying deployment patches (couchdb1.6, etc) ***"
wget -nv https://github.com/dmwm/deployment/pull/162.patch -O - | patch -p 1
chmod 600 /data/certs/service{cert,key}.pem
echo "Done!"
echo -e "\n*** Removing the current crontab ***"
/usr/bin/crontab -r;
echo "Done!"
echo -e "\n*** Bootstrapping WMAgent: prep ***"
cd $BASE_DIR/deployment-$CMSWEB_TAG
set -e
./Deploy -R wmagent@$WMA_TAG -s prep -A $WMA_ARCH -r $REPO -t v$WMA_TAG $DEPLOY_DIR wmagent
echo -e "\n*** Deploying WMAgent: sw ***"
./Deploy -R wmagent@$WMA_TAG -s sw -A $WMA_ARCH -r $REPO -t v$WMA_TAG $DEPLOY_DIR wmagent
echo -e "\n*** Posting WMAgent: post ***"
./Deploy -R wmagent@$WMA_TAG -s post -A $WMA_ARCH -r $REPO -t v$WMA_TAG $DEPLOY_DIR wmagent
set +e
echo -e "\n*** Activating the agent ***"
cd $MANAGE
./manage activate-agent
echo "Done!" && echo
### Checking the database backend
echo "*** Cleaning up database instance ***"
if [ "$FLAVOR" == "oracle" ]; then
cleanup_oracle
elif [ "$FLAVOR" == "mysql" ]; then
echo "Mysql, nothing to clean up" && echo
fi
### Enabling couch watchdog:
echo "*** Enabling couch watchdog ***"
sed -i "s+RESPAWN_TIMEOUT=0+RESPAWN_TIMEOUT=5+" $CURRENT/sw*/$WMA_ARCH/external/couchdb*/*/bin/couchdb
echo "Done!" && echo
echo "*** Starting services ***"
./manage start-services
echo "Done!" && echo
sleep 5
echo "*** Initializing the agent ***"
./manage init-agent
echo "Done!" && echo
sleep 5
# By default, it will only work for official WMCore patches in the general path
echo -e "\n*** Applying agent patches ***"
if [ "x$PATCHES" != "x" ]; then
cd $CURRENT
for pr in $PATCHES; do
wget -nv https://github.com/dmwm/WMCore/pull/$pr.patch -O - | patch -d apps/wmagent/lib/python2.6/site-packages/ -p 3
done
cd -
fi
echo "Done!" && echo
echo "*** Checking if couchdb migration is needed ***"
echo -e "\n[query_server_config]\nos_process_limit = 50" >> $CURRENT/config/couchdb/local.ini
if [ "$DATA1" = true ]; then
./manage stop-services
sleep 5
if [ -d "/data1/database/" ]; then
echo "Moving old database away... "
mv /data1/database/ /data1/database_old/
FINAL_MSG="5) Remove the old database when possible (/data1/database_old/)"
fi
rsync --remove-source-files -avr /data/srv/wmagent/current/install/couchdb/database /data1
sed -i "s+database_dir = .*+database_dir = /data1/database+" $CURRENT/config/couchdb/local.ini
sed -i "s+view_index_dir = .*+view_index_dir = /data1/database+" $CURRENT/config/couchdb/local.ini
./manage start-services
fi
echo "Done!" && echo
###
# tweak configuration
### TODO: remove part of these tweaks when #5949 gets merged
echo "*** Tweaking configuration ***"
sed -i "s+couchProcessThreshold = 25+couchProcessThreshold = 50+" $MANAGE/config.py
sed -i "s+team1,team2,cmsdataops+$TEAMNAME+" $MANAGE/config.py
sed -i "s+Agent.agentNumber = 0+Agent.agentNumber = $AG_NUM+" $MANAGE/config.py
sed -i "s+OP EMAIL+$OP_EMAIL+" $MANAGE/config.py
sed -i "s+config.AnalyticsDataCollector.diskUseThreshold = 60+config.AnalyticsDataCollector.diskUseThreshold = 75+" $MANAGE/config.py
sed -i "s+config.PhEDExInjector.diskSites = \[\]+config.PhEDExInjector.diskSites = \['storm-fe-cms.cr.cnaf.infn.it','srm-cms-disk.gridpp.rl.ac.uk','cmssrm-fzk.gridka.de','ccsrm.in2p3.fr','srmcms.pic.es','cmssrmdisk.fnal.gov'\]+" $MANAGE/config.py
sed -i "s+'Running': 169200, 'Pending': 360000, 'Error': 1800+'Running': 169200, 'Pending': 259200, 'Error': 1800+" $MANAGE/config.py
if [[ "$TEAMNAME" == relval* ]]; then
sed -i "s+ErrorHandler.maxRetries = 3+ErrorHandler.maxRetries = \{'default' : 3, 'Merge' : 4, 'LogCollect' : 2, 'Cleanup' : 2\}+" $MANAGE/config.py
sed -i "s+config.TaskArchiver.archiveDelayHours = 24+config.TaskArchiver.archiveDelayHours = 336+" $MANAGE/config.py
elif [[ "$TEAMNAME" == *testbed* ]]; then
GLOBAL_DBS_URL=https://cmsweb-testbed.cern.ch/dbs/int/global/DBSReader
sed -i "s+ErrorHandler.maxRetries = 3+ErrorHandler.maxRetries = 0+" $MANAGE/config.py
sed -i "s+DBSInterface.globalDBSUrl = 'https://cmsweb.cern.ch/dbs/prod/global/DBSReader'+DBSInterface.globalDBSUrl = '$GLOBAL_DBS_URL'+" $MANAGE/config.py
sed -i "s+DBSInterface.DBSUrl = 'https://cmsweb.cern.ch/dbs/prod/global/DBSReader'+DBSInterface.DBSUrl = '$GLOBAL_DBS_URL'+" $MANAGE/config.py
else
sed -i "s+ErrorHandler.maxRetries = 3+ErrorHandler.maxRetries = \{'default' : 3, 'Harvesting' : 2, 'Merge' : 4, 'LogCollect' : 1, 'Cleanup' : 2\}+" $MANAGE/config.py
fi
# TODO remove this hack once AlertProcessor gets fixed
sed -i "s+config.AlertProcessor.critical.sinks.email.fromAddr = '[email protected]'+#config.AlertProcessor.critical.sinks.email.fromAddr = '[email protected]'+" $MANAGE/config.py
sed -i "s+config.AlertProcessor.critical.sinks.email.smtpServer = 'cernmx.cern.ch'+#config.AlertProcessor.critical.sinks.email.smtpServer = 'cernmx.cern.ch'+" $MANAGE/config.py
sed -i "s+config.AlertProcessor.critical.sinks.email.toAddr = \['[email protected]'\]+#config.AlertProcessor.critical.sinks.email.toAddr = \['[email protected]'\]+" $MANAGE/config.py
sed -i "s+config.AlertProcessor.soft.sinks.email.fromAddr = '[email protected]'+#config.AlertProcessor.soft.sinks.email.fromAddr = '[email protected]'+" $MANAGE/config.py
sed -i "s+config.AlertProcessor.soft.sinks.email.smtpServer = 'cernmx.cern.ch'+#config.AlertProcessor.soft.sinks.email.smtpServer = 'cernmx.cern.ch'+" $MANAGE/config.py
sed -i "s+config.AlertProcessor.soft.sinks.email.toAddr = \['[email protected]'\]+#config.AlertProcessor.soft.sinks.email.toAddr = \['[email protected]'\]+" $MANAGE/config.py
# Additional config
sed -i "/config.ErrorHandler.pollInterval = 240/a config.ErrorHandler.maxProcessSize = 30" $MANAGE/config.py
echo "Done!" && echo
### Populating resource-control
echo "*** Populating resource-control ***"
cd $MANAGE
if [[ "$TEAMNAME" == relval* || "$TEAMNAME" == *testbed* ]]; then
echo "Adding only T1 and T2 sites to resource-control..."
./manage execute-agent wmagent-resource-control --add-T1s --plugin=CondorPlugin --pending-slots=50 --running-slots=50
./manage execute-agent wmagent-resource-control --add-T2s --plugin=CondorPlugin --pending-slots=50 --running-slots=50
else
echo "Adding ALL sites to resource-control..."
./manage execute-agent wmagent-resource-control --add-all-sites --plugin=CondorPlugin --pending-slots=50 --running-slots=50
fi
echo "Done!" && echo
###
# set scripts and specific cronjobs
###
echo "*** Downloading utilitarian scripts ***"
cd $CURRENT
rm -f rmOldJobs.sh checkProxy.py
wget -q --no-check-certificate https://raw.githubusercontent.com/CMSCompOps/WmAgentScripts/master/rmOldJobs.sh
wget -q --no-check-certificate https://raw.githubusercontent.com/amaltaro/scripts/master/checkProxy.py
mv -f checkProxy.py /data/admin/wmagent/
echo "Done!" && echo
### Populating cronjob with utilitarian scripts
echo "*** Creating cronjobs for them ***"
( crontab -l 2>/dev/null | grep -Fv ntpdate
echo "#remove old jobs script"
echo "10 */4 * * * source /data/srv/wmagent/current/rmOldJobs.sh &> /tmp/rmJobs.log"
echo "55 */12 * * * (export X509_USER_CERT=/data/certs/servicecert.pem; export X509_USER_KEY=/data/certs/servicekey.pem; myproxy-get-delegation -v -l amaltaro -t 168 -s 'myproxy.cern.ch' -k $MYPROXY_CREDNAME -n -o /data/certs/mynewproxy.pem && voms-proxy-init -rfc -voms cms:/cms/Role=production -valid 168:00 -noregen -cert /data/certs/mynewproxy.pem -key /data/certs/mynewproxy.pem -out /data/certs/myproxy.pem)"
echo "58 */12 * * * python /data/admin/wmagent/checkProxy.py --proxy /data/certs/myproxy.pem --time 96 --send-mail True --mail [email protected],[email protected]"
) | crontab -
echo "Done!" && echo
echo && echo "Deployment finished!! However you still need to:"
echo " 1) Source the new WMA env: source /data/admin/wmagent/env.sh"
echo " 2) Double check agent configuration: less config/wmagent/config.py"
echo " 3) Start the agent with: \$manage start-agent"
echo " 4) Remove the old WMAgent version when possible"
echo " $FINAL_MSG"
echo "Have a nice day!" && echo
exit 0