1.环境变量配置
.bashrc 环境变量文件 如下:
echo ".bashrc loaded"
userhome=/home/dms-deployer
PATH=$PATH:$userhome
warshome=$userhome/wars
basehome=/opt/OriDms-Base-tomcat7
reporthome=/opt/OriDMS-Report-tomcat7
saleshome=/opt/OriDms-Sales-tomcat7
sfhome=/opt/OriDms-sf-tomcat7
sfwar=$warshome/OrionDMS-sf.war
#sflog=/home/logs/catelina.out
export basehome
export reporthome
export saleshome
export sfhome
export sfwar
export PATH
#export sflog
2.编写 tomcat 执行文件 如下:
#!/bin/sh
thomecp=$1thome=${thomecp%%/}
cmd="cmd usage:tomcat sf|sales|base|common start|restart|stop"
echo "================================================vars init start========================================================"
function setlog(){
#echo "test========>>>>$1"
if [ -f "$1" ]
then
echo "then test========>>>>$1"
tlog=$1
else
tlog="$thome/logs/catalina.out"
fi
}
function setwar(){
#echo "wars start======================>>,$wars,"
if [ -n "$1" ]
then
wars=$1
echo "then wars==================>>>,$wars,"
#elif [ -f "$thome/wars/*.war" ]
#then
else
wars="$thome/wars/*.war"
echo "war defualt path is $thome/wars/ "
#exit -1
fi
}
case $1 in
sf)
thome=$sfhome
setlog $sflog
setwar $sfwar
;;
common)
thome=$commonhome
setlog $commonlog
setwar $commonwar
;;
base)
thome=$basehome
setlog $baselog
setwar $basewar
;;
sales)
thome=$saleshome
setlog $baselog
setwar $basewar
;;
report)
thome=$reporthome
setlog $reportlog
setwar $reportwar
;;
*)
echo $cmd
;;
esac
webapps="$thome/webapps"
tbin="$thome/bin"
echo "tlog:$tlog"
echo "bin:$tbin"
echo "home:$thome"
echo "wars:$wars"
echo "webapps:$webapps"
echo "=============================================vars init end===================================================="
rmweb(){
ls $webapps|while read file
do
echo $webapps/$file
if [ -d $webapps/$file ]
then
echo "remove dir $webapps/$file"
rm -r $webapps/$file
fi
done
}
case $2 in
stop)
ps -ef |grep $thome|grep -v grep|grep -v $0|awk -F" " '{print $2}'|while read pid
do
sh "$tbin/shutdown.sh" 2>/dev/null
echo "stoping......$pid"
sleep 5
kill $pid
done
echo "stop is ok"
;;
start)
if ls $wars
then
$0 $1 stop
echo "prestart..............."
rmweb
ls $wars|if read wfile
then
cpfile=$webapps/${wfile##*/}
day=`date +%Y%m%d`
if [ ! -f $cpfile.$day ]
then
echo "copy file $cpfile to $cpfile.$day"
cp $cpfile $cpfile.$day
else
echo "$cpfile is already back"
fi
fi
echo "move file $wars to $webapps"
mv $wars $webapps/
echo "starting..................."
sh "$tbin/startup.sh"
tail -f $tlog
else
echo "error===================>>can't find war file in $wars"
exit -1
fi
;;
restart)
$0 $1 stop 2>/dev/null
sh "$tbin/startup.sh"
echo "restart......."
echo "tlog=====================================================>>>$tlog"
tail -f $tlog
;;
*)
echo $cmd
;;
esac
3.命令调用 如下:
dms-deployer@linux-dli3:~>tomcat sf start