启动脚本
#!/bin/bash
## 配置CONFIG_JAVA_HOME,如果不配置将使用系统默认的java启动
CUR_DIR=$(cd $(dirname $0); pwd)
ROOT_DIR=$(dirname $CUR_DIR)
CONFIG_JAVA_HOME=
GC_TUNE="-XX:NewRatio=3 \
-XX:SurvivorRatio=4 \
-XX:TargetSurvivorRatio=90 \
-XX:MaxTenuringThreshold=8 \
-XX:+UseConcMarkSweepGC \
-XX:ConcGCThreads=4 \
-XX:ParallelGCThreads=4 \
-XX:+CMSScavengeBeforeRemark \
-XX:PretenureSizeThreshold=64m \
-XX:+UseCMSInitiatingOccupancyOnly \
-XX:CMSInitiatingOccupancyFraction=50 \
-XX:CMSMaxAbortablePrecleanTime=6000 \
-XX:+CMSParallelRemarkEnabled \
-XX:+ParallelRefProcEnabled \
-Xmx1024m"
DEFAULT_JAVA_EXEC=$(which java |awk '{print $1}')
if [ -n "$DEFAULT_JAVA_EXEC" ]
then
echo "获取系统的Java为:" "$DEFAULT_JAVA_EXEC"
JAVA_EXEC=${DEFAULT_JAVA_EXEC}
fi
if [ -n "$CONFIG_JAVA_HOME" ]
then
echo "使用配置的Java环境运行,JAVA_HOME为:" "$CONFIG_JAVA_HOME"
JAVA_EXEC=${CONFIG_JAVA_HOME}/bin/java
elif [ -n "$DEFAULT_JAVA_EXEC" ];
then
echo "未配置JavaHome运行环境,将使用系统Java环境"
fi
if [ -z "$JAVA_EXEC" ]
then
echo "未找到可用的Java环境,请检查"
exit 0
fi
nohup $JAVA_EXEC $GC_TUNE -Duser.dir=$ROOT_DIR -jar $ROOT_DIR/dgdpsportal.jar > /dev/null 2>&1 &
RUNNING_PID=$(ps -ef | grep "$ROOT_DIR"/dgdpsportal.jar | grep -v grep | awk '{print $2}')
echo "start run,pid:" "$RUNNING_PID"
停止脚本
#!/bin/bash
CUR_DIR=$(cd $(dirname $0); pwd)
ROOT_DIR=$(dirname $CUR_DIR)
echo "Stopping dKnowlbase.jar"
echo "****:" $ROOT_DIR
STOP_PID=$(ps -ef | grep "$ROOT_DIR"/dKnowlbase.jar | grep -v grep | awk '{print $2}'|xargs )
if [ -n "$STOP_PID" ]
then
echo "kill -9 的pid:" $STOP_PID
kill -9 "$STOP_PID"
fi
echo "stop finish"
部分命令行示例
ps -ef | grep "$ROOT_DIR"/dKnowlbase.jar | grep -v grep | awk '{print $2}'
k8s
#!/bin/sh
export LANG=zh_CN.UTF-8
export NLS_LANG=AMERICA_CHINA.ZHS16GBK
# Check APP_NAME,如果要设置 apm 监控,必须设置该变量
if [ $APP_NAME ];
then
echo "APP_NAME=$APP_NAME"
else
export APP_NAME=no_name
echo "set APP_NAME $APP_NAME"
fi
# Check JAVA_HEAP
if [ $JAVA_HEAP ];
then
echo "JAVA_HEAP=$JAVA_HEAP"
else
# 如果程序对内存有特殊要求,修改此处配置,否则使用默认的配置1G
export JAVA_HEAP=4G
echo "set JAVA_HEAP $JAVA_HEAP"
fi
# Check APM setting
if [ $APM_URL ];
then
echo "APM_URL=$APM_URL"
export APM="-javaagent:/opt/elastic/apm-agent.jar \
-Delastic.apm.service_name=$APP_NAME \
-Delastic.apm.server_url=$APM_URL \
-Delastic.apm.secret_token= \
-Delastic.apm.application_packages=org.example \"
else
export APM=""
echo "No APM_URL set "
fi
GC_TUNE="-XX:NewRatio=3 \
-XX:SurvivorRatio=4 \
-XX:TargetSurvivorRatio=90 \
-XX:MaxTenuringThreshold=8 \
-XX:+UseConcMarkSweepGC \
-XX:ConcGCThreads=4
-XX:ParallelGCThreads=4 \
-XX:+CMSScavengeBeforeRemark \
-XX:PretenureSizeThreshold=64m \
-XX:+UseCMSInitiatingOccupancyOnly \
-XX:CMSInitiatingOccupancyFraction=50 \
-XX:CMSMaxAbortablePrecleanTime=6000 \
-XX:+CMSParallelRemarkEnabled \
-XX:+ParallelRefProcEnabled \
-XX:+HeapDumpOnOutOfMemoryError"
java -Xms$JAVA_HEAP -Xmx$JAVA_HEAP $GC_TUNE $APM -jar /app/bin/dknowlbase/dKnowlbase.jar