123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #!/bin/sh
- S_ACTIVE=dev
- JAVA_OPS='-Xms512M -Xmx512M'
- CURR_PATH=$(pwd)
- SERVICE_NAME=""
- JAR_NAME=$(find ./ -maxdepth 1 -name \*1.0.0-SNAPSHOT-exec.jar -type f -exec basename {} \;)
- if [ -z $JAR_NAME ];then
- JAR_NAME=$(find ./ -maxdepth 1 -name \*1.0.0-SNAPSHOT.jar -type f -exec basename {} \;)
- if [ -z $JAR_NAME ];then
- JAR_NAME=$(find ./ -maxdepth 1 -name \*1.0.0-RELEASE-exec.jar -type f -exec basename {} \;)
- SERVICE_NAME=${JAR_NAME%%-1.0.0-RELEASE-exec.jar}
- else
- SERVICE_NAME=${JAR_NAME%%-1.0.0-SNAPSHOT.jar}
- fi
- else
- SERVICE_NAME=${JAR_NAME%%-1.0.0-SNAPSHOT-exec.jar}
- fi
- #create tmp dir
- TMP_DIR=${CURR_PATH}"/tmp"
- mkdir -p $TMP_DIR
- JAVA_OPS=" -Dspring.profiles.active=$S_ACTIVE -Dtmp.dir=${TMP_DIR} "${JAVA_OPS}
- JAR_LIB=${CURR_PATH}"/lib"
- if [ -d $JAR_LIB ];then
- JAVA_OPS=" -Dloader.path=file://${JAR_LIB} "${JAVA_OPS}
- fi
- PATH_TO_JAR="$CURR_PATH/$JAR_NAME"
- PID_PATH_NAME="$CURR_PATH/$SERVICE_NAME-pid"
- if [ -f $PID_PATH_NAME ]; then
- if test -z $(cat $PID_PATH_NAME) ;then
- rm $PID_PATH_NAME
- fi
- fi
- start()
- {
- echo "Starting $SERVICE_NAME ..."
- if [ ! -f $PID_PATH_NAME ]; then
- if [ $1 -eq 0 ]; then
- java $JAVA_OPS -jar $PATH_TO_JAR
- echo "$SERVICE_NAME stoped ..."
- else
- nohup java $JAVA_OPS -jar $PATH_TO_JAR >/dev/null 2>&1 &
- echo $! > $PID_PATH_NAME
- echo "$SERVICE_NAME started ..."
- fi
- else
- PID=$(cat $PID_PATH_NAME);
- PID_EXISTS=$(ps -p $PID);
- if [ $? -eq 0 ]; then
- echo "$SERVICE_NAME is already running ..."
- else
- if [ $1 -eq 0 ]; then
- java $JAVA_OPS -jar $PATH_TO_JAR
- echo "$SERVICE_NAME stoped ..."
- else
- nohup java $JAVA_OPS -jar $PATH_TO_JAR >/dev/null 2>&1 &
- echo $! > $PID_PATH_NAME
- echo "$SERVICE_NAME started ..."
- fi
- fi
- fi
- }
- stop()
- {
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME);
- echo "$SERVICE_NAME stoping ..."
- i=0
- kill $PID
- PID_EXISTS=$(ps -p $PID);
- while ( [ $? -eq 0 ] && [ "$i" -lt 15 ] )
- do
- sleep 1;
- let "i += 1";
- echo "$i sec"
- PID_EXISTS=$(ps -p $PID);
- done
- PID_EXISTS=$(ps -p $PID);
- if [ $? -eq 0 ]; then
- CPID=$(ps -ef|grep java|grep $PATH_TO_JAR|grep -v grep|awk '{print $2}')
- kill -9 $CPID;
- echo "$SERVICE_NAME stop failure so kill process ..."
- fi
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- }
- case $1 in
- start)
- start 1
- ;;
- console)
- start 0
- ;;
- stop)
- stop
- ;;
- restart)
- stop
- start 1
- ;;
- *)
- echo "Usage: $0 {start|console|stop|restart}"
- exit 1
- ;;
- esac
- exit 0
|