-
Notifications
You must be signed in to change notification settings - Fork 5
/
volcinstall.sh
executable file
·409 lines (362 loc) · 12.8 KB
/
volcinstall.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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
#!/bin/bash
# Copyright (C) 2021-2025 Bytedance Ltd. and/or its affiliates
# Description:
# You can use this script in two ways to install volclava in shared file system:
# Way1: Install volclava in cluster by three steps:
# 1) Run 'volcinstall.sh --setup=pre' on each host in cluster.
# This will help to setup environments and install some necessary packages
# needed by volclava.
# 2) Run 'volcinstall.sh --setup=install --type=code --prefix=/share-nfs/software/volclava'
# on master host.
# This will install volclava package on the shared file system
# 3) Run 'volcinstall.sh --setup=post --env=/share-nfs/software/volclava'
# on each host in cluster.
# This will help enable the automatic startup of services and the automatic
# addition of environment variables for each host in cluster.
# Way2: Install volclava in cluster by two steps:
# 1) Install master host: 'volcinstall.sh --type=code --prefix=/share-nfs/software/volclava'.
# This will help finish all steps(pre/install/post) for master host.
# 2) Log on each compute node, run "volcinstall.sh --type=server --prefix=/share-nfs/software/volclava"
# This will help finish installation steps on server host.
#
# Note:
# --hosts=/path/file: It is a file which lists hosts' name in one column. Default is not to add hosts into
# lsf.cluster.volclava. If defined, installer will append hosts into lsf.cluster.volclava.
# --startup: Default is N. When set as Y, you also need define "--hosts", then we will startup cluster after
# installation. Without "--hosts", volclava fails to startup cluster because of no hosts in cluster.
# --uid: specify uniform uid for user "volclava". Default is undefined.
function usage() {
echo "Usage: volcinstall.sh [--help]"
echo " [--setup=pre [--uid=number]]"
echo " [--setup=install [--type=code|rpm|deb] [--prefix=/opt/volclava] [--hosts=\"master server1 ...\"|/path/file]]"
echo " [--setup=post [--env=/volclava_top] [--startup=Y|y|N|n]]"
echo " [--type=code|rpm|deb|server] [--prefix=/opt/volclava] [--hosts=\"master server1 ...\"|/path/file] [--uid=number] [--startup=Y|y|N|n]"
}
#Default values
TYPE="code"
PACKAGE_NAME="volclava-1.0"
PREFIX="/opt/${PACKAGE_NAME}"
setPrefix=0
PHASE="all"
USRID=""
HOSTS=""
STARTUP="N"
while [ $# -gt 0 ]; do
case $1 in
--type=*)
TYPE=$(echo $1 | awk -F "=" '{print $2}')
if [ -z "$TYPE" ]; then
usage
exit 1
fi
if [ "$TYPE" == "rpm" -a $setPrefix -eq 0 ]; then
PREFIX="/opt"
fi
if [ "$TYPE" == "deb" -a $setPrefix -eq 0 ]; then
PREFIX="/opt"
fi
if [ "$TYPE" == "server" -a $PHASE != "all" ]; then
usage
exit 1
fi
if [ "$TYPE" == "server" ]; then
PHASE="pre-post"
fi
;;
--prefix=*)
PREFIX=$(echo $1 | awk -F "=" '{print $2}')
if [ -z "$PREFIX" ]; then
usage
exit 1
fi
setPrefix=1
;;
--setup=*)
PHASE=$(echo $1 | awk -F "=" '{print $2}')
if [ -z "$PHASE" ]; then
usage
exit 1
fi
if [ "$PHASE" != "pre" -a "$PHASE" != "post" -a "$PHASE" != "install" ]; then
usage
exit 1
fi
;;
--env=*)
PREFIX=$(echo $1 | awk -F "=" '{print $2}')
if [ -z "$PREFIX" ]; then
usage
exit 1
fi
;;
--uid=*)
USRID=$(echo $1 | awk -F "=" '{print $2}')
if [ -z "$USRID" ]; then
usage
exit 1
fi
;;
--hosts=*)
HOSTS=$(echo $1 | awk -F "=" '{print $2}')
if [ -z "$HOSTS" ]; then
usage
exit 1
fi
;;
--startup=*)
STARTUP=$(echo $1 | awk -F "=" '{print $2}')
if [ -z "$STARTUP" ]; then
usage
exit 1
fi
if [[ "$STARTUP" != "Y" ]] && [[ "$STARTUP" != "y" ]] && [[ "$STARTUP" != "N" ]] && [[ "$STARTUP" != "n" ]]; then
usage
exit 1
fi
;;
--help)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
shift
done
if [ "$TYPE" != "code" -a "$TYPE" != "rpm" -a "$TYPE" != "deb" -a "$TYPE" != "server" ]; then
usage
exit 1
fi
if [ "$TYPE" = "server" -a "$PHASE" != "pre-post" ] || [ "$TYPE" != "server" -a "$PHASE" = "pre-post" ]; then
usage
exit 1
fi
osType=$(sed -n '/^NAME=/ {s/^NAME="//;s/"$//;p}' /etc/os-release)
if [ -z "$osType" ]; then
echo "Failed to find OS type, please check supported OS from README.md"
exit 1
fi
if [ "$osType" = "Ubuntu" ] && [ "$TYPE" = "rpm" ]; then
echo "Ubuntu does not support rpm installation, please install package from source code"
exit 1
fi
if [ "$osType" = "Rocky Linux" ] && [ "$TYPE" = "deb" ]; then
echo "Rocky Linux does not support deb installation, please install package from source code"
exit 1
fi
if [ "$osType" = "CentOS Linux" ] && [ "$TYPE" = "deb" ]; then
echo "CentOS Linux does not support deb installation, please install package from source code"
exit 1
fi
function pre_setup() {
#add user
if ! id -u "volclava" > /dev/null 2>&1; then
if [ -z "$USRID" ]; then
useradd "volclava"
else
useradd -u $USRID "volclava"
fi
fi
#install compile library
if [ "$osType" = "Rocky Linux" ]; then
yum install -y ncurses-devel tcl tcl-devel libtirpc libtirpc-devel libnsl2-devel
yum groupinstall -y "Development Tools"
elif [ "$osType" = "Ubuntu" ]; then
apt update
apt install -y build-essential automake tcl-dev libncurses-dev debhelper
else #CentOS
yum install -y tcl-devel ncurses-devel
yum groupinstall -y "Development Tools"
fi
#close firewall
if [ "$osType" != "Ubuntu" ]; then
systemctl stop firewalld
systemctl disable firewalld
fi
}
function post_setup() {
#rpm way doesn't need post setup, rpm already setup service and shell environment
if [ "$TYPE" = "rpm" -a "$PHASE" = "all" ]; then
return
fi
#set up volclava service and shell environment
if [ "$TYPE" = "deb" ] && [ $setPrefix -ne 0 ]; then
cp $PREFIX/lib/systemd/system/volclava.service /lib/systemd/system/volclava.service
chmod 644 /lib/systemd/system/volclava.service
cp $PREFIX/etc/init.d/volclava /etc/init.d/volclava
chmod 755 /etc/init.d/volclava
systemctl daemon-reload
cp -f $PREFIX/etc/profile.d/volclava.csh /etc/profile.d/
cp -f $PREFIX/etc/profile.d/volclava.sh /etc/profile.d/
else
cp -f $PREFIX/etc/volclava /etc/init.d/
cp -f $PREFIX/etc/volclava.csh /etc/profile.d/
cp -f $PREFIX/etc/volclava.sh /etc/profile.d/
fi
# configure the lava service to start at boot
if [ "$osType" == "Ubuntu" ]; then
/lib/systemd/systemd-sysv-install enable volclava
else
chkconfig --add volclava
chkconfig volclava on
fi
# startup cluster if need
if [[ "$STARTUP" == "Y" ]] || [[ "$STARTUP" == "y" ]]; then
service volclava start
fi
source /etc/profile.d/volclava.sh
if [ $? == 0 ]; then
echo -e "Congratulates, installation is done and enjoy the journey!"
fi
}
function addHosts2Cluster() {
hostList=$1
clusterFile=$2
if [[ -z "$hostList" ]] || [[ -z "$clusterFile" ]]; then
return 1
fi
if [ ! -e "$clusterFile" ]; then
return 1
fi
if [[ "$hostList" == *"/"* ]]; then
#from file
if [ ! -f "$hostList" ];then
echo "$hostList not exist, failed to add hosts to ${clusterFile}"
return 1
fi
hostnames=($(cat $hostList))
else
hostnames=($(echo $hostList))
fi
found_place=false
line_number=0
while read line; do
((line_number++))
trimmed_line=$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [[ "$trimmed_line" == HOSTNAME* ]]; then
found_place=true
fi
if [ "$found_place" == true ]; then
for hostname in "${hostnames[@]}"; do
sed -i "${line_number}a\\${hostname} IntelI5 linux 1 3.5 (cs)" $clusterFile
((line_number++))
done
break
fi
done < $clusterFile
return 0
}
function install() {
if [ "$TYPE" = "code" ]; then
# install volclava from source code
#setup automake
./bootstrap.sh --prefix=$PREFIX
#make and install
if [ $? -eq 0 ]; then
make
else
echo "Failed to setup autoconf and automake ..."
exit 1
fi
if [ $? -eq 0 ]; then
make install
else
echo "Failed to execute make ..."
exit 1
fi
chown volclava:volclava -R $PREFIX
chmod 755 -R $PREFIX
#append hosts into lsf.cluster file
if [ ! -z "$HOSTS" ]; then
addHosts2Cluster "$HOSTS" ${PREFIX}/etc/lsf.cluster.volclava
fi
elif [ "$TYPE" = "deb" ]; then
#deb way to install volclava
chmod 755 bootstrap.sh
#create deb under ../
dpkg-buildpackage -b -rfakeroot -us -uc
if [ $? -ne 0 ]; then
echo "Failed to create volclava deb package. Please check."
exit 1
fi
#install volclava from deb package
if dpkg -l | grep volclava > /dev/null 2>&1; then
dpkg -P volclava
fi
if [ $setPrefix -ne 0 ]; then
#install deb with prefix
dpkg -x ../volclava_1.0*.deb $PREFIX
#append hosts into lsf.cluster file
if [ ! -z "$HOSTS" ]; then
addHosts2Cluster "$HOSTS" ${PREFIX}/opt/${PACKAGE_NAME}/etc/lsf.cluster.volclava
fi
sed -i "s|/opt/${PACKAGE_NAME}|${PREFIX}/opt/${PACKAGE_NAME}|g" $(grep -rl /opt/${PACKAGE_NAME} ${PREFIX}/)
chown volclava:volclava -R $PREFIX
chmod 755 -R $PREFIX
else
dpkg -i ../volclava_1.0*.deb
#append hosts into lsf.cluster file
if [ ! -z "$HOSTS" ]; then
addHosts2Cluster "$HOSTS" /opt/${PACKAGE_NAME}/etc/lsf.cluster.volclava
fi
fi
else
#rpm way to install volclava
if which yum > /dev/null 2>&1; then
if ! yum list installed rpm-build >/dev/null 2>&1; then
yum install -y rpm-build
fi
if ! yum list installed rpmdevtools >/dev/null 2>&1; then
yum install -y rpmdevtools
fi
else
echo "Failed to find yum ..."
exit 1
fi
chmod 755 rpm.sh
chmod 755 bootstrap.sh
#create rpm under ~/rpmbuild/RPMS/x86-64
./rpm.sh
if [ $? -ne 0 ]; then
echo "Failed to create volclava rpm package. Please check."
exit 1
fi
#install volclava from rpm package
cd ~/rpmbuild/RPMS/x86_64/
chmod 755 volclava-1.0*
if rpm -qa | grep volclava-1.0* > /dev/null 2>&1; then
rpm -e volclava-1.0*
fi
rpm -ivh --prefix $PREFIX volclava-1.0*
#append hosts into lsf.cluster file
if [ ! -z "$HOSTS" ]; then
addHosts2Cluster "$HOSTS" ${PREFIX}/${PACKAGE_NAME}/etc/lsf.cluster.volclava
fi
fi
}
if [ "$PHASE" == "pre" ]; then
pre_setup
echo "Preparation is done. You can use \"volcinstall.sh --setup=install ...\" to install the package"
elif [ "$PHASE" == "install" ]; then
install
if [ "$TYPE" == "code" ]; then
echo -e "The volclava is installed under ${PREFIX}\nYou can use the following command to enable services to startup and add environment variables automatically on master and computing nodes: \n$0 --setup=post --env=${PREFIX}"
else
echo -e "The volclava is installed under ${PREFIX}/${PACKAGE_NAME}\nYou can use the following command to enable services to startup and add environment variables automatically other computing nodes:\n$0 --setup=post --env=${PREFIX}/${PACKAGE_NAME}"
fi
elif [ "$PHASE" == "post" ]; then
post_setup
elif [ "$PHASE" == "pre-post" ]; then
pre_setup
post_setup
elif [ "$PHASE" == "all" ]; then
pre_setup
install
post_setup
else
echo "Failed to install volclava ..."
exit 1
fi
exit 0