[root@WEB1-live sh]# cat licai_fabu.sh #!/bin/bash pid=` ps -ef | grep java | grep '8011' | awk '{print $2}'` bak_date=`date +%y%m%d%H%M` JAVA_RUN="/usr/bin/java " pak_dir=/data/pro_fabu/front target_dir=/data/java_web_app/licai_live if [ -d ${target_dir} ];then echo "dir have exist" cp -rf ${target_dir}/webapps/root.war /data/bak_project/front/root_${bak_date}.war else echo "*****************************" echo "从jetty拷贝内容到目标目录下 " echo "*****************************" mkdir ${target_dir} cp -r /data/jetty/* ${target_dir} fi kill -9 ${pid} cp -rf ${pak_dir}/*.war ${target_dir}/webapps/root.war cd ${target_dir} #/usr/bin/java -jar start.jar jetty.port=6011 -DSTOP.PORT=7011 -DSTOP.KEY=bao_licai cd ${target_dir} output="CONSOLE" nohup ${JAVA_RUN} -jar start.jar -DSTOP.PORT=9011 -DSTOP.KEY=licai_live --stop >$output 2>&1 & nohup ${JAVA_RUN} -jar start.jar jetty.port=8011 -DSTOP.PORT=9011 -DSTOP.KEY=licai_live >$output 2>&1 & echo $? tail -10 $output /bin/sh /root/sh/scp_licai_war.sh
[root@WEB1-live sh]# cat scp_licai_war.sh #!/usr/bin/expect set ip 10.1.90.2 set pass Weddddu0.5 set timeout 30 #spawn ssh root@$ip spawn scp /data/pro_fabu/front/kzfinance-front.war root@10.1.90.2:/data/pro_fabu/front expect { "(yes/no)" {send "yes "; exp_continue} "password:" {send "$pass "} } #expect "root@*" {send "df -h "} #expect "root@*" {send "exit "} #expect eof spawn ssh root@$ip expect { "(yes/no)" {send "yes "; exp_continue} "password:" {send "$pass "} } expect "root@*" {send "/bin/sh /root/sh/start_front.sh "} expect "root@*" {send "exit "} expect eof
[root@WEB2-live sh]# cat start_front.sh #!/bin/bash pid=` ps -ef | grep java | grep '8011' | awk '{print $2}'` bak_date=`date +%y%m%d%H%M` JAVA_RUN="/usr/bin/java " pak_dir=/data/pro_fabu/front target_dir=/data/java_web_app/licai_live if [ -d ${target_dir} ];then echo "dir have exist" cp -rf ${target_dir}/webapps/root.war /data/bak_project/front/root_${bak_date}.war else echo "*****************************" echo "从jetty拷贝内容到目标目录下 " echo "*****************************" mkdir ${target_dir} cp -r /data/jetty/* ${target_dir} fi kill -9 ${pid} cp -rf ${pak_dir}/*.war ${target_dir}/webapps/root.war cd ${target_dir} #/usr/bin/java -jar start.jar jetty.port=6011 -DSTOP.PORT=7011 -DSTOP.KEY=bao_licai cd ${target_dir} output="CONSOLE" nohup ${JAVA_RUN} -jar start.jar -DSTOP.PORT=9011 -DSTOP.KEY=licai_live --stop >>$output 2>&1 & nohup ${JAVA_RUN} -jar start.jar jetty.port=8011 -DSTOP.PORT=9011 -DSTOP.KEY=licai_live >>$output 2>&1 & echo $? tail -10 $output
上面的脚本有点复杂,但是上面的脚本都是我使用jenkins需要用到的
下面记录一下以为大神写的发版脚本
[root@SVN-200-15 build]# cat build_live_licai.sh #!/bin/sh #项目打包发布脚本 #create by zgh 2016-3-2 #目标ip 12.9.15.2812.9.15.29 usage() { echo "Usage: cp-jetty.sh dir skip_mvn skip_svn build_or_restart" exit 1 } if [ $# -eq 0 ]; then usage fi DISTIBUTE_DIR="/home/build/" ACTION=$1 SKIP_MVN="true" SKIP_SVN="true" BUILD_OR_RESTART="true" #BUILD if [ $# -gt 1 ] && [ $2 = "false" ]; then SKIP_MVN="false" fi if [ $# -gt 2 ] && [ $3 = "false" ]; then SKIP_SVN="false" fi if [ $# -gt 3 ] && [ $4 = "false" ]; then BUILD_OR_RESTART="false" #RESTART fi #mkdir2(){ # local dir=$1 # local rip=$2 # ssh $ip -l root " # if [ -d /home/java_web_app/$dir ]; then # echo "dir have exist" # else # echo "make a java dir $dir on $rip" # cp -r /home/jetty/. /home/java_web_app/$dir # fi # exit # " #} copy2(){ local ip=$1 local dir=$2 local pk=$3 local app=$4 local user=$5 local path=$6 ssh $ip -l root " if [ -d /data/java_web_app/$dir ]; then echo "dir have exist" else echo "make a java dir $dir on $rip" cp -r /data/jetty/. /data/java_web_app/$dir fi exit " echo "scp $pk to $ip : $dir/webapps/$app" scp $pk $user@$ip:$path/$dir/webapps/$app } restart2(){ local ip=$1 local dir=$2 local port=$3 local stop=$4 local user=$5 local path=$6 echo "restart jetty $ip $dir" echo "$path/jetty-stop.sh $dir $port $stop 2>/dev/null" echo "$path/jetty-start.sh $dir $port $stop 2>/dev/null" ssh $ip -l $user " $path/jetty-stop.sh $dir $port $stop for pid in $(ps -ef|grep "jetty.port=$port" | grep -v "grep"|awk '{print $2}'); do echo "kill,jetty:$pid" kill -9 $pid done $path/jetty-start.sh $dir $port $stop " echo "http://$ip:$port/" } copyRestart2(){ local ip=$1 local dir=$2 local port=$3 local stop=$4 local source=$5 local target=$6 copy2 $ip $dir $source $target root /data/java_web_app restart2 $ip $dir $port $stop root /data/java_web_app } m_mvn(){ if [ $SKIP_MVN = 'true' ]; then mvn clean install -Dmaven.test.skip=true -U -Pproduct fi } m_svn(){ if [ $SKIP_SVN = 'true' ]; then svn co http://10.23.20.15/svn/finance/kzfinance-front/trunk $DISTIBUTE_DIR$ACTION --username=deploy #svn update -r 202 http://10.23.20.15/svn/finance/kzfinance-front/trunk $DISTIBUTE_DIR$ACTION --username=deploy #svn co http://10.23.20.15/svn/huamu/%E4%BC%97%E7%AD%B9/trunk/kzfinance-front $DISTIBUTE_DIR$ACTION --username=deploy fi } m_copy_op(){ local ACTION=$1 cd $DISTIBUTE_DIR m_svn cd $ACTION m_mvn if [ $BUILD_OR_RESTART = 'true' ]; then copyRestart2 12.9.15.28 $ACTION 8011 9011 "target/*.war" "root.war"; copyRestart2 12.9.15.29 $ACTION 8011 9011 "target/*.war" "root.war"; else restart2 12.9.15.28 $ACTION 8011 9011 root /data/java_web_app restart2 12.9.15.29 $ACTION 8011 9011 root /data/java_web_app fi } m_copy_op $ACTION exit
上面的这个脚本的前提条件是要配好秘钥