updating ec2_init.sh file
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/6f19a147 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/6f19a147 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/6f19a147 Branch: refs/heads/master Commit: 6f19a14760a8a8f066efd6fbcf8a0934f5954cc8 Parents: 2622228 Author: Nirmal Fernando <[email protected]> Authored: Thu Feb 20 13:08:16 2014 +0530 Committer: Nirmal Fernando <[email protected]> Committed: Thu Feb 20 13:08:16 2014 +0530 ---------------------------------------------------------------------- tools/puppet/agent/root/bin/ec2_init.sh | 128 +++++++++++++++------------ 1 file changed, 72 insertions(+), 56 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6f19a147/tools/puppet/agent/root/bin/ec2_init.sh ---------------------------------------------------------------------- diff --git a/tools/puppet/agent/root/bin/ec2_init.sh b/tools/puppet/agent/root/bin/ec2_init.sh index 1ad8a21..1fe63bb 100644 --- a/tools/puppet/agent/root/bin/ec2_init.sh +++ b/tools/puppet/agent/root/bin/ec2_init.sh @@ -18,6 +18,13 @@ # specific language governing permissions and limitations # under the License. # +# This script will read SERVICE from the payload +# and do the following. +# - Set the hostname of the instance. +# - Configure the Puppet agent and restart the service. +# - Fetch deployment instructions and configs for this host +# from the Puppet master. +# # -------------------------------------------------------------- MKDIR=`which mkdir` @@ -46,7 +53,10 @@ HOSTSFILE=/etc/hosts HOSTNAMEFILE=/etc/hostname read_master() { - ${COMMAND} +# local COUNT=0 +# [ ${COUNT} == 10 ] && exit 1 || true + ${COMMAND} +# [ $? == 0 ] && true || (read_master ; COUNT=`expr ${COUNT} + 1`) } @@ -57,26 +67,27 @@ do wget http://169.254.169.254/latest/meta-data/public-ipv4 if [ ! -f public-ipv4 ] then - echo "Public ipv4 file not found. Sleep and retry" >> $LOG - sleep 2; - continue; + echo "Public ipv4 file not found. Sleep and retry" >> $LOG + sleep 2; + continue; else - echo "public-ipv4 file is available. Read value" >> $LOG - # Here means file is available. Read the file - read -r ip<public-ipv4; - echo "value is **[$ip]** " >> $LOG - - if [ -z "$ip" ] - then - echo "File is empty. Retry...." >> $LOG - sleep 2 - rm public-ipv4 - continue - else - echo "public ip is assigned. value is [$ip]. Remove file" >> $LOG - rm public-ipv4 - break - fi + "public-ipv4 file is available. Read value" >> $LOG + + # Here means file is available. Read the file + read -r ip<public-ipv4; + echo "Empty value is **$ip** " >> $LOG + + if [ -z "$ip" ] + then + echo "File is empty. Retry...." >> $LOG + sleep 2 + rm public-ipv4 + continue + else + echo "public ip is assigned.. value is [$ip]. Remove file" >> $LOG + rm public-ipv4 + break + fi fi done } @@ -87,45 +98,50 @@ RANDOMNUMBER="`${TR} -c -d 0-9 < /dev/urandom | ${HEAD} -c 4`${DATE}" if [ ! -d /tmp/payload ]; then - ## Check whether the public ip is assigned - is_public_ip_assigned - - echo "Public ip have assigned. Continue.." >> $LOG - - ## Clean old poop - ${ECHO} "Removing all existing certificates .." - #${FIND} /var/lib/puppet -type f -print0 | ${XARGS} -0r ${RM} - - ${MKDIR} -p /tmp/payload - ${WGET} http://169.254.169.254/latest/user-data -O /tmp/payload/launch-params - - cd /tmp/payload - SERVICE_NAME=`sed 's/,/\n/g' launch-params | grep SERVICE_NAME | cut -d "=" -f 2` - DEPLOYMENT=`sed 's/,/\n/g' launch-params | grep DEPLOYMENT | cut -d "=" -f 2` - INSTANCE_HOSTNAME=`sed 's/,/\n/g' launch-params | grep HOSTNAME | cut -d "=" -f 2` - PUPPET_IP=`sed 's/,/\n/g' launch-params | grep PUPPET_IP | cut -d "=" -f 2` - HOST="${RANDOMNUMBER}.${DEPLOYMENT}.${SERVICE_NAME}" - ${ECHO} -e "\nNew hostname ${HOST}\n" - - ## Set the hostname - ${HOSTNAME} ${HOST} - ${ECHO} "${HOST}" > ${HOSTNAMEFILE} - ${ECHO} "${PUPPET_IP} demo.stratos.org" >> ${HOSTSFILE} - /etc/init.d/hostname start - -# ## Enable and restart Puppet -# ${SED} -i /etc/default/puppet -e 's/START=no/START=yes/' - /etc/init.d/puppet stop - - ${SLEEP} 5 - - ${PUPPETD} --enable + ## Check whether the public ip is assigned + is_public_ip_assigned + + "Public ip have assigned. Continue.." >> $LOG + + ## Clean old poop + ${ECHO} "Removing all existing certificates .." + #${FIND} /var/lib/puppet -type f -print0 | ${XARGS} -0r ${RM} + + ${MKDIR} -p /tmp/payload + ${WGET} http://169.254.169.254/latest/user-data -O /tmp/payload/launch-params + + cd /tmp/payload + SERVICE_NAME=`sed 's/,/\n/g' launch-params | grep SERVICE_NAME | cut -d "=" -f 2` + DEPLOYMENT=`sed 's/,/\n/g' launch-params | grep DEPLOYMENT | cut -d "=" -f 2` + INSTANCE_HOSTNAME=`sed 's/,/\n/g' launch-params | grep HOSTNAME | cut -d "=" -f 2` + #CLUSTER=`sed 's/,/\n/g' launch-params | grep CLUSTER | cut -d "=" -f 2` + PUPPET_IP=`sed 's/,/\n/g' launch-params | grep PUPPET_IP | cut -d "=" -f 2` + HOST="${RANDOMNUMBER}.${DEPLOYMENT}.${SERVICE_NAME}" + ${ECHO} -e "\nNew hostname ${HOST}\n" + + ## Set the hostname + ${HOSTNAME} ${HOST} + ${ECHO} "${HOST}" > ${HOSTNAMEFILE} +# ${ECHO} "${IP} ${HOST}" >> ${HOSTSFILE} + #${ECHO} "${IP} local.${INSTANCE_HOSTNAME}" >> ${HOSTSFILE} + #${ECHO} "${IP} bind.${INSTANCE_HOSTNAME}" >> ${HOSTSFILE} + #${ECHO} "${PUPPET_IP} ${INSTANCE_HOSTNAME}" >> ${HOSTSFILE} + ${ECHO} "${PUPPET_IP} s2demo.s2.wso2.com" >> ${HOSTSFILE} + /etc/init.d/hostname start + +# ## Enable and restart Puppet +# ${SED} -i /etc/default/puppet -e 's/START=no/START=yes/' + /etc/init.d/puppet stop + + ${SLEEP} 5 + + ${PUPPETD} --enable - read_master + read_master -# ${SLEEP} 15m +# ${SLEEP} 15m - ${PUPPETD} --disable + ${PUPPETD} --disable #${ECHO} "* * * * * root /root/bin/cron-hosts.sh" >> /etc/crontab fi
