赞
踩
run.sh
-
- if [ -z "$1" ] || [ -z "$2" ]
- then
- echo "需按规范传参,实例: "
- echo "./run.sh xx.jar status"
- exit
- fi
-
-
-
- OJECT_DATE=$(date +%Y%m%d%H%M%S)
- #
- #当前文件目录
- BASE_HOME=$(cd $(dirname $0); pwd)
- #
- PROJECT_NAME=$1
- #
- #PROJECT_OPTS="-Dbuildv=${PROJECT_DATE} -Xmx512m -Djava.compiler=NONE -Dspring.profiles.active=prod"
- PROJECT_OPTS=""
- #
- PIDS=`ps -ef | grep "${PROJECT_NAME}" | grep java |awk '{print $2}'`
- count=$(ps -ef | grep "${PROJECT_NAME}" | grep "java" | wc -l)
- status(){
- echo "==========status======="
- ps -ef | grep "${PROJECT_NAME}" | grep java
-
- if [ $count -le 0 ]; then
- echo ${PROJECT_NAME}" is not runing"
- else
- echo ${PROJECT_NAME}" is runing"
- fi
- }
-
- start() {
- echo "==========start===========";
- ps -ef | grep "${PROJECT_NAME}" | grep java
- count=$(ps -ef | grep "${PROJECT_NAME}" | grep "java" | wc -l)
- if [ $count -le 0 ]; then
- echo ${PROJECT_NAME}" is starting"
-
- cd $BASE_HOME
-
- nohup java $PROJECT_OPTS -jar ${PROJECT_NAME} >/dev/null 2>&1 &
- else
-
- echo ${PROJECT_NAME}" is runing"
- fi
- }
-
- stop() {
- echo "===========stop============";
-
- ps -ef | grep "${PROJECT_NAME}" | grep java
-
- if [ -z "$PIDS" ]; then
- echo "警告: ${PROJECT_NAME} 未启动!"
- exit 1
- fi
- echo -e "正在停止 ${PROJECT_NAME} 进程[PIDS] ...\c"
- for PID in $PIDS ; do
- kill $PID > /dev/null 2>&1
- done
- COUNT=0
- while [ $COUNT -lt 1 ]; do
- echo -e "......\c"
- sleep 2
- COUNT=1
- for PID in $PIDS ; do
- PID_EXIST=`ps -f -p $PID | grep java`
- if [ -n "$PID_EXIST" ]; then
- COUNT=0
- break
- fi
- done
- done
- echo "${PROJECT_NAME} 进程[PIDS], 已停止!"
- }
-
- restart() {
- stop;
- echo "sleeping.........";
- sleep 3;
- start;
-
- }
- case "$2" in
- 'start')
- start
- ;;
- 'stop')
- stop
- ;;
- 'status')
- status
- ;;
- 'restart')
- restart
- ;;
- *)
- echo "usage: $0 {start|stop|restart|status}"
- exit 1
- ;;
- esac
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。