欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

自动修改war配置文件,自动部署 部署 

程序员文章站 2024-03-13 08:56:39
...
##打开war文件
rm -rf /upload/app/temp
mkdir /upload/app/temp
cd /upload/app/temp
cp /upload/app/SCM.war /upload/app/temp/
jar xvf /upload/app/temp/SCM.war
rm -rf /upload/app/temp/SCM.war
##拷贝配置文件
sh /upload/config.sh

##重新打包
cd /upload/app/temp
jar -cvfM0 /upload/app/temp/dabichong.war  ./*

##备份文件到/upload/app_bak
##jar -cvfM0 dabichong.war  /usr/share/tomcat/apache-tomcat-7.0.22/
cp /usr/share/tomcat/apache-tomcat-7.0.22/webapps/dabichong.war /upload/app_bak/dabichong_$(date +%Y%m%d-%H%M%S).war
rm -rf /usr/share/tomcat/apache-tomcat-7.0.22/webapps/dabichong.war
rm -rf /usr/share/tomcat/apache-tomcat-7.0.22/webapps/dabichong

##重启tomcat
sh /usr/share/tomcat/apache-tomcat-7.0.22/bin/shutdown.sh
cp /upload/app/temp/dabichong.war /usr/share/tomcat/apache-tomcat-7.0.22/webapps/dabichong.war
sh /usr/share/tomcat/apache-tomcat-7.0.22/bin/startup.sh



==================config.sh========================
cp -r -f /upload/config/open.top.properties  /upload/app/temp/WEB-INF/classes/com/hupun/scm/top/open.top.properties


=================备份脚本============================

tomcat_path=/home/apache-tomcat-7.0.22
upload_path=/upload
upload_app_path=${upload_path}/app
back_db_path=${upload_path}/sql
alter_db_bak_path=${upload_path}/sql_bak
alter_sql_file=${upload_app_path}/alter_$(date +%Y_%m_%d).sql

##备份文件到${upload_app_path}_bak
cp ${tomcat_path}/webapps/scm.war ${upload_app_path}_bak/scm_$(date +%Y%m%d-%H%M%S).war
echo 'app backup ok'


##备份数据库文件
sh ${back_db_path}/backupDb.sh
echo 'backup ok'

##判断当天的更新脚本是否存在
if [ -f "$alter_sql_file" ]; then
  echo "$alter_sql_file exist add sql"
  mysql -uxxxx -pxxxx scm_xxxx < $alter_sql_file
  cp -rf $alter_sql_file $alter_db_bak_path/alter_$(date +%Y%m%d-%H%M%S).sql
  rm -rf $alter_sql_file
  echo '---------update db ok----------'
else
  echo "---------not exist alert sql-------"
fi


-----------------------ftp拉去文件脚本ftpGet.sh---------------------------


#!/bin/sh
F="xxxx.ftp"
echo "open hupun.xxxx.xxxx 21"     > $F
echo "user hupun xxxx"     >> $F
echo "bin"                      >> $F
#echo "cd /upload/app"            >> $F
echo "mget $1 $2 $3"                  >> $F
echo "bye"                      >> $F
ftp  -in < $F
rm -rf $F


---------------------------ftpPut.sh-------------------------

#!/bin/sh
F="xxxx.ftp"
echo "open hupun.xxx.xxxx 21"     > $F
echo "user hupun xxxx"     >> $F
echo "bin"                      >> $F
#echo "cd /upload/app"            >> $F
echo "mput $1 $2 $3"                  >> $F
echo "bye"                      >> $F
ftp  -in < $F
rm -rf $F


==================================最新备份脚本==========================

tomcat_path=/home/apache-tomcat-7.0.22
upload_path=/upload
upload_app_path=${upload_path}/app
back_db_path=${upload_path}/sql
alter_db_bak_path=${upload_path}/sql_bak
alter_sql_file=${upload_app_path}/alter_bus_$(date +%Y_%m_%d).sql
app_file=wanliniu
upload_app_temp_path=/upload/app_bak/bak_temp
app_bak_path=/upload/app_bak

##备份war文件到${upload_app_path}_bak
##cp ${tomcat_path}/webapps/${app_file}.war ${upload_app_path}_bak/${app_file}_$(date +%Y%m%d-%H%M%S).war

##直接备份系统执行的包
rm -rf ${upload_app_temp_path}
mkdir ${upload_app_temp_path}
##拷贝文件
cp -a ${tomcat_path}/webapps/${app_file}/* ${upload_app_temp_path}/

cd ${upload_app_temp_path}
##压缩
jar -cvfM0 ${app_bak_path}/${app_file}_file_$(date +%Y%m%d-%H%M%S).war  ./*
cd ${upload_app_path}
echo 'app backup ok'


##备份数据库文件
sh ${back_db_path}/backupDb.sh
echo 'backup ok'

##判断当天的更新脚本是否存在
if [ -f "$alter_sql_file" ]; then
  echo "[warn]only update bus cur bus db:  you must check!!!!"
  echo "$alter_sql_file exist add sql"
  mysql -uroot -pxxxx -hxxx.xxx.xxx.xxx db_1 < $alter_sql_file
  mysql -uroot -pxxxx -hxxx.xxx.xxx.xxx db_2 < $alter_sql_file
  cp -rf $alter_sql_file $alter_db_bak_path/alter_bus_$(date +%Y%m%d-%H%M%S).sql
  rm -rf $alter_sql_file
  echo '---------update bus db ok----------'
else
  echo "---------not exist alert bus update sql-------"
fi


==================================================================

1.linux kill tomcat shell 脚本

#!/bin/sh
#kill tomcat pid
pidlist=`ps -ef|grep tomcat | grep -v "grep"|awk '{print $2}'`
#ps -u $USER|grep "java"|grep -v "grep"
echo "tomcat Id list :$pidlist"
if [ "$pidlist" = "" ]
then
  echo "no tomcat pid alive"
else
  for pid in ${pidlist}
{
   kill -9 $pid
echo "KILL $pid:"
echo "service stop success"
  }
fi



如果有提示 一个什么什么错误可以在

vi命令模式

原因这通常都是由于windows下对文本文件的保存格式与unix下不同造成的,windows下回车的字符是’\r\n’,而linux下是’\n’。2 解决方法vi file在命令模式下,输入 setff=? ,查看文件格式为dos或者unix,如:setff=unixw保存,即可



2.linux kill某一用户的所有tomcat进程

start.sh

#!/bin/sh

PRG="$0"
while [ -h "$PRG" ]; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

# Get standard environment variables
PRGDIR=`dirname "$PRG"`
TMS_HOME=`cd "$PRGDIR"/.. ; pwd`
$JAVA_HOME/bin/java -jar $TMS_HOME/bin/tms.jar

stop.sh

ps aufx|grep tomcat|grep 509|awk '{print $2}'|xargs kill -9  或

ps -ef|grep tms.jar|grep -v grep|awk '{print $2}'|xargs kill

509替换为要kill的用户名

有时直接用shutdown.sh关闭不了tomcat,要强制kill掉,但是可能tomcat启动了多次,进程里已经有了多个tomcat进程,一个一个关闭相当麻烦,可以使用以上命令一次性关闭某一个用户所有tomcat进程。



start.bat

@echo off
::cd %~dp0
echo Start Server ...
java -jar "%~sdp0tms.jar"
相关标签: 部署