1. 程式人生 > >linux下配置JRE和Tomcat環境變數

linux下配置JRE和Tomcat環境變數

 

#########################################
#!/bin/bash
#SCRIPT: installTomcat.sh
#AUTHOR:
#DATE: 2012-03-06
#PLATFORM: Not platform dependent
#PURPOSE: 安裝Tomcat,啟動成功:安裝成功;啟動失敗:安裝失敗;
#命令:./installTomcat.sh
#引數列表:
#返回值: 0: 安裝成功
#  1:安裝失敗
#########################################
######  DEFINE VARIABLES  #####
JRE=$1/ota/jre1.6.0_29
TOMCAT=$1/ota/apache-tomcat-6.0.29
destdirpath=$1
#設定Jre環境變數

SET_JRE=`cat /etc/profile | grep OTA_JRE=${JRE} | grep -v "#" | wc -l`
if [ ${SET_JRE} -eq 0 ]
then
 sed s/OTA_JRE=/#OTA_JRE=/g /etc/profile >  /tmp/profile.tmp
 echo export OTA_JRE=${JRE} >>/tmp/profile.tmp
 cp -f /tmp/profile.tmp /etc/profile
 rm -fr /tmp/profile.tmp
fi

  
#設定Tomcat環境變數
SET_TOMCAT=`cat /etc/profile | grep  TOMCAT_HOME=${TOMCAT} | grep -v "#" | wc -l`
if [ ${SET_TOMCAT} -eq 0 ]
then
 sed s/TOMCAT_HOME=/#TOMCAT_HOME=/g /etc/profile >  /tmp/profile.tmp
 echo export TOMCAT_HOME=${TOMCAT} >>/tmp/profile.tmp
 cp -f /tmp/profile.tmp /etc/profile
 rm -fr /tmp/profile.tmp
fi 
###########為Tomcat指定jre
cat >>$destdirpath/ota/apache-tomcat-6.0.29/bin/setclasspath.sh<< TD 

export JRE_HOME=$(JRE)

TD

#啟動 Tomcat 

sh  $destdirpath/ota/apache-tomcat-6.0.29/bin/startup.sh  

sleep 5 

curl  127.0.0.1:8080  |grep   "Thanks for using Tomcat"

if  [ "$?" != 0 ] ; 
     then
          echo "I think install tomcat is unfinished  ."

     exit 1 

fi

#Add auto start開機自啟動 

sed -i '2a source /etc/profile' $destdirpath/ota/apache-tomcat-6.0.29/bin/startup.sh 

echo  "$destdirpath/ota/apache-tomcat-6.0.29//bin/startup.sh" >> /etc/rc.local