#!/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