fabric8镜像的deployments脚本
因为没有直接使用fabric8的镜像(https://hub.docker.com/r/fabric8/java-jboss-openjdk8-jdk/~/dockerfile/), 但是又羡慕其自动内存计算的功能, 所以从facric8的把"/deployments"目录下的脚本都活剥出来, 也就是抄袭出来, 打算加到自己的镜像中去.
run-java.sh:
#!/bin/sh# Fail on a single failed command set -eo pipefail# ========================================================== # Generic run script for running arbitrary Java applications # # Source and Documentation can be found # at https://github.com/fabric8io/run-java-sh # # ==========================================================# Error is indicated with a prefix in the return value check_error() {local msg=$1if echo ${msg} | grep -q "^ERROR:"; thenecho ${msg}exit 1fi }# The full qualified directory where this script is located get_script_dir() {# Default is current directorylocal dir=`dirname "$0"`local full_dir=`cd "${dir}" ; pwd`echo ${full_dir} }# Try hard to find a sane default jar-file auto_detect_jar_file() {local dir=$1# Filter out temporary jars from the shade plugin which start with 'original-'local old_dir=$(pwd)cd ${dir}if [ $? = 0 ]; thenlocal nr_jars=`ls *.jar 2>/dev/null | grep -v '^original-' | wc -l | tr -d '[[:space:]]'`if [ ${nr_jars} = 1 ]; thenls *.jar | grep -v '^original-'exit 0ficd ${old_dir}echo "ERROR: Neither \$JAVA_MAIN_CLASS nor \$JAVA_APP_JAR is set and ${nr_jars} found in ${dir} (1 expected)"elseecho "ERROR: No directory ${dir} found for auto detection"fi }# Check directories (arg 2...n) for a jar file (arg 1) get_jar_file() {local jar=$1shift;if [ "${jar:0:1}" = "/" ]; thenif [ -f "${jar}" ]; thenecho "${jar}"elseecho "ERROR: No such file ${jar}"fielsefor dir in $*; doif [ -f "${dir}/$jar" ]; thenecho "${dir}/$jar"returnfidoneecho "ERROR: No ${jar} found in $*"fi }load_env() {local script_dir=$1# Configuration stuff is read from this filelocal run_env_sh="run-env.sh"# Load default default configif [ -f "${script_dir}/${run_env_sh}" ]; thensource "${script_dir}/${run_env_sh}"fi# Check also $JAVA_APP_DIR. Overrides other defaults# It's valid to set the app dir in the default scriptif [ -z "${JAVA_APP_DIR}" ]; thenJAVA_APP_DIR="${script_dir}"elseif [ -f "${JAVA_APP_DIR}/${run_env_sh}" ]; thensource "${JAVA_APP_DIR}/${run_env_sh}"fifiexport JAVA_APP_DIR# Read in container limits and export the as environment variablesif [ -f "${script_dir}/container-limits" ]; thensource "${script_dir}/container-limits"fi# JAVA_LIB_DIR defaults to JAVA_APP_DIRexport JAVA_LIB_DIR="${JAVA_LIB_DIR:-${JAVA_APP_DIR}}"if [ -z "${JAVA_MAIN_CLASS}" ] && [ -z "${JAVA_APP_JAR}" ]; thenJAVA_APP_JAR="$(auto_detect_jar_file ${JAVA_APP_DIR})"check_error "${JAVA_APP_JAR}"fiif [ "x${JAVA_APP_JAR}" != x ]; thenlocal jar="$(get_jar_file ${JAVA_APP_JAR} ${JAVA_APP_DIR} ${JAVA_LIB_DIR})"check_error "${jar}"export JAVA_APP_JAR=${jar}elseexport JAVA_MAIN_CLASSfi }# Check for standard /opt/run-java-options first, fallback to run-java-options in the path if not existing run_java_options() {if [ -f "/opt/run-java-options" ]; thenecho `sh /opt/run-java-options`elsewhich run-java-options >/dev/null 2>&1if [ $? = 0 ]; thenecho `run-java-options`fifi }# Combine all java options get_java_options() {local dir=$(get_script_dir)local java_optslocal debug_optsif [ -f "$dir/java-default-options" ]; thenjava_opts=$($dir/java-default-options)fiif [ -f "$dir/debug-options" ]; thendebug_opts=$($dir/debug-options)fi# Normalize spaces with awk (i.e. trim and elimate double spaces)echo "${JAVA_OPTIONS} $(run_java_options) ${debug_opts} ${java_opts}" | awk '$1=$1' }# Read in a classpath either from a file with a single line, colon separated # or given line-by-line in separate lines # Arg 1: path to claspath (must exist), optional arg2: application jar, which is stripped from the classpath in # multi line arrangements format_classpath() {local cp_file="$1"local app_jar="$2"local wc_out=`wc -l $1 2>&1`if [ $? -ne 0 ]; thenecho "Cannot read lines in ${cp_file}: $wc_out"exit 1filocal nr_lines=`echo $wc_out | awk '{ print $1 }'`if [ ${nr_lines} -gt 1 ]; thenlocal sep=""local classpath=""while read file; dolocal full_path="${JAVA_LIB_DIR}/${file}"# Don't include app jar if include in listif [ x"${app_jar}" != x"${full_path}" ]; thenclasspath="${classpath}${sep}${full_path}"fisep=":"done < "${cp_file}"echo "${classpath}"else# Supposed to be a single line, colon separated classpath filecat "${cp_file}"fi }# Fetch classpath from env or from a local "run-classpath" file get_classpath() {local cp_path="."if [ "x${JAVA_LIB_DIR}" != "x${JAVA_APP_DIR}" ]; thencp_path="${cp_path}:${JAVA_LIB_DIR}"fiif [ -z "${JAVA_CLASSPATH}" ] && [ "x${JAVA_MAIN_CLASS}" != x ]; thenif [ "x${JAVA_APP_JAR}" != x ]; thencp_path="${cp_path}:${JAVA_APP_JAR}"fiif [ -f "${JAVA_LIB_DIR}/classpath" ]; then# Classpath is pre-created and stored in a 'run-classpath' filecp_path="${cp_path}:`format_classpath ${JAVA_LIB_DIR}/classpath ${JAVA_APP_JAR}`"else# No order impliedcp_path="${cp_path}:${JAVA_APP_DIR}/*"fielif [ "x${JAVA_CLASSPATH}" != x ]; then# Given from the outsidecp_path="${JAVA_CLASSPATH}"fiecho "${cp_path}" }# Set process name if possible get_exec_args() {EXEC_ARGS=""if [ "x${JAVA_APP_NAME}" != x ]; then# Not all shells support the 'exec -a newname' syntax..`exec -a test true 2>/dev/null`if [ "$?" = 0 ] ; thenecho "-a '${JAVA_APP_NAME}'"else# Lets switch to bash if you have it installed...if [ -f "/bin/bash" ] ; thenexec "/bin/bash" $0 $@fififi }# Start JVM startup() {# Initialize environmentload_env $(get_script_dir)local argscd ${JAVA_APP_DIR}if [ "x${JAVA_MAIN_CLASS}" != x ] ; thenargs="${JAVA_MAIN_CLASS}"elseargs="-jar ${JAVA_APP_JAR}"fiecho exec $(get_exec_args) java $(get_java_options) -cp "$(get_classpath)" ${args} $*exec $(get_exec_args) java $(get_java_options) -cp "$(get_classpath)" ${args} $* }# ============================================================================= # Fire up startup $*
java-default-options:
#!/bin/sh # ================================================================= # Detect whether running in a container and set appropriate options # for limiting Java VM resources # # Usage: JAVA_OPTIONS="$(java-default-options.sh)"# Env Vars evaluated:# JAVA_OPTIONS: Checked for already set options # JAVA_MAX_MEM_RATIO: Ratio use to calculate a default maximum Memory, in percent. # E.g. the default value "50" implies that 50% of the Memory # given to the container is used as the maximum heap memory with # '-Xmx'. It is a heuristic and should be better backed up with real # experiments and measurements. # For a good overviews what tuning options are available --> # https://youtu.be/Vt4G-pHXfs4 # https://www.youtube.com/watch?v=w1rZOY5gbvk # https://vimeo.com/album/4133413/video/181900266 # Also note that heap is only a small portion of the memory used by a JVM. There are lot # of other memory areas (metadata, thread, code cache, ...) which addes to the overall # size. There is no easy solution for this, 50% seems to be are reasonable compromise. # However, when your container gets killed because of an OOM, then you should tune # the absolute values ## Check for memory options and calculate a sane default if not given max_memory() {# Check whether -Xmx is already given in JAVA_OPTIONS. Then we dont# do anything hereif echo "${JAVA_OPTIONS}" | grep -q -- "-Xmx"; thenreturnfi# Check if explicitely disabledif [ "x$JAVA_MAX_MEM_RATIO" = "x0" ]; thenreturnfi# Check for the 'real memory size' and caluclate mx from a ratio# given (default is 50%)if [ "x$CONTAINER_MAX_MEMORY" != x ]; thenlocal max_mem="${CONTAINER_MAX_MEMORY}"local ratio=${JAVA_MAX_MEM_RATIO:-50}local mx=$(echo "${max_mem} ${ratio} 1048576" | awk '{printf "%d\n" , ($1*$2)/(100*$3) + 0.5}')echo "-Xmx${mx}m"fi }# Switch on diagnostics except when switched off diagnostics() {if [ "x$JAVA_DIAGNOSTICS" != "x" ]; thenecho "-XX:NativeMemoryTracking=summary -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UnlockDiagnosticVMOptions"fi }cpu_core_tunning() {local core_limit="${JAVA_CORE_LIMIT}"if [ "x$core_limit" = "x0" ]; thenreturnfiif [ "x$CONTAINER_CORE_LIMIT" != x ]; thenif [ "x$core_limit" = x ]; thencore_limit="${CONTAINER_CORE_LIMIT}"fiecho "-XX:ParallelGCThreads=${core_limit} " \"-XX:ConcGCThreads=${core_limit} " \"-Djava.util.concurrent.ForkJoinPool.common.parallelism=${core_limit}"fi }# Echo options, trimming trailing and multiple spaces echo "$(max_memory) $(diagnostics) $(cpu_core_tunning)" | awk '$1=$1'
debug-options:
#!/bin/sh# Check for debug options and echo them if enabled. Meant to be included by # a run script.debug_options() {if [ "x${JAVA_ENABLE_DEBUG}" != "x" -o "x${JAVA_DEBUG_ENABLE}" != "x" -o "x${JAVA_DEBUG}" != "x" ]; thenlocal debug_port=${JAVA_DEBUG_PORT:-5005}echo "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${debug_port}"fi }## Echo options, trimming trailing and multiple spaces echo "$(debug_options)" | awk '$1=$1'
container-limits:
#!/bin/sh# Detected container limits # If found these are exposed as the following environment variables: # # - CONTAINER_MAX_MEMORY # - CONTAINER_CORE_LIMIT # # This script is meant to be sourced.ceiling() {awk -vnumber="$1" -vdiv="$2" 'function ceiling(x){return x%1 ? int(x)+1 : x}BEGIN{print ceiling(number/div)}' }# Based on the cgroup limits, figure out the max number of core we should utilize core_limit() {local cpu_period_file="/sys/fs/cgroup/cpu/cpu.cfs_period_us"local cpu_quota_file="/sys/fs/cgroup/cpu/cpu.cfs_quota_us"if [ -r "${cpu_period_file}" ]; thenlocal cpu_period="$(cat ${cpu_period_file})"if [ -r "${cpu_quota_file}" ]; thenlocal cpu_quota="$(cat ${cpu_quota_file})"# cfs_quota_us == -1 --> no restrictionsif [ "x$cpu_quota" != "x-1" ]; thenceiling "$cpu_quota" "$cpu_period"fififi }max_memory() {# High number which is the max limit unti which memory is supposed to be# unbounded. 512 TB for now.local max_mem_unbounded="562949953421312"local mem_file="/sys/fs/cgroup/memory/memory.limit_in_bytes"if [ -r "${mem_file}" ]; thenlocal max_mem="$(cat ${mem_file})"if [ ${max_mem} -lt ${max_mem_unbounded} ]; thenecho "${max_mem}"fifi }limit="$(core_limit)" if [ x$limit != x ]; thenexport CONTAINER_CORE_LIMIT="${limit}" fi unset limitlimit="$(max_memory)" if [ x$limit != x ]; thenexport CONTAINER_MAX_MEMORY="$limit" fi unset limit
fabric8镜像的deployments脚本相关推荐
- SQL Server镜像自动生成脚本
SQL Server镜像自动生成脚本 镜像的搭建非常繁琐,花了一点时间写了这个脚本,方便大家搭建镜像 执行完这个镜像脚本之后,最好在每台机器都绑定一下hosts文件,不然的话,镜像可能会不work 1 ...
- docker 使用python 镜像运行python脚本
第一步创建:python脚本 # touch helloworld.py #vim helloworld.py #!/usr/bin/python print("hello world!&q ...
- dockerfile如何运行镜像内的脚本_第七章 Dockerfile文件解析(一)
七 Dockerfile文件解析-1 7.1 定义:Dockerfile是用来构建Docker镜像的文件,是由一系列命令和参数构成的脚本 7.2 Dockerfile内容基础知识: 1.每条保留字指令 ...
- dockerfile如何运行镜像内的脚本_Docker精华问答 | Docker commit如何用?
Docker 是个划时代的开源项目,它彻底释放了计算虚拟化的威力,极大提高了应用的维护效率,降低了云计算应用开发的成本!使用 Docker,可以让应用的部署.测试和分发都变得前所未有的高效和轻松! 1 ...
- Fabric v2.3 下载二进制文件和镜像bootstrap.sh脚本解析
下载二进制文件和镜像官网提示命令: curl -sSL https://bit.ly/2ysbOFE | bash -s 浏览器可直接打开 https://bit.ly/2ysbOFE 查看脚本(科学 ...
- dockerfile如何运行镜像内的脚本_如何从看不懂Dockerfile到创建自己的镜像
开始了解Docker是健明的一篇文章跟着jimmy学docker系列之第2讲:一个软件一个容器,那时正在研究虚拟机(Virtual Machine),发现Docker更适合现在的需求,就从基本概念和操 ...
- Docker多阶段镜像构建Dockerfile脚本示例:构建nodejs前端项目
# 声明镜像来源为node:12.16.1 FROM node:12.16.1# 声明工作目录 WORKDIR /gva_web/# 拷贝整个web项目到当前工作目录 COPY . .# 通过npm下 ...
- 查看docker镜像的dockerfile脚本json信息
cd /var/lib/docker/image/overlay2/imagedb/content/sha256 镜像id就是文件的前缀 参考链接:https://www.cnblogs.com/wh ...
- 两个Harbor镜像库之间备份拉取镜像的shell脚本
#当前日期 now=`date +%Y%m%d`#镜像名 ImageName=web#项目版本 itemVersion=v2.1#测试环境镜像 test_images=测试环境IP地址:端口号/pbp ...
最新文章
- h5 返回上一页并且刷新页面
- 两道与二进制有关的sequence
- python函数count_python中count函数知识点浅析
- P5502-[JSOI2015]最大公约数【分治】
- 【快速幂】小明解密码 (jzoj 2146)
- ASP.NET Core 2.2 : 十六.扒一扒2.2版更新的新路由方案
- 视觉SLAM笔记(55) 位姿图
- 打造云上深度学习实验室
- (已拿offer)2017腾讯暑期实习生从笔试到面试总结(附带华为、阿里面试经历)...
- 帆软获取单元格值与赋值
- java ror_Java会因为RoR的流行而过时吗?
- MES系统源码 MES系统功能介绍
- bootstrap视频教程 jsp_家政服务系统(JAVA,SSM,BOOTSTRAP,JSP,AJAX,MYSQL)+手把手系列视频教程...
- 如何用计算机声卡录声音,录音声卡怎么设置 录音声卡设置教程
- vue.js 知乎_zhihu每日水疗中心与vue.js
- Python监听RabbitMq ready数量
- Android 和 iOS 实现录屏推流的方案整理
- RollPitchYaw傻傻分不清
- matlab音乐信号处理,数字信号处理课程设计---基于 MATLAB 的音乐信号处理和分析...
- Apex_json应用
热门文章
- 微信公众平台开发(110) 微信连Wi-Fi
- python写公众号_python如何编写公众号
- latex footnote numbering
- 电商平台后台管理系统--->操作方法说明
- 坐标转换—高斯正反算(附测量助理最新版软件下载)
- 苹果手机7P ios14 nfc怎么复制门禁卡
- 梦幻诛仙linux纯端架设教程,梦幻诛仙 一键端搭建iOS安卓双端+完整后台源码+各种工具附带视频架设教程...
- BUUCTF刷题笔记
- 复旦大学智能感知与无人系统实验室诚聘海内外超级博士后/博士后
- 程序员颈椎病康复秘籍,你值得拥有!