maven清理、service jar 脚本

maven清理

REPOSITORY_PATH 指定路径

set REPOSITORY_PATH=D:\repository
rem Searching now...
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%*lastUpdated"') do (
del /s /q %%i
)
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%*unknown"') do (
rmdir /s /q %%i
)
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\unknown"') do (
rmdir /s /q %%i
)
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%*error*"') do (
rmdir /s /q %%i
)
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\error"') do (
rmdir /s /q %%i
)
rem Clean success
pause

service.sh

#!/bin/sh

## java env
#export JAVA_HOME=/usr/local/jdk/jdk1.8.0_101
#export JRE_HOME=$JAVA_HOME/jre

APP_NAME=APP_NAME

JAR_NAME=APP_NAME.jar

LOG_NAME=$APP_NAME\.log

#PID  pid
PID=$APP_NAME\.pid

OPSTION="-Xms1G -Xmx1G"

#tip msg
usage() {
    echo "Usage: service.sh [start|stop|restart|status]"
    exit 1
}

#check is exist
is_exist(){
  pid=`ps -ef|grep $JAR_NAME|grep -v grep|awk '{print $2}' `     
  if [ -z "${pid}" ]; then
   return 1
  else
   return 0
  fi
}

#start
start(){
  is_exist
  if [ $? -eq "0" ]; then 
    echo ">>> ${JAR_NAME} is already running PID=${pid} <<<" 
  else 
    nohup java -jar $JAR_NAME --spring.profiles.active=dev >$LOG_NAME 2>&1 &
    echo $! > $PID
    echo ">>> start $JAR_NAME successed PID=$! <<<" 
    tail -f ./$LOG_NAME
   fi
  }

#stop
stop(){
  #is_exist
  pidf=$(cat $PID)
  #echo "$pidf"  
  echo ">>> api PID = $pidf begin kill $pidf <<<"
  kill $pidf
  rm -rf $PID
  sleep 4
  is_exist
  if [ $? -eq "0" ]; then 
    echo ">>> api 2 PID = $pid begin kill -9 $pid  <<<"
    kill -9  $pid
    sleep 4
    echo ">>> $JAR_NAME process stopped <<<"  
  else
    echo ">>> ${JAR_NAME} is not running <<<"
  fi  
}

#check status
status(){
  is_exist
  if [ $? -eq "0" ]; then
    echo ">>> ${JAR_NAME} is running PID is ${pid} <<<"
  else
    echo ">>> ${JAR_NAME} is not running <<<"
  fi
}

#restart
restart(){
  stop
  sleep 5
  start
}

#swich case
case "$1" in
  "start")
    start
    ;;
  "stop")
    stop
    ;;
  "status")
    status
    ;;
  "restart")
    restart
    ;;
  *)
    usage
    ;;
esac
exit 0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值