#!/bin/sh source /etc/profile ## java env export JAVA_HOME=/usr/java/jdk1.8.0_172 export JRE_HOME=$JAVA_HOME/jre ## service name APP_NAME=xxxxx SERVICE_DIR=/data/wwwroot/xxxxxx SERVICE_NAME=$APP_NAME JAR_NAME=xxxxxx.jar PID=$SERVICE_NAME\.pid OUT=$SERVICE_NAME\.out ERR=$SERVICE_NAME\.err cd $SERVICE_DIR if [ -f "$OUT" ];then rm -rf $OUT; rm -rf $ERR; rm -rf $PID; echo "$OUT 文件存在" else echo "$OUT 文件不存在" fi case "$1" in start) nohup $JRE_HOME/bin/java -server -XX:+UseG1GC -Xss256k -Xms1g -Xmx1g -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -XX:MaxGCPauseMillis=100 -XX:InitiatingHeapOccupancyPercent=70 -XX:+PerfDisableSharedMem -XX:AutoBoxCacheMax=2000 -XX:+DisableExplicitGC -Djava.awt.headless=true -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/data/wwwlogs/ -Dfile.encoding=UTF-8 -Dspring.profiles.active=test -jar $JAR_NAME >>$OUT 2> $ERR & echo $! > $SERVICE_DIR/$PID echo "=== start $SERVICE_NAME" ;; stop) kill `cat $SERVICE_DIR/$PID` rm -rf $SERVICE_DIR/$PID echo "=== stop $SERVICE_NAME" sleep 3 ## P_ID=`ps -ef | grep -w "$SERVICE_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" ;; *) ## restart $0 stop sleep 2 $0 start ;; esac exit 0
spring boot 打包成jar包,啓動腳本java