1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #!/bin/sh
APP_NAME=hello
SERVICE_DIR=/home/$APP_NAME
SERVICE_NAME=$APP_NAME JAR_NAME=$SERVICE_NAME\.jar PID=$SERVICE_NAME\.pid LOG=$SERVICE_DIR/log/$APP_NAME ACTIVE=test cd $SERVICE_DIR case "$1" in
start) nohup java -Xms512m -Xmx1024m -jar $JAR_NAME --spring.profiles.active=$ACTIVE > $LOG.out 2>> $LOG.err & echo $! > $SERVICE_DIR/$PID echo "=== start $SERVICE_NAME" tail -f $LOG.out ;;
stop) kill `cat $SERVICE_DIR/$PID` rm -rf $SERVICE_DIR/$PID echo "=== stop $SERVICE_NAME" sleep 5 P_ID=`ps -ef | grep -w "$JAR_NAME" | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "=== $SERVICE_NAME process not exists or stop success" else echo "=== $SERVICE_NAME process pid is:$P_ID" echo "=== begin kill $SERVICE_NAME process, pid is:$P_ID" kill -9 $P_ID fi ;;
restart) $0 stop sleep 2 $0 start echo "=== restart $SERVICE_NAME success" ;;
*) $0 stop sleep 2 $0 start ;;
esac exit 0
|