#!/bin/bash
tc_home=/opt/oracle/tomcat/
instanceName=$1 【建立的執行個體】
cd .. >> /dev/null
template_dir=`pwd`
echo $template_dir
if [ ! -d $tc_home ] ;then
mkdir -p $tc_home 【目錄不存在就建立】
fi
usemethod(){
echo -e "Usage :sh creattcinstance instanceName
note: The instance name must be as the format:
tomcatServerXXX-X
shutdown port (10000 - 10100)
ajp port (8010 - 8079)
http port (8080 - 8190)
https port (8440 - 8540)
jmx port (6900 - 6970) "
}
insnum=`echo $instanceName | awk -F- '{print $2}'`
conffile="$tc_home""$instanceName"/conf/catalina.properties
if [ -n
"$insnum" ];then 【-n表示非空串】
cp -rf $template_dir $tc_home$instanceName
【將目前的目錄中的檔案拷貝到新建立的執行個體中】
echo "shutdown.port=1000$insnum" >> $conffile
echo "ajp.port=801$insnum" >> $conffile
echo "http.port=808$insnum" >> $conffile
echo "https.port=804$insnum" >> $conffile
echo "jmx.port=690$insnum" >> $conffile
else
echo "Warn,please define your instance name in right format."
exit
fi
if [ -f "$conffile" ] ; then
sed -i 's/^M//' $conffile 【刪除亂碼,注意這個字元可以按住ctrl鍵,然後按vm就會出現】
echo "New instance $instanceName has successfully builded, and "
grep port $conffile 【將建立的那幾個連接埠的相關資訊輸出】
else
usemethod
exit
fi
cat >> ~/start_$instanceName.sh << EOF
#!/bin/sh
cd /opt/oracle/tomcat/$instanceName/bin
sh catalina.sh start
tail -f /opt/oracle/tomcat/$instanceName/logs/catalina.out
EOF
cat >> ~/stop_$instanceName.sh << EOF
#!/bin/sh
cd /opt/oracle/tomcat/$instanceName/bin
sh catalina.sh stop
tail -f /opt/oracle/tomcat/$instanceName/logs/catalina.out
EOF