码迷,mamicode.com
首页 > 其他好文 > 详细

服务启动脚本

时间:2020-12-15 11:51:17      阅读:1      评论:0      收藏:0      [点我收藏+]

标签:The   app   $0   print   ESS   size   exists   meta   java   

#!/bin/sh
## java env
export JAVA_HOME=/data/opt/jdk1.8.0_181
export JRE_HOME=$JAVA_HOME/jre
export JAVA_BIN=$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/li/tools.jar:$JRE_HOME/lib/rt.jar
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
## service name
APP_NAME=

SERVICE_DIR=/data/opt/develop/service/$APP_NAME
SERVICE_NAME=$APP_NAME
JAR_NAME=$SERVICE_NAME\.jar
PID=$SERVICE_NAME\.pid

cd $SERVICE_DIR

case "$1" in

    start)
        nohup $JRE_HOME/bin/java -Xms2048m -Xmx2048m -XX:MetaspaceSize=512M -XX:MaxMetaspaceSize=512M -javaagent:/data/opt/skywalking/agent/skywalking-agent.jar -Dskywalking.agent.service_name=$APP_NAME -Dskywalking.agent.keep_report=false -jar $JAR_NAME >/dev/null 2>&1 &
        echo $! > $SERVICE_DIR/$PID
        echo "=== start $SERVICE_NAME"
        ;;

    stop)
        #echo "qwe123asd"| sudo -S kill `cat $SERVICE_DIR/$PID`
        kill `cat $SERVICE_DIR/$PID` 
        rm -rf $SERVICE_DIR/$PID
        echo "=== stop $SERVICE_NAME"

        sleep 5

        P_ID=`ps -ef | grep -w "$SERVICE_NAME" | grep -v "grep" | grep -v "stop" | grep "java" | awk ‘{print $2}‘`
        if [ "$P_ID" == "" ]; then
            echo "=== $SERVICE_NAME process not exists or stop success"
        else
            echo "=== begin kill $SERVICE_NAME process, pid is:$P_ID"
            #echo "qwe123asd"| sudo -S kill -9 $P_ID
            kill -9 $P_ID
        fi
        ;;

    restart)
        $0 stop
        sleep 2
        $0 start
        echo "=== restart $SERVICE_NAME end"
        ;;

    *)
        ## restart
        $0 stop
        sleep 2
        $0 start
        ;;

esac
exit 0

  

服务启动脚本

标签:The   app   $0   print   ESS   size   exists   meta   java   

原文地址:https://www.cnblogs.com/BINGJJFLY/p/14107611.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!