tomcat启动shell编写
2013-10-14 15:08
260 查看
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=$1
thome=${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
.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=$1
thome=${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
相关文章推荐
- 实现单Tomcat多Server配置
- 生产环境下的Tomcat配置
- 动态清空 nohup 输出文件
- install scrapy with pip and easy_install
- 文本处理工具AWK详解
- Linux Shell常用技巧
- Shell编程的一些知识集合
- linux Shell学习笔记第五天
- Perl 获取shell命令的执行结果
- Linux shell操作mysql数据库深入解析
- awk简介与学习笔记收集第1/3页
- Linux Shell简介
- javascript 面向对象编程 function是方法(函数)
- javascript 面向对象编程 function也是类
- IIS下PHP连接数据库提示mysql undefined function mysql_connect()
- IE 当eval遇上function的处理
- JavaScript中Object和Function的关系小结
- Javascript 使用function定义构造函数
- javascript Object与Function使用