diff --git a/README.md b/README.md index bd69d49b..2ba498e8 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,7 @@ default.yaml file define variables that can be used at any time in the container ##### default.yaml.startup default.yaml.startup define variables that are only available during the container **first start** in **startup files**. -*\*.yaml.startup* are deleted right after startup files are processed for the first time, +\*.yaml.startup are deleted right after startup files are processed for the first time, then all variables they contains will not be available in the container environment. This helps to keep the container configuration secret. If you don't care all environment variables can be defined in **default.yaml** and everything will work fine. @@ -573,8 +573,10 @@ Here simple Dockerfile example how to add a service-available to an image: FROM osixia/ubuntu-light-baseimage:0.1.4 MAINTAINER Your Name - # Add cfssl and cron service-available and get nginx and php5-fpm. - # https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/add-multiple-process-stack + # Add cfssl and cron service-available + # https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/add-service-available + # https://github.com/osixia/docker-light-baseimage/blob/stable/image/service-available/:cfssl/download.sh + # https://github.com/osixia/docker-light-baseimage/blob/stable/image/service-available/:cron/download.sh RUN apt-get -y update \ && /container/tool/add-service-available :cfssl :cron \ && LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ @@ -606,7 +608,7 @@ What it does: *Run tool* takes several options, to list them: - docker run osixia/light-baseimage:0.2.1 --help + docker run osixia/ubuntu-light-baseimage:0.2.1 --help usage: run [-h] [-e] [-s] [-p] [-k] [-c] [-l {none,error,warning,info,debug,trace}] [MAIN_COMMAND [MAIN_COMMAND ...]] @@ -688,7 +690,7 @@ If a main command is set for example: If a main command is set *run tool* launch it otherwise bash is launched. Example: - docker run -it osixia/light-baseimage:0.2.1 + docker run -it osixia/ubuntu-light-baseimage:0.2.1 ##### Extra environment variables @@ -749,9 +751,9 @@ will produce this bash environment variables: complex-bash-env make it easy to iterate trough this variable: - for fruit in $(complex-bash-env iterate "${FRUITS}") + for fruit in $(complex-bash-env iterate FRUITS) do - echo $fruit + echo ${!fruit} done A more complete example can be found [osixia/phpLDAPadmin](https://github.com/osixia/docker-phpLDAPadmin) image. @@ -764,8 +766,8 @@ Note this yaml definition: Can also be set by command line converted in python or json: - docker run -it --env FRUITS="#PYTHON2BASH:['orange','apple']" osixia/light-baseimage:0.2.1 printenv - docker run -it --env FRUITS="#JSON2BASH:[\"orange\",\"apple\"]" osixia/light-baseimage:0.2.1 printenv + docker run -it --env FRUITS="#PYTHON2BASH:['orange','apple']" osixia/ubuntu-light-baseimage:0.2.1 printenv + docker run -it --env FRUITS="#JSON2BASH:[\"orange\",\"apple\"]" osixia/ubuntu-light-baseimage:0.2.1 printenv ### Tests diff --git a/image/build.sh.orig b/image/build.sh.orig new file mode 100755 index 00000000..a01918b7 --- /dev/null +++ b/image/build.sh.orig @@ -0,0 +1,85 @@ +#!/bin/bash -ex + +## Add bash tools to /sbin +ln -s /container/tool/* /sbin/ + +mkdir -p /container/service +mkdir -p /container/environment /container/environment/startup +chmod 700 /container/environment/ /container/environment/startup + +groupadd -g 8377 docker_env + +# dpkg options +cp /container/file/dpkg_nodoc /etc/dpkg/dpkg.cfg.d/01_nodoc +cp /container/file/dpkg_nolocales /etc/dpkg/dpkg.cfg.d/01_nolocales + +# General config +export LC_ALL=C +export DEBIAN_FRONTEND=noninteractive +MINIMAL_APT_GET_INSTALL='apt-get install -y --no-install-recommends' + +## Temporarily disable dpkg fsync to make building faster. +if [[ ! -e /etc/dpkg/dpkg.cfg.d/docker-apt-speedup ]]; then + echo force-unsafe-io > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup +fi + +## Prevent initramfs updates from trying to run grub and lilo. +## https://journal.paul.querna.org/articles/2013/10/15/docker-ubuntu-on-rackspace/ +## http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=594189 +export INITRD=no +echo -n no > /container/environment/INITRD + +## Enable Ubuntu Universe and Multiverse. +sed -i 's/^#\s*\(deb.*universe\)$/\1/g' /etc/apt/sources.list +sed -i 's/^#\s*\(deb.*multiverse\)$/\1/g' /etc/apt/sources.list +apt-get update + +## Fix some issues with APT packages. +## See https://github.com/dotcloud/docker/issues/1024 +dpkg-divert --local --rename --add /sbin/initctl +ln -sf /bin/true /sbin/initctl + +## Replace the 'ischroot' tool to make it always return true. +## Prevent initscripts updates from breaking /dev/shm. +## https://journal.paul.querna.org/articles/2013/10/15/docker-ubuntu-on-rackspace/ +## https://bugs.launchpad.net/launchpad/+bug/974584 +dpkg-divert --local --rename --add /usr/bin/ischroot +ln -sf /bin/true /usr/bin/ischroot + +<<<<<<< HEAD +## Install HTTPS support for APT. +$minimal_apt_get_install apt-transport-https ca-certificates + +## Install add-apt-repository +$minimal_apt_get_install software-properties-common +======= +## Install apt-utils. +$MINIMAL_APT_GET_INSTALL apt-utils python locales +>>>>>>> stable + +## Upgrade all packages. +apt-get dist-upgrade -y --no-install-recommends + +# fix locale +$minimal_apt_get_install language-pack-en +locale-gen en_US +update-locale LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 + +echo -n C.UTF-8 > /container/environment/LANG +echo -n C.UTF-8 > /container/environment/LANGUAGE +echo -n C.UTF-8 > /container/environment/LC_CTYPE + +# install PyYAML +tar -C /container/file/ -xvf /container/file/PyYAML-3.11.tar.gz +cd /container/file/PyYAML-3.11/ +python3 setup.py install +cd - + +apt-get clean +rm -rf /tmp/* /var/tmp/* +rm -rf /var/lib/apt/lists/* +rm -f /etc/dpkg/dpkg.cfg.d/02apt-speedup + +# Remove useless files +rm -rf /container/file +rm -rf /container/build.sh /container/Dockerfile diff --git a/image/service-available/:cfssl/assets/tool/cfssl-helper b/image/service-available/:cfssl/assets/tool/cfssl-helper index 3dc92fce..5d6180d5 100755 --- a/image/service-available/:cfssl/assets/tool/cfssl-helper +++ b/image/service-available/:cfssl/assets/tool/cfssl-helper @@ -40,7 +40,6 @@ if [ ! -e "$CERT_FILE" ] && [ ! -e "$KEY_FILE" ]; then esac # set env vars - PREFIX=$1 PREFIX=${PREFIX^^} # uppercase # search for prefixed env var first @@ -137,7 +136,7 @@ if [ ! -e "$CERT_FILE" ] && [ ! -e "$KEY_FILE" ]; then CONFIG_PARAM="-config $CONFIG_FILE" elif [ -n "$CFSSL_CONFIG" ]; then - echo "use $CFSSL_CONFIG as config file" + log-helper debug "use $CFSSL_CONFIG as config file" cp -f $CFSSL_CONFIG $CONFIG_FILE CONFIG_PARAM="-config $CONFIG_FILE" fi @@ -176,7 +175,14 @@ if [ ! -e "$CERT_FILE" ] && [ ! -e "$KEY_FILE" ]; then fi log-helper debug "done :)" +elif [ ! -e "$KEY_FILE" ]; then + log-helper error "Certificate file $CERT_FILE exists but not key file $KEY_FILE" + exit 1 +elif [ ! -e "$CERT_FILE" ]; then + log-helper error "Key file $KEY_FILE exists but not certificate file $CERT_FILE" + exit 1 else - log-helper info "Files $CERT_FILE or $KEY_FILE already exists," - log-helper info "do nothing." + log-helper debug "Files $CERT_FILE and $KEY_FILE exists, fix files permissions" + chmod 644 $CERT_FILE + chmod 600 $KEY_FILE fi diff --git a/image/service-available/:cfssl/download.sh b/image/service-available/:cfssl/download.sh index 70e10cee..e6582c95 100755 --- a/image/service-available/:cfssl/download.sh +++ b/image/service-available/:cfssl/download.sh @@ -1,30 +1,30 @@ #!/bin/bash -e # download curl and ca-certificate from apt-get if needed -TO_INSTALL="" +to_install="" if [ $(dpkg-query -W -f='${Status}' curl 2>/dev/null | grep -c "ok installed") -eq 0 ]; then - TO_INSTALL="curl" + to_install="curl" fi if [ $(dpkg-query -W -f='${Status}' ca-certificates 2>/dev/null | grep -c "ok installed") -eq 0 ]; then - TO_INSTALL="$TO_INSTALL ca-certificates" + to_install="$to_install ca-certificates" fi -if [ -n "$TO_INSTALL" ]; then - LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $TO_INSTALL +if [ -n "$to_install" ]; then + LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $to_install fi # download libltdl-dev from apt-get LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends libltdl-dev -curl -o /usr/sbin/cfssl -SL https://pkg.cfssl.org/R1.1/cfssl_linux-amd64 +curl -o /usr/sbin/cfssl -SL https://github.com/osixia/cfssl/raw/master/bin/cfssl chmod 700 /usr/sbin/cfssl -curl -o /usr/sbin/cfssljson -SL https://pkg.cfssl.org/R1.1/cfssljson_linux-amd64 +curl -o /usr/sbin/cfssljson -SL https://github.com/osixia/cfssl/raw/master/bin/cfssljson chmod 700 /usr/sbin/cfssljson # remove tools installed to download cfssl -if [ -n "$TO_INSTALL" ]; then - apt-get remove -y --purge --auto-remove $TO_INSTALL +if [ -n "$to_install" ]; then + apt-get remove -y --purge --auto-remove $to_install fi diff --git a/image/service-available/:cfssl/startup.sh b/image/service-available/:cfssl/startup.sh index 59e8947e..fffb8d92 100755 --- a/image/service-available/:cfssl/startup.sh +++ b/image/service-available/:cfssl/startup.sh @@ -1,13 +1,5 @@ #!/bin/bash -e log-helper level eq trace && set -x -FIRST_START_DONE="${CONTAINER_STATE_DIR}/cfssl-first-start-done" - -# container first start -if [ ! -e "$FIRST_START_DONE" ]; then - - chmod 700 ${CONTAINER_SERVICE_DIR}/:cfssl/assets/tool/* - ln -s ${CONTAINER_SERVICE_DIR}/:cfssl/assets/tool/* /usr/sbin - - touch $FIRST_START_DONE -fi +chmod 700 ${CONTAINER_SERVICE_DIR}/:cfssl/assets/tool/* +ln -sf ${CONTAINER_SERVICE_DIR}/:cfssl/assets/tool/* /usr/sbin diff --git a/image/service-available/:logrotate/startup.sh b/image/service-available/:logrotate/startup.sh index c45851ce..a9d7a76d 100755 --- a/image/service-available/:logrotate/startup.sh +++ b/image/service-available/:logrotate/startup.sh @@ -1,12 +1,4 @@ #!/bin/bash -e log-helper level eq trace && set -x -FIRST_START_DONE="${CONTAINER_STATE_DIR}/logrotate-first-start-done" - -# container first start -if [ ! -e "$FIRST_START_DONE" ]; then - - ln -s ${CONTAINER_SERVICE_DIR}/:logrotate/assets/config/logrotate_syslogng /etc/logrotate.d/syslog-ng - - touch $FIRST_START_DONE -fi +ln -sf ${CONTAINER_SERVICE_DIR}/:logrotate/assets/config/logrotate_syslogng /etc/logrotate.d/syslog-ng diff --git a/image/service-available/:syslog-ng-core/startup.sh b/image/service-available/:syslog-ng-core/startup.sh index 84514efe..8d58601b 100755 --- a/image/service-available/:syslog-ng-core/startup.sh +++ b/image/service-available/:syslog-ng-core/startup.sh @@ -1,17 +1,9 @@ #!/bin/bash -e log-helper level eq trace && set -x -FIRST_START_DONE="${CONTAINER_STATE_DIR}/syslog-ng-first-start-done" +ln -sf ${CONTAINER_SERVICE_DIR}/:syslog-ng-core/assets/config/syslog_ng_default /etc/default/syslog-ng +ln -sf ${CONTAINER_SERVICE_DIR}/:syslog-ng-core/assets/config/syslog-ng.conf /etc/syslog-ng/syslog-ng.conf -# container first start -if [ ! -e "$FIRST_START_DONE" ]; then - - ln -s ${CONTAINER_SERVICE_DIR}/:syslog-ng-core/assets/config/syslog_ng_default /etc/default/syslog-ng - ln -s ${CONTAINER_SERVICE_DIR}/:syslog-ng-core/assets/config/syslog-ng.conf /etc/syslog-ng/syslog-ng.conf - - ## Install syslog to "docker logs" forwarder. - mkdir /container/run/process/syslog-forwarder - ln -s ${CONTAINER_SERVICE_DIR}/:syslog-ng-core/process-syslog-forwarder.sh /container/run/process/syslog-forwarder/run - - touch $FIRST_START_DONE -fi +## Install syslog to "docker logs" forwarder. +[ -d /container/run/process/:syslog-forwarder ] || mkdir -p /container/run/process/:syslog-forwarder +ln -sf ${CONTAINER_SERVICE_DIR}/:syslog-ng-core/process-syslog-forwarder.sh /container/run/process/:syslog-forwarder/run diff --git a/image/tool/add-service-available b/image/tool/add-service-available index 2cab48b3..6d9b53fa 100755 --- a/image/tool/add-service-available +++ b/image/tool/add-service-available @@ -3,24 +3,28 @@ # Usage : # RUN /container/tool/add-service-available [service1] [service2] ... +SERVICE_DIR="/container/service" +SERVICE_AVAILABLE_DIR="/container/service-available" +DOWNLOAD_FILENAME="download.sh" + for i in $@ do echo "add-service-available: $i" - if [ -d "/container/service-available/$i" ]; then + if [ -d "${SERVICE_AVAILABLE_DIR}/$i" ]; then - if [ -f /container/service-available/$i/download.sh ]; then - echo "run /container/service-available/$i/download.sh" - /container/service-available/$i/download.sh - echo "remove /container/service-available/$i/download.sh" - rm -f /container/service-available/$i/download.sh + if [ -f ${SERVICE_AVAILABLE_DIR}/$i/${DOWNLOAD_FILENAME} ]; then + echo "run ${SERVICE_AVAILABLE_DIR}/$i/${DOWNLOAD_FILENAME}" + ${SERVICE_AVAILABLE_DIR}/$i/${DOWNLOAD_FILENAME} + echo "remove ${SERVICE_AVAILABLE_DIR}/$i/${DOWNLOAD_FILENAME}" + rm -f ${SERVICE_AVAILABLE_DIR}/$i/${DOWNLOAD_FILENAME} fi - echo "move /container/service-available/$i to /container/service/$i" - mv /container/service-available/$i /container/service/$i + echo "move ${SERVICE_AVAILABLE_DIR}/$i to ${SERVICE_DIR}/$i" + mv ${SERVICE_AVAILABLE_DIR}/$i ${SERVICE_DIR}/$i else - echo "service-available: $i not found in /container/service-available/$i" + echo "service-available: $i not found in ${SERVICE_AVAILABLE_DIR}/$i" exit 1 fi done diff --git a/image/tool/complex-bash-env b/image/tool/complex-bash-env index c9c4aca7..384a7d3c 100755 --- a/image/tool/complex-bash-env +++ b/image/tool/complex-bash-env @@ -1,31 +1,21 @@ #!/bin/bash -e -CALL=$1 +call=$1 function iterate() { - local ENV_VAR=$(complex-bash-env stripTablePrefix "$1") - local ENV_VAR_TABLE=($ENV_VAR) - local RETURN=() + local env_var_name=$1 + local env_var=${!env_var_name} - for subenvvar in "${ENV_VAR_TABLE[@]}" - do - subenvvar_value=${!subenvvar} - - if [ $(complex-bash-env isTable "$subenvvar_value") = true ] || [ $(complex-bash-env isRow "$subenvvar_value") = true ]; then - RETURN+=($subenvvar) - elif [ -n "${subenvvar_value}" ]; then - RETURN+=($subenvvar_value) - else - RETURN+=($subenvvar) - fi - done - - echo ${RETURN[@]} + if [ $(complex-bash-env isTable "$env_var") = true ]; then + echo $(complex-bash-env stripTablePrefix "$env_var") + else + echo "$env_var_name" + fi } function isTable() { - local ENV_VAR=$1 - if [ $(echo $ENV_VAR | grep "#COMPLEX_BASH_ENV:TABLE:" -c ) -eq 1 ]; then + local env_var=$1 + if [ $(echo $env_var | grep "#COMPLEX_BASH_ENV:TABLE:" -c ) -eq 1 ]; then echo true else echo false @@ -33,8 +23,8 @@ function isTable() { } function isRow() { - local ENV_VAR=$1 - if [ $(echo $ENV_VAR | grep "#COMPLEX_BASH_ENV:ROW:" -c ) -eq 1 ]; then + local env_var=$1 + if [ $(echo $env_var | grep "#COMPLEX_BASH_ENV:ROW:" -c ) -eq 1 ]; then echo true else echo false @@ -42,43 +32,56 @@ function isRow() { } function getRowKey() { - local ENV_VAR=$1 - if [ $(complex-bash-env isRow "$ENV_VAR") = true ]; then - local ENV_VAR=$(complex-bash-env stripRowPrefix "$ENV_VAR") - local ENV_VAR_TABLE=($ENV_VAR) - echo "${!ENV_VAR_TABLE[0]}" - else - echo "$ENV_VAR is not a complex bash env row" - fi + local env_var=$1 + local row_key_var_name=$(complex-bash-env getRowKeyVarName "$env_var") + echo "${!row_key_var_name}" } function getRowValue() { - local ENV_VAR=$1 - if [ $(complex-bash-env isRow "$ENV_VAR") = true ]; then - local ENV_VAR=$(complex-bash-env stripRowPrefix "$ENV_VAR") - local ENV_VAR_TABLE=($ENV_VAR) - echo "${!ENV_VAR_TABLE[1]}" + local env_var=$1 + local row_value_var_name=$(complex-bash-env getRowValueVarName "$env_var") + echo "${!row_value_var_name}" +} + +function getRowKeyVarName() { + local env_var=$1 + local row=($(complex-bash-env getRow "$env_var")) + echo "${row[0]}" +} + +function getRowValueVarName() { + local env_var=$1 + local row=($(complex-bash-env getRow "$env_var")) + echo "${row[1]}" +} + +function getRow() { + local env_var=$1 + if [ $(complex-bash-env isRow "$env_var") = true ]; then + local env_var=$(complex-bash-env stripRowPrefix "$env_var") + echo "${env_var}" else - echo "$ENV_VAR is not a complex bash env row" + echo "$env_var is not a complex bash env row" + exit 1 fi } function stripTablePrefix() { - local ENV_VAR=$1 - stripPrefix "$ENV_VAR" "#COMPLEX_BASH_ENV:TABLE:" + local env_var=$1 + stripPrefix "$env_var" "#COMPLEX_BASH_ENV:TABLE:" } function stripRowPrefix() { - local ENV_VAR=$1 - stripPrefix "$ENV_VAR" "#COMPLEX_BASH_ENV:ROW:" + local env_var=$1 + stripPrefix "$env_var" "#COMPLEX_BASH_ENV:ROW:" } function stripPrefix() { - local ENV_VAR=$1 - local PREFIX=$2 - local RETURN=${ENV_VAR#$PREFIX} - echo $RETURN + local env_var=$1 + local prefix=$2 + local r=${env_var#$prefix} + echo $r } shift -$CALL "$@" +$call "$@" diff --git a/image/tool/install-service b/image/tool/install-service index f3579b85..5d5a1a4f 100755 --- a/image/tool/install-service +++ b/image/tool/install-service @@ -2,29 +2,31 @@ import os, os.path, subprocess SERVICE_DIR = "/container/service" +INSTALL_FILENAME = "install.sh" +PROCESS_FILENAME = "process.sh" nb_process = 0 print("install-service") # Auto run global install script if available -if os.path.isfile(SERVICE_DIR + os.sep + "install.sh"): - print("run " + SERVICE_DIR + os.sep + "install.sh") - subprocess.call([SERVICE_DIR + os.sep + "install.sh"],shell=True) +if os.path.isfile(SERVICE_DIR + os.sep + INSTALL_FILENAME): + print("run " + SERVICE_DIR + os.sep + INSTALL_FILENAME) + subprocess.call([SERVICE_DIR + os.sep + INSTALL_FILENAME],shell=True) - print("remove " + SERVICE_DIR + os.sep + "install.sh\n") - os.remove(SERVICE_DIR + os.sep + "install.sh") + print("remove " + SERVICE_DIR + os.sep + INSTALL_FILENAME + "\n") + os.remove(SERVICE_DIR + os.sep + INSTALL_FILENAME) # Process install script of services in /container/service for service in sorted(os.listdir(SERVICE_DIR)): - if os.path.isfile(SERVICE_DIR + os.sep + service + os.sep + "install.sh"): - print("run " + SERVICE_DIR + os.sep + service + os.sep + "install.sh") - subprocess.call([SERVICE_DIR + os.sep + service + os.sep + "install.sh"],shell=True) + if os.path.isfile(SERVICE_DIR + os.sep + service + os.sep + INSTALL_FILENAME): + print("run " + SERVICE_DIR + os.sep + service + os.sep + INSTALL_FILENAME) + subprocess.call([SERVICE_DIR + os.sep + service + os.sep + INSTALL_FILENAME],shell=True) - print("remove " + SERVICE_DIR + os.sep + service + os.sep + "install.sh") - os.remove(SERVICE_DIR + os.sep + service + os.sep + "install.sh") + print("remove " + SERVICE_DIR + os.sep + service + os.sep + INSTALL_FILENAME) + os.remove(SERVICE_DIR + os.sep + service + os.sep + INSTALL_FILENAME) - if os.path.isfile(SERVICE_DIR + os.sep + service + os.sep + "process.sh"): + if os.path.isfile(SERVICE_DIR + os.sep + service + os.sep + PROCESS_FILENAME): nb_process += 1 diff --git a/image/tool/log-helper b/image/tool/log-helper index 69d9e5c9..ee6d4667 100755 --- a/image/tool/log-helper +++ b/image/tool/log-helper @@ -15,78 +15,78 @@ LOG_LEVEL_DEBUG=4 LOG_LEVEL_TRACE=5 # default log level if CONTAINER_LOG_LEVEL is not set -> info -LOG_LEVEL=${CONTAINER_LOG_LEVEL:-${LOG_LEVEL_INFO}} +log_level=${CONTAINER_LOG_LEVEL:-${LOG_LEVEL_INFO}} -CALL=$1 # function to call (error, warning, info, debug, trace, level) -if [[ ! "$CALL" =~ ^(error|warning|info|debug|trace|level)$ ]]; then - echo "Error: Function $CALL not found" +call=$1 # function to call (error, warning, info, debug, trace, level) +if [[ ! "$call" =~ ^(error|warning|info|debug|trace|level)$ ]]; then + echo "Error: Function $call not found" echo "Allowed functions are: error, warning, info, debug, trace, level" echo "usage example: log-helper info hello !" exit 1 fi -ECHO_MSG="" # message to print if required log level is set -ECHO_PARAM="" # echo command parameters +echo_msg="" # message to print if required log level is set +echo_param="" # echo command parameters function error() { getEchoParams $@ - if [ $LOG_LEVEL -ge 1 ]; then - [[ -z "$ECHO_MSG" ]] && getMsgFromStdin - echo $ECHO_PARAM "$ECHO_MSG" + if [ $log_level -ge 1 ]; then + [[ -z "$echo_msg" ]] && getMsgFromStdin + echo $echo_param "$echo_msg" fi } function warning() { getEchoParams $@ - if [ $LOG_LEVEL -ge 2 ]; then - [[ -z "$ECHO_MSG" ]] && getMsgFromStdin - echo $ECHO_PARAM "$ECHO_MSG" + if [ $log_level -ge 2 ]; then + [[ -z "$echo_msg" ]] && getMsgFromStdin + echo $echo_param "$echo_msg" fi } function info() { getEchoParams $@ - if [ $LOG_LEVEL -ge 3 ]; then - [[ -z "$ECHO_MSG" ]] && getMsgFromStdin - echo $ECHO_PARAM "$ECHO_MSG" + if [ $log_level -ge 3 ]; then + [[ -z "$echo_msg" ]] && getMsgFromStdin + echo $echo_param "$echo_msg" fi } function debug() { getEchoParams $@ - if [ $LOG_LEVEL -ge 4 ]; then - [[ -z "$ECHO_MSG" ]] && getMsgFromStdin - echo $ECHO_PARAM "$ECHO_MSG" + if [ $log_level -ge 4 ]; then + [[ -z "$echo_msg" ]] && getMsgFromStdin + echo $echo_param "$echo_msg" fi } function trace() { getEchoParams $@ - if [ $LOG_LEVEL -ge 5 ]; then - [[ -z "$ECHO_MSG" ]] && getMsgFromStdin - echo $ECHO_PARAM "$ECHO_MSG" + if [ $log_level -ge 5 ]; then + [[ -z "$echo_msg" ]] && getMsgFromStdin + echo $echo_param "$echo_msg" fi } function getMsgFromStdin() { if [ -z "$2" ]; then - read -r ECHO_MSG + read -r echo_msg fi } function getEchoParams() { - ECHO_MSG="$@" + echo_msg="$@" if [[ "$1" =~ ^(-e|-n|-E)$ ]]; then - ECHO_PARAM=$1 - ECHO_MSG=${ECHO_MSG#$1 } + echo_param=$1 + echo_msg=${echo_msg#$1 } fi } @@ -110,16 +110,16 @@ function level() { exit 1 fi - local loglevel=LOG_LEVEL_$loglevel_str + local log_level_var=LOG_LEVEL_$loglevel_str - if [ ${!loglevel} -$operator $LOG_LEVEL ]; then - return 0 + if [ ${!log_level_var} -$operator $log_level ]; then + exit 0 else - return 1 + exit 1 fi } shift -$CALL "$@" +$call "$@" exit 0 diff --git a/image/tool/run b/image/tool/run index 93614aa8..db3ecacd 100755 --- a/image/tool/run +++ b/image/tool/run @@ -2,7 +2,7 @@ import os, os.path, sys, stat, signal, errno, argparse, time, re, json, yaml, ast, socket, shutil, pwd, grp KILL_PROCESS_TIMEOUT = 5 -KILL_ALL_PROCESSES_TIMEOUT = 5 +KILL_ALL_PROCESSES_TIMEOUT = 10 LOG_LEVEL_NONE = 0 LOG_LEVEL_ERROR = 1