当tarball执行时候,它是如何判断这个节点所处的环境是qa,还是production 抑或是dev呢?显然,如果让管理员一个一个分配的话,那么将非常容易错,所幸的是,所有的不同环境的机器都分配在不同的network segment中,所以我们可以让脚本获得dnsdomainname的信息,然后进行加工来轻松获取环境信息:
- touch /tmp/dnsdomainname.txt
- dnsdomainname > /tmp/dnsdomainname.txt
- #get the dnsdomainname
- DNSDOMAINNAME=`cat /tmp/dnsdomainname.txt`
- echo "DNSDOMAINNAME is : $DNSDOMAINNAME"
- rm -r /tmp/dnsdomainname.txt
- #make decision of the environment based on the dnsdomainname
- DEV_KEYWORD="dev"
- QA_KEYWORD="qa"
- PROD_KEYWORD="prod"
- declare -i IS_DEV_ENV
- declare -i IS_QA_ENV
- declare -i IS_PROD_ENV
- IS_DEV_ENV=`echo $DNSDOMAINNAME | grep $DEV_KEYWORD | wc -l`
- IS_QA_ENV=`echo $DNSDOMAINNAME | grep $QA_KEYWORD | wc -l`
- IS_PROD_ENV=`echo $DNSDOMAINNAME | grep $PROD_KEYWORD | wc -l`
- # Download from Storage
- if [ "$IS_DEV_ENV" -gt "$ZERO" ];
- then
- ENVIRONMENT_TYPE=dev
- LIFERAY_TOMCAT_BUNDLE_DOWNLOAD_ADDR="http://10.242.8.206:4227/storage/paas/installer/liferay/community-edition-liferay-portal-tomcat-6.1.0.zip"
- echo "the environment of this machine is dev "
- elif [ "$IS_QA_ENV" -gt "$ZERO" ];
- then
- ENVIRONMENT_TYPE=qa
- LIFERAY_TOMCAT_BUNDLE_DOWNLOAD_ADDR="http://10.242.8.206:4227/storage/paas/installer/liferay/community-edition-liferay-portal-tomcat-6.1.0.zip"
- echo "the environment of this machine is qa"
- elif [ "$IS_PROD_ENV" -gt "$ZERO" ];
- then
- ENVIRONMENT_TYPE=prod
- LIFERAY_TOMCAT_BUNDLE_DOWNLOAD_ADDR=http://ndc-staas-app1.prod.gecwalmart.com:4227/storage/paas/installer/liferay/community-edition-liferay-portal-tomcat-6.1.0.zip
- echo "the environment of this machine is prod"
- else
- #the default one ,the environment is dev
- ENVIRONMENT_TYPE=dev
- LIFERAY_TOMCAT_BUNDLE_DOWNLOAD_ADDR="http://10.242.8.206:4227/storage/paas/installer/liferay/community-edition-liferay-portal-tomcat-6.1.0.zip"
- echo "the environment of this machine is dev"
- fi
-
- echo "The liferay tomcat bundle zip file is accessable from $LIFERAY_TOMCAT_BUNDLE_DOWNLOAD_ADDR"
从这里可以看出,(01-11行)我的思路是首先把dnsdomainname的输出读到一个临时文件中,并用cat读取这个文件,然后删除临时文件:
然后对于读取的内容,因为我们已经有了一些约定,所以可以很轻松的识别出这个机器所处的环境,(15-39行)方法是看这个dnsdomainname中是否有"qa","prod","dev"的字眼出现。
最终当识别出环境之后,我们就可以吧环境保存到变量中,并且被configure.sh中所使用了。当然了,这个环境的不同还会影响到tomcat zip bundle下载地址的不同。
本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/979805,如需转载请自行联系原作者