不鸣则已

海阔凭鱼跃,天高任鸟飞!

首页 新随笔 联系 订阅 管理
#!/bin/bash

function log_info () { 
DATE=`date "+%Y-%m-%d %H:%M:%S"`
USER=$(whoami)
echo "${DATE} ${USER} execute $0 [INFO] $@"
}

function log_error () 
{ 
DATE=`date "+%Y-%m-%d %H:%M:%S"`
USER=$(whoami)
echo "${DATE} ${USER} execute $0 [ERROR] $@"
}

function fn_log () 
{ 
if [ $? -eq 0 ]; then 
	log_info "$@ sucessed!"
else 
	log_error "$@ failed!"
	exit 
fi 
}

# cd 51token
# git pull
# cd token-api
# get pid
# kill pid
# mvn clean package
# cd target
# nohup java -jar ... >/dev/null &

APP="token-api-0.0.1-SNAPSHOT.jar"

cd ~/51token

git pull
fn_log "git pull"

sleep 3

cd token-api

PID=`ps -C java -f | grep $APP | awk '{print $2}'`
fn_log "ps -C java -f | grep $APP | awk '{print $2}"

if [ -n "$PID" ]; then
	kill 9 $PID
	fn_log "kill 9 $PID"
fi

sleep 2

mvn clean package
fn_log "mvn clean package"

sleep 5

cd target
if [ -f "$APP" ]; then
	nohup java -jar $APP >/dev/null &
	fn_log "nohup java -jar $APP >/dev/null &"
else
	echo "package not exist"
	exit
fi

ss -tlnp

COUNT=15
while [ $COUNT -gt 0 ]; do
        echo "wait"
        COUNT=`expr $COUNT "-" 1`
        sleep 1
done

ss -tlnp

  

posted on 2018-07-31 14:50  唐群  阅读(207)  评论(0编辑  收藏  举报