start.sh

version 1:

#!/bin/bash
#auth xilh 
#time 2019-04-22
#Auto deploy for jenkins perf
#params:
#       $1: port
#       $2: print log flag
#       $3: date, eg: 20190618-172955
 
cd "$(dirname $0)"
project=$(pwd | cut -d / -f 4)
#echo 'project: '$project
cd /home/loginuser/$project/app
 
LOG=/home/loginuser/$project/app/restart.log
echo '================================' >> $LOG
echo `date +%Y%m%d' '%H:%M:%S` >> $LOG
echo '================================' >> $LOG
 
if [ -z $1 ]
then
        echo "port may not be null"
        exit 1
fi
 
PID=$(netstat -tpln|grep $1 | cut -d 'N' -f2 | sed -s "s/\/java//g")
if [ -n $PID]
then
 
        echo $1 >> $LOG
        echo $PID >> $LOG
        echo 'kill -9 '$PID >> $LOG
        kill -9 $PID
fi
 
if [ "$2" = "1" -o "$2" = "2" ]
then
        echo 'mv log to log dir ...'
        mv /home/loginuser/$project/app/nohup.out /tpdata/taiping-logs/$project/nohup-`date +%Y-%m-%d-%H:%M:%S`.out
fi
 
# an absolute path is a must, by xiluhua 21090619
nohup /home/loginuser/java/jdk1.8.0_131/bin/java -jar taiping-$project-$3.jar --spring.profiles.active=prod >> nohup.out &
#/home/loginuser/java/jdk1.8.0_131/bin/java -version >> $LOG
tmp=$(echo $?)
 
 
if [ "$2" = "2" -o "$2" = "3" ]
then
        tail -fn 200 nohup.out
fi
 
echo $tmp

 

version 2:

#!/bin/bash
#auth xilh 
#time 2019-04-22
#Auto deploy for lack of jenkins 
#params:
#       $1: project
#       $2: port
#       $3: log print flag
#       $4: project version
 
cd "$(dirname $0)"
project=$(pwd | cut -d / -f 4)
echo 'project: '$1
cd /home/loginuser/$1/app
 
LOG=/home/loginuser/$1/app/restart.log
echo '================================' >> $LOG
echo `date +%Y%m%d' '%H:%M:%S` >> $LOG
echo '================================' >> $LOG
 
if [ -z $1 ]
then
        echo "project name may not be null"
        exit 1
fi
 
if [ -z $2 ]
then
        echo "port may not be null"
        exit 1
fi
 
PID=$(netstat -tpln|grep $2 | cut -d 'N' -f2 | sed -s "s/\/java//g")
if [ -n $PID ]
then
 
        echo $2 >> $LOG
        echo $PID >> $LOG
        echo 'kill -9 '$PID >> $LOG
        kill -9 $PID
fi
 
if [ "$3" = "1" -o "$3" = "2" ]
then
        echo 'mv log to log dir ...'
        mv /home/loginuser/$1/app/nohup.out /tpdata/taiping-logs/$1/nohup-`date +%Y-%m-%d-%H:%M:%S`.out
fi
 
nohup java -jar taiping-$1-$4.jar --spring.profiles.active=prod >> nohup.out &
 
if [ "$3" = "2" -o "$3" = "3" ]
then
        tail -fn 200 nohup.out
fi

 

posted @ 2019-06-21 10:25  xiluhua  阅读(619)  评论(0编辑  收藏  举报