/
prepare-mapr-image.sh
executable file
·749 lines (618 loc) · 21.3 KB
/
prepare-mapr-image.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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
#! /bin/bash
#
# leveraged from mapr_imager.sh
#
# Script to be executed on top of a newly created Linux instance
# to install MapR components for an instance image to be used later.
# The specific packages can be passed in via meta data (see maprpackages
# below)
#
# The resulting image will be used as a basis for configure-mapr-instance.sh
# See that script for the steps that need to be done BEFORE this node
# can successfully run MapR services.
#
# Expectations:
# - Script run as root user (hence no need for permission checks)
# - Basic distro differences (APT-GET vs YUM, etc) can be handled
# There are so few differences, it seemed better to manage one script.
#
# Tested with MapR 2.x, 3.x, and 4.x
#
# JAVA
# This script defaults to OpenJDK; the logic to support Oracle JDK
# is included for users who which to implicitly accept Oracle's
# end-user license agreement.
#
# This instance may have been just started.
# Allow ample time for the network and setup processes to settle.
sleep 10
# Metadata for this installation ... pull out details that we'll need
#
# Note: The official release of GCE requires extra HTTP headers to
# satisfy the metadata requests.
#
murl_top=http://metadata/computeMetadata/v1
murl_attr="${murl_top}/instance/attributes"
md_header="Metadata-Flavor: Google"
THIS_FQDN=$(curl -H "$md_header" -f $murl_top/instance/hostname)
if [ -z "${THIS_FQDN}" ] ; then
THIS_HOST=${THIS_FQDN/.*/}
else
THIS_HOST=`/bin/hostname`
fi
THIS_IMAGE=$(curl -H "$md_header" -f $murl_attr/image) # name of initial image loaded here
GCE_PROJECT=$(curl -H "$md_header" -f $murl_top/project/project-id)
# NOTE: We could be smart and look to see if THIS_IMAGE was a
# MapR image, and bail on all the rest of this script.
# Definitions for our installation
# These should use the same meta-data definitions as the configure-* script
#
MAPR_HOME=$(curl -H "$md_header" -f $murl_attr/maprhome) # software installation directory
MAPR_HOME=${MAPR_HOME:-"/opt/mapr"}
MAPR_UID=$(curl -H "$md_header" -f $murl_attr/mapruid)
MAPR_UID=${MAPR_UID:-"2000"}
MAPR_USER=$(curl -H "$md_header" -f $murl_attr/mapruser)
MAPR_USER=${MAPR_USER:-"mapr"}
MAPR_GROUP=$(curl -H "$md_header" -f $murl_attr/maprgroup)
MAPR_GROUP=${MAPR_GROUP:-"mapr"}
MAPR_PASSWD=$(curl -H "$md_header" -f $murl_attr/maprpasswd)
MAPR_PASSWD=${MAPR_PASSWD:-"MapR"}
MAPR_VERSION=$(curl -H "$md_header" -f $murl_attr/maprversion)
MAPR_VERSION=${MAPR_VERSION:-"4.1.0"}
MAPR_PACKAGES=$(curl -H "$md_header" -f $murl_attr/maprpackages)
MAPR_PACKAGES=${MAPR_PACKAGES:-"core,fileserver"}
MAPR_PACKAGES=${MAPR_PACKAGES//:/,}
TRAINING_UID=$(curl -H "$md_header" -f $murl_attr/traininguid)
TRAINING_UID=${TRAINING_UID:-"4000"}
LOG=/tmp/prepare-mapr-image.log
OUT=/tmp/prepare-mapr-image.out
# Extend the PATH. This shouldn't be needed after Compute leaves beta.
PATH=/sbin:/usr/sbin:$PATH
# Helper utility to log the commands that are being run and
# save any errors to a log file
# BEWARE : any error forces the script to exit
# Since there are some some errors that we can live with,
# this helper script is not used for all operations.
#
# BE CAREFUL ... this function cannot handle command lines with
# their own redirection.
c() {
echo $* >> $LOG
$* || {
echo "============== $* failed at "`date` >> $LOG
exit 1
}
}
# For CentOS, add the EPEL repo
# NOTE: this target will change FREQUENTLY !!!
#
function add_epel_repo() {
EPEL_RPM=/tmp/epel.rpm
if [ `which lsb_release 2> /dev/null` ] ; then
CVER=`lsb_release -r | awk '{print $2}'`
elif [ -f /etc/centos-release ] ; then
CVER=`grep -o '[0-9]*' /etc/centos-release | head -1`
fi
CVER=${CVER:-6}
if [ ${CVER%.*} -eq 5 ] ; then
EPEL_LOC="epel/5/x86_64/epel-release-5-4.noarch.rpm"
elif [ "${CVER%.*}" -eq 7 ] ; then
EPEL_LOC="epel/7/x86_64/e/epel-release-7-5.noarch.rpm"
else
EPEL_LOC="epel/6/x86_64/epel-release-6-8.noarch.rpm"
fi
epel_def=/etc/yum.repos.d/epel.repo
if [ -f $epel_def ] ; then
grep -q "^enabled=1" $epel_def
if [ $? -ne 0 ] ; then
sed -i '0,/^enabled=0/s/enabled=0/enabled=1/' $epel_def
fi
else
curl -L -f -o $EPEL_RPM http://download.fedoraproject.org/pub/$EPEL_LOC
[ $? -eq 0 ] && rpm --quiet -i $EPEL_RPM
fi
}
# The "customized" debian distributions often have configuration
# files that should not be overwritten during the upgrade process.
# We need the Dpkg::Options arg so that we don't get an error
# during the upgrad operation that will cause us to bail out
# right away.
function update_os_deb() {
apt-get update
# c apt-get upgrade -y -o Dpkg::Options::="--force-confdef,confold"
c apt-get install -y nfs-common iputils-arping libsysfs2
c apt-get install -y ntp
c apt-get install -y syslinux sdparm
c apt-get install -y sysstat
apt-get install -y dnsutils less lsof
apt-get install -y clustershell pdsh realpath
[ -f /etc/debian_version ] && touch /etc/init.d/.legacy-bootordering
}
# For CentOS and Fedora, the GCE environment does not support
# plugin modules to be added to the kernel ... so we don't
# need the module-init-tools package. Moreover, on several
# occasions, updating that module cause strange behavior during
# instance launch.
function update_os_rpm() {
add_epel_repo
yum makecache
# c yum update -y --exclude=module-init-tools
c yum install -y nfs-utils iputils libsysfs
c yum install -y ntp ntpdate
c yum install -y syslinux sdparm
c yum install -y sysstat
yum install -y bind-utils less lsof
yum install -y clustershell pdsh
}
# Make sure that NTP service is sync'ed and running
# Key Assumption: the /etc/ntp.conf file is reasonable for the
# hosting cloud platform. We could shove our own NTP servers into
# place, but that seems like a risk.
#
# NOTE: This does not handle the latest systemctl model.
# TBD : fix for CentOS 7
function update_ntp_config() {
echo " updating NTP configuration" >> $LOG
# Make sure the service is enabled at boot-up
if [ -x /etc/init.d/ntp ] ; then
SERVICE_SCRIPT=/etc/init.d/ntp
update-rc.d ntp enable
elif [ -x /etc/init.d/ntpd ] ; then
SERVICE_SCRIPT=/etc/init.d/ntpd
chkconfig ntpd on
else
return 0
fi
$SERVICE_SCRIPT stop
ntpdate pool.ntp.org
$SERVICE_SCRIPT start
# TBD: copy in /usr/share/zoneinfo file based on
# zone in which the instance is deployed
zoneInfo=$(curl -f ${murl_top}/zone)
curZone=`basename "${zoneInfo}"`
curTZ=`date +"%Z"`
echo " Instance zone is $curZone; TZ setting is $curTZ" >> $LOG
# Update the timezones we're sure of.
TZ_HOME=/usr/share/zoneinfo/posix
case $curZone in
europe-west*)
newTZ="CET"
;;
us-central*)
newTZ="CST6CDT"
;;
us-east*)
newTZ="EST5EDT"
;;
*)
newTZ=${curTZ}
esac
if [ -n "${newTZ}" -a -f $TZ_HOME/$newTZ -a "${curTZ}" != "${newTZ}" ]
then
echo " Updating TZ to $newTZ" >> $LOG
cp -p $TZ_HOME/$newTZ /etc/localtime
fi
}
function update_ssh_config() {
echo " updating SSH configuration" >> $LOG
SSHD_CONFIG=/etc/ssh/sshd_config
# allow ssh via keys (some virtual environments disable this)
sed -i 's/#AuthorizedKeysFile/AuthorizedKeysFile/' $SSHD_CONFIG
# allow roaming (GCE disabled this in 2014 ... for unknown reasons)
sed -i 's/^#[ ]*HostbasedAuthentication.*/HostbasedAuthentication yes/g' $SSHD_CONFIG
# For Dev Clusters ONLY !!!
# allow ssh password prompt (only for our dev clusters)
# root login via passwordless ssh
sed -i 's/ChallengeResponseAuthentication .*no$/ChallengeResponseAuthentication yes/' $SSHD_CONFIG
sed -i 's/PasswordAuthentication .*no$/PasswordAuthentication yes/' $SSHD_CONFIG
sed -i 's/PermitRootLogin .*no$/PermitRootLogin yes/' $SSHD_CONFIG
[ service ssh status &> /dev/null ] && service ssh restart
[ service sshd status &> /dev/null ] && service sshd restart
}
function update_os() {
echo "Installing OS security updates and useful packages" >> $LOG
if which dpkg &> /dev/null; then
update_os_deb
elif which rpm &> /dev/null; then
update_os_rpm
fi
# raise TCP rbuf size
echo 4096 1048576 4194304 > /proc/sys/net/ipv4/tcp_rmem
# sysctl -w vm.overcommit_memory=1 # swap behavior
# SElinux gets in the way of older MapR installs (1.2)
# as well as MySQL (if we want a non-standard data directory)
# Be sure to disable it IMMEDIATELY for the rest of this
# process; the change to SELINUX_CONFIG will ensure the
# change across reboots.
SELINUX_CONFIG=/etc/selinux/config
if [ -f $SELINUX_CONFIG ] ; then
sed -i 's/^SELINUX=enforcing/SELINUX=permissive/' $SELINUX_CONFIG
[ -d /selinux ] && echo 0 > /selinux/enforce
fi
update_ntp_config
update_ssh_config
}
# Whatever version of Java we want, we can do here. The
# OpenJDK is a little easier because the mechanism for accepting
# the Oracle JVM EULA changes frequently.
#
# Be sure to add the JAVA_HOME to our environment ... we'll use it later
function install_oraclejdk_deb() {
echo "Installing Oracle JDK (for deb distros)" >> $LOG
apt-get install -y python-software-properties
add-apt-repository -y ppa:webupd8team/java
apt-get update
echo debconf shared/accepted-oracle-license-v1-1 select true | \
debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | \
debconf-set-selections
apt-get install -y x11-utils
apt-get install -y oracle-jdk7-installer
if [ $? -ne 0 ] ; then
echo " Oracle JDK installation failed" >> $LOG
return 1
fi
# update-java-alternatives -s java-7-oracle
JAVA_HOME=/usr/lib/jvm/java-7-oracle
export JAVA_HOME
echo " JAVA_HOME=$JAVA_HOME"
return 0
}
function install_openjdk_deb() {
echo "Installing OpenJDK packages (for deb distros)" >> $LOG
apt-get install -y x11-utils
# The GCE Debian 6 image doesn't have a repo enabled for
# Java 7 ... stick with Java 6 fo that version
deb_version=`cat /etc/debian_version`
if [ -n "$deb_version" -a "${deb_version%%.*}" = "6" ] ; then
apt-get install -y openjdk-6-jdk openjdk-6-doc
JAVA_HOME=/usr/lib/jvm/java-6-openjdk
else
apt-get install -y openjdk-7-jdk openjdk-7-doc
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
fi
export JAVA_HOME
echo " JAVA_HOME=$JAVA_HOME" >> $LOG
}
function install_oraclejdk_rpm() {
echo "Installing Oracle JDK (for rpm distros)" >> $LOG
JDK_RPM="http://download.oracle.com/otn-pub/java/jdk/7u75-b13/jdk-7u75-linux-x64.rpm"
$(cd /tmp; curl -f -L -C - -b "oraclelicense=accept-securebackup-cookie" -O $JDK_RPM)
RPM_FILE=/tmp/`basename $JDK_RPM`
if [ ! -s $RPM_FILE ] ; then
echo " Downloading Oracle JDK failed" >> $LOG
return 1
fi
rpm -ivh $RPM_FILE
if [ $? -ne 0 ] ; then
echo " Oracle JDK installation failed" >> $LOG
return 1
fi
JAVA_HOME=/usr/java/latest
export JAVA_HOME
echo " JAVA_HOME=$JAVA_HOME" | tee -a $LOG
return 0
}
function install_openjdk_rpm() {
echo "Installing OpenJDK packages (for rpm distros)" >> $LOG
yum install -y java-1.7.0-openjdk java-1.7.0-openjdk-devel
# yum install -y java-1.7.0-openjdk-javadoc
jcmd=`readlink -f /usr/bin/java`
JAVA_HOME=${jcmd%/bin/java}
[ -z "${JAVA_HOME}" ] && JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk
export JAVA_HOME
echo " JAVA_HOME=$JAVA_HOME" >> $LOG
}
# This has GOT TO SUCCEED ... otherwise the node is useless for MapR
function install_java() {
echo Installing JAVA >> $LOG
# If Java is already installed, simply set JAVA_HOME
# Should check for Java version, but both 1.6 and 1.7 work.
#
javacmd=`which java`
if [ $? -eq 0 ] ; then
echo "JRE (and possibly JDK) already installed on this instance" >> $LOG
java -version 2>&1 | head -1 >> $LOG
# We could be linked to the JRE or JDK version; we want
# the REAL jdk, so look for javac in the directory we choose
jcmd=`python -c "import os; print os.path.realpath('$javacmd')"`
if [ -x ${jcmd%/jre/bin/java}/bin/javac ] ; then
JAVA_HOME=${jcmd%/jre/bin/java}
elif [ -x ${jcmd%/java}/javac ] ; then
JAVA_HOME=${jcmd%/bin/java}
else
JAVA_HOME=""
fi
if [ -n "${JAVA_HOME:-}" ] ; then
echo " JAVA_HOME=$JAVA_HOME" | tee -a $LOG
echo updating /etc/profile.d/javahome.sh >> $LOG
echo "JAVA_HOME=${JAVA_HOME}" > /etc/profile.d/javahome.sh
echo "export JAVA_HOME" >> /etc/profile.d/javahome.sh
return 0
fi
echo "Could not identify JAVA_HOME; will install JDK ourselves" >> $LOG
fi
if which dpkg &> /dev/null; then
install_oraclejdk_deb
[ $? -ne 0 ] && install_openjdk_deb
elif which rpm &> /dev/null; then
install_oraclejdk_rpm
[ $? -ne 0 ] && install_openjdk_rpm
fi
if [ -x $JAVA_HOME/bin/java ] ; then
echo Java installation complete >> $LOG
# Strip of jre just in case
JAVA_HOME="${JAVA_HOME%/jre}"
echo updating /etc/profile.d/javahome.sh >> $LOG
echo "JAVA_HOME=${JAVA_HOME}" > /etc/profile.d/javahome.sh
echo "export JAVA_HOME" >> /etc/profile.d/javahome.sh
# Update link to java in primary path if necessary
# We need to do this because the Oracle JDK installation
# DOES NOT overwrite the link to the OpenJDK JRE java
# (even as it creates /usr/bin links for every other component)
if [ -n "${javacmd:-}" ] ; then
javatarget=`readlink -f $javacmd`
jdktarget=`readlink -f $JAVA_HOME/bin/java`
if [ "$javatarget" != "$jdktarget" ] ; then
ln -f -s $JAVA_HOME/bin/java ${javacmd}
fi
elif [ ! -x /usr/bin/java ] ; then
ln -s $JAVA_HOME/bin/java /usr/bin/java
fi
else
echo Java installation failed >> $LOG
fi
}
function add_mapr_user() {
echo Adding/configuring mapr user >> $LOG
id $MAPR_USER &> /dev/null
if [ $? -eq 0 ] ; then
# If we passed a UID in as meta-data,
# now is the time to make sure it lines up
# with the pre-existing account.
# NOTE: we ONLY do this if a UID was passed in
target_uid=$(curl -f $murl_attr/mapruid)
if [ -n "${target_uid}" -a `id -u $MAPR_USER` -ne "${target_uid:-0}" ] ; then
echo "updating ${MAPR_USER} account to uid ${MAPR_UID}" >> $LOG
usermod -u ${target_uid} ${MAPR_USER}
groupmod -g ${target_uid} ${MAPR_USER}
fi
return 0
fi
echo "useradd -u $MAPR_UID -c MapR -m -s /bin/bash $MAPR_USER" >> $LOG
useradd -u $MAPR_UID -c "MapR" -m -s /bin/bash $MAPR_USER 2> /dev/null
if [ $? -ne 0 ] ; then
# Assume failure was dup uid; try with default uid assignment
echo "useradd returned $?; trying auto-generated uid" >> $LOG
useradd -c "MapR" -m -s /bin/bash $MAPR_USER
fi
if [ $? -ne 0 ] ; then
echo "Failed to create new user $MAPR_USER {error code $?}"
return 1
else
passwd $MAPR_USER << passwdEOF > /dev/null
$MAPR_PASSWD
$MAPR_PASSWD
passwdEOF
fi
# Create sshkey for $MAPR_USER (must be done AS MAPR_USER)
su $MAPR_USER -c "mkdir ~${MAPR_USER}/.ssh ; chmod 700 ~${MAPR_USER}/.ssh"
su $MAPR_USER -c "ssh-keygen -q -t rsa -f ~${MAPR_USER}/.ssh/id_rsa -P '' "
su $MAPR_USER -c "cp -p ~${MAPR_USER}/.ssh/id_rsa.pub ~${MAPR_USER}/.ssh/authorized_keys"
su $MAPR_USER -c "chmod 600 ~${MAPR_USER}/.ssh/authorized_keys"
# TBD : copy the key-pair used to launch the instance directly
# into the mapr account to simplify connection from the
# launch client.
MAPR_USER_DIR=`eval "echo ~${MAPR_USER}"`
# Enhance the login with rational stuff
cat >> $MAPR_USER_DIR/.bashrc << EOF_bashrc
CDPATH=.:$HOME
export CDPATH
# PATH updates based on settings in MapR env file
MAPR_HOME=${MAPR_HOME:-/opt/mapr}
MAPR_ENV=\${MAPR_HOME}/conf/env.sh
[ -f \${MAPR_ENV} ] && . \${MAPR_ENV}
[ -n "\${JAVA_HOME}:-" ] && PATH=\$PATH:\$JAVA_HOME/bin
[ -n "\${MAPR_HOME}:-" ] && PATH=\$PATH:\$MAPR_HOME/bin
set -o vi
EOF_bashrc
# Add MapR user to sudo group if it exists
grep -q -e "^sudo:" /etc/group
[ $? -eq 0 ] && usermod -G sudo $MAPR_USER
return 0
}
function add_training_users() {
echo Adding/configuring sample users for admin training >> $LOG
NUSERS=3
for (( i=1 ; i<=NUSERS ; i++ )) ; do
TUSER="user${i}"
TUSER_PASSWD="password${i}"
TUID=$[TRAINING_UID+$i]
echo "useradd -u $TUID -c AdminTraining -m -s /bin/bash $TUSER" >> $LOG
useradd -u $TUID -c "AdminTraining" -m -s /bin/bash $TUSER 2> /dev/null
if [ $? -ne 0 ] ; then
# Assume failure was dup uid; try with default uid assignment
echo "useradd returned $?; trying auto-generated uid" >> $LOG
useradd -c "AdminTraining" -m -s /bin/bash $TUSER
fi
if [ $? -ne 0 ] ; then
echo "Failed to create new user $TUSER {error code $?}"
else
passwd $TUSER << passwdEOF > /dev/null
$TUSER_PASSWD
$TUSER_PASSWD
passwdEOF
fi
done
return 0
}
function setup_mapr_repo_deb() {
MAPR_REPO_FILE=/etc/apt/sources.list.d/mapr.list
MAPR_PKG="http://package.mapr.com/releases/v${MAPR_VERSION}/ubuntu"
MAPR_ECO="http://package.mapr.com/releases/ecosystem/ubuntu"
major_ver=${MAPR_VERSION%%.*}
if [ ${major_ver:-3} -gt 3 ] ; then
MAPR_ECO=${MAPR_ECO//ecosystem/ecosystem-${major_ver}.x}
fi
echo Setting up repos in $MAPR_REPO_FILE
if [ ! -f $MAPR_REPO_FILE ] ; then
cat > $MAPR_REPO_FILE << EOF_ubuntu
deb $MAPR_PKG mapr optional
deb $MAPR_ECO binary/
EOF_ubuntu
else
sed -i "s|/releases/v.*/|/releases/v${MAPR_VERSION}/|" $MAPR_REPO_FILE
fi
apt-get update
}
function setup_mapr_repo_rpm() {
MAPR_REPO_FILE=/etc/yum.repos.d/mapr.repo
MAPR_PKG="http://package.mapr.com/releases/v${MAPR_VERSION}/redhat"
MAPR_ECO="http://package.mapr.com/releases/ecosystem/redhat"
major_ver=${MAPR_VERSION%%.*}
if [ ${major_ver:-3} -gt 3 ] ; then
MAPR_ECO=${MAPR_ECO//ecosystem/ecosystem-${major_ver}.x}
fi
echo Setting up repos in $MAPR_REPO_FILE
if [ -f $MAPR_REPO_FILE ] ; then
sed -i "s|/releases/v.*/|/releases/v${MAPR_VERSION}/|" $MAPR_REPO_FILE
yum makecache
return
fi
cat > $MAPR_REPO_FILE << EOF_redhat
[MapR]
name=MapR Version $MAPR_VERSION media
baseurl=$MAPR_PKG
${MAPR_PKG//package.mapr.com/archive.mapr.com}
enabled=1
gpgcheck=0
protected=1
[MapR_ecosystem]
name=MapR Ecosystem Components
baseurl=$MAPR_ECO
${MAPR_ECO//package.mapr.com/archive.mapr.com}
enabled=1
gpgcheck=0
protected=1
EOF_redhat
yum makecache
}
function setup_mapr_repo() {
if which dpkg &> /dev/null; then
setup_mapr_repo_deb
MAPRGPG_KEY=/tmp/maprgpg.key
wget -O $MAPRGPG_KEY http://package.mapr.com/releases/pub/maprgpg.key
[ $? -eq 0 ] && apt-key add $MAPRGPG_KEY
elif which rpm &> /dev/null; then
setup_mapr_repo_rpm
rpm --import http://package.mapr.com/releases/pub/maprgpg.key
fi
}
# Helper utility to update ENV settings in env.sh.
# Function is replicated in the configure-mapr-instance.sh script.
# Function WILL NOT override existing settings ... it looks
# for the default "#export <var>=" syntax and substitutes the new value
#
# NOTE: this updates ONLY the env variables that are commented out
# within env.sh. It WILL NOT overwrite active settings. This is
# OK for our current deployment model, but may not be sufficient in
# all cases.
MAPR_ENV_FILE=$MAPR_HOME/conf/env.sh
update_env_sh()
{
[ -z "${1:-}" ] && return 1
[ -z "${2:-}" ] && return 1
AWK_FILE=/tmp/ues$$.awk
cat > $AWK_FILE << EOF_ues
/^#export ${1}=/ {
getline
print "export ${1}=$2"
}
{ print }
EOF_ues
cp -p $MAPR_ENV_FILE ${MAPR_ENV_FILE}.imager_save
awk -f $AWK_FILE ${MAPR_ENV_FILE} > ${MAPR_ENV_FILE}.new
[ $? -eq 0 ] && mv -f ${MAPR_ENV_FILE}.new ${MAPR_ENV_FILE}
}
install_mapr_packages() {
mpkgs=""
for pkg in `echo ${MAPR_PACKAGES//,/ }`
do
mpkgs="$mpkgs mapr-$pkg"
done
echo Installing MapR base components {$MAPR_PACKAGES} >> $LOG
if which dpkg &> /dev/null; then
c apt-get install -y --force-yes $mpkgs
elif which rpm &> /dev/null; then
c yum install -y $mpkgs
fi
echo Configuring $MAPR_ENV_FILE >> $LOG
update_env_sh MAPR_HOME $MAPR_HOME
update_env_sh JAVA_HOME $JAVA_HOME
}
#
# Disable starting of MAPR, and clean out the ID's that will be intialized
# with the full install.
# NOTE: the instantiation process from an image generated via
# this script MUST recreate the hostid and hostname files
#
function disable_mapr_services()
{
echo Temporarily disabling MapR services >> $LOG
mv -f $MAPR_HOME/hostid $MAPR_HOME/conf/hostid.image
mv -f $MAPR_HOME/hostname $MAPR_HOME/conf/hostname.image
if which dpkg &> /dev/null; then
update-rc.d -f mapr-warden disable
echo $MAPR_PACKAGES | grep -q zookeeper
if [ $? -eq 0 ] ; then
update-rc.d -f mapr-zookeeper disable
fi
elif which rpm &> /dev/null; then
chkconfig mapr-warden off
echo $MAPR_PACKAGES | grep -q zookeeper
if [ $? -eq 0 ] ; then
chkconfig mapr-zookeeper off
fi
fi
}
# High level wrapper around the above scripts.
# Ideally, we should handle errors correctly here.
#
# Remember that this script is used in two different circumstances:
# 1. to initialize nodes for the training class
# 2. as part of a full MapR installation
# (invoked by configure-mapr-instance.sh)
#
main() {
# Do nothing if we've been run on a previous instance startup
# (GCE has the behavior of running "startup-script"
# every time an instance is started).
[ -f /var/log/`basename $LOG` ] && exit 0
echo "Image creation started at "`date` >> $LOG
update_os
install_java
if [ "$MAPR_PACKAGES" = "none" ] ; then
add_training_users
else
add_mapr_user
setup_mapr_repo
install_mapr_packages
disable_mapr_services
fi
echo "Image creation completed at "`date` >> $LOG
echo IMAGE READY >> $LOG
return 0
}
main
exitCode=$?
# Save of the install log to /var/log and ~${MAPR_USER}; some cloud
# images use AMI's that automatically clear /tmp with every reboot
cp $LOG /var/log
MAPR_USER_DIR=`eval "echo ~${MAPR_USER}"`
if [ -n "${MAPR_USER_DIR}" -a -d ${MAPR_USER_DIR} ] ; then
cp $LOG $MAPR_USER_DIR
chmod a-w ${MAPR_USER_DIR}/`basename $LOG`
chown ${MAPR_USER}:`id -gn ${MAPR_USER}` \
${MAPR_USER_DIR}/`basename $LOG`
fi
exit $exitCode