启动脚本

  1. #!/bin/bash
  2. ## 配置CONFIG_JAVA_HOME,如果不配置将使用系统默认的java启动
  3. CUR_DIR=$(cd $(dirname $0); pwd)
  4. ROOT_DIR=$(dirname $CUR_DIR)
  5. CONFIG_JAVA_HOME=
  6. GC_TUNE="-XX:NewRatio=3 \
  7. -XX:SurvivorRatio=4 \
  8. -XX:TargetSurvivorRatio=90 \
  9. -XX:MaxTenuringThreshold=8 \
  10. -XX:+UseConcMarkSweepGC \
  11. -XX:ConcGCThreads=4 \
  12. -XX:ParallelGCThreads=4 \
  13. -XX:+CMSScavengeBeforeRemark \
  14. -XX:PretenureSizeThreshold=64m \
  15. -XX:+UseCMSInitiatingOccupancyOnly \
  16. -XX:CMSInitiatingOccupancyFraction=50 \
  17. -XX:CMSMaxAbortablePrecleanTime=6000 \
  18. -XX:+CMSParallelRemarkEnabled \
  19. -XX:+ParallelRefProcEnabled \
  20. -Xmx1024m"
  21. DEFAULT_JAVA_EXEC=$(which java |awk '{print $1}')
  22. if [ -n "$DEFAULT_JAVA_EXEC" ]
  23. then
  24. echo "获取系统的Java为:" "$DEFAULT_JAVA_EXEC"
  25. JAVA_EXEC=${DEFAULT_JAVA_EXEC}
  26. fi
  27. if [ -n "$CONFIG_JAVA_HOME" ]
  28. then
  29. echo "使用配置的Java环境运行,JAVA_HOME为:" "$CONFIG_JAVA_HOME"
  30. JAVA_EXEC=${CONFIG_JAVA_HOME}/bin/java
  31. elif [ -n "$DEFAULT_JAVA_EXEC" ];
  32. then
  33. echo "未配置JavaHome运行环境,将使用系统Java环境"
  34. fi
  35. if [ -z "$JAVA_EXEC" ]
  36. then
  37. echo "未找到可用的Java环境,请检查"
  38. exit 0
  39. fi
  40. nohup $JAVA_EXEC $GC_TUNE -Duser.dir=$ROOT_DIR -jar $ROOT_DIR/dgdpsportal.jar > /dev/null 2>&1 &
  41. RUNNING_PID=$(ps -ef | grep "$ROOT_DIR"/dgdpsportal.jar | grep -v grep | awk '{print $2}')
  42. echo "start run,pid:" "$RUNNING_PID"

停止脚本

  1. #!/bin/bash
  2. CUR_DIR=$(cd $(dirname $0); pwd)
  3. ROOT_DIR=$(dirname $CUR_DIR)
  4. echo "Stopping dKnowlbase.jar"
  5. echo "****:" $ROOT_DIR
  6. STOP_PID=$(ps -ef | grep "$ROOT_DIR"/dKnowlbase.jar | grep -v grep | awk '{print $2}'|xargs )
  7. if [ -n "$STOP_PID" ]
  8. then
  9. echo "kill -9 的pid:" $STOP_PID
  10. kill -9 "$STOP_PID"
  11. fi
  12. echo "stop finish"

部分命令行示例

  1. ps -ef | grep "$ROOT_DIR"/dKnowlbase.jar | grep -v grep | awk '{print $2}'

image.png

k8s

  1. #!/bin/sh
  2. export LANG=zh_CN.UTF-8
  3. export NLS_LANG=AMERICA_CHINA.ZHS16GBK
  4. # Check APP_NAME,如果要设置 apm 监控,必须设置该变量
  5. if [ $APP_NAME ];
  6. then
  7. echo "APP_NAME=$APP_NAME"
  8. else
  9. export APP_NAME=no_name
  10. echo "set APP_NAME $APP_NAME"
  11. fi
  12. # Check JAVA_HEAP
  13. if [ $JAVA_HEAP ];
  14. then
  15. echo "JAVA_HEAP=$JAVA_HEAP"
  16. else
  17. # 如果程序对内存有特殊要求,修改此处配置,否则使用默认的配置1G
  18. export JAVA_HEAP=4G
  19. echo "set JAVA_HEAP $JAVA_HEAP"
  20. fi
  21. # Check APM setting
  22. if [ $APM_URL ];
  23. then
  24. echo "APM_URL=$APM_URL"
  25. export APM="-javaagent:/opt/elastic/apm-agent.jar \
  26. -Delastic.apm.service_name=$APP_NAME \
  27. -Delastic.apm.server_url=$APM_URL \
  28. -Delastic.apm.secret_token= \
  29. -Delastic.apm.application_packages=org.example \"
  30. else
  31. export APM=""
  32. echo "No APM_URL set "
  33. fi
  34. GC_TUNE="-XX:NewRatio=3 \
  35. -XX:SurvivorRatio=4 \
  36. -XX:TargetSurvivorRatio=90 \
  37. -XX:MaxTenuringThreshold=8 \
  38. -XX:+UseConcMarkSweepGC \
  39. -XX:ConcGCThreads=4
  40. -XX:ParallelGCThreads=4 \
  41. -XX:+CMSScavengeBeforeRemark \
  42. -XX:PretenureSizeThreshold=64m \
  43. -XX:+UseCMSInitiatingOccupancyOnly \
  44. -XX:CMSInitiatingOccupancyFraction=50 \
  45. -XX:CMSMaxAbortablePrecleanTime=6000 \
  46. -XX:+CMSParallelRemarkEnabled \
  47. -XX:+ParallelRefProcEnabled \
  48. -XX:+HeapDumpOnOutOfMemoryError"
  49. java -Xms$JAVA_HEAP -Xmx$JAVA_HEAP $GC_TUNE $APM -jar /app/bin/dknowlbase/dKnowlbase.jar