diff options
author | Taka Cho <takamune.cho@att.com> | 2020-11-12 17:48:30 -0500 |
---|---|---|
committer | Taka Cho <takamune.cho@att.com> | 2020-11-30 10:20:55 -0500 |
commit | 8583b5150f8ccf3a1d1b0e4849346024763aa838 (patch) | |
tree | f36885b89485b2144c0ab287fe9f06fbdfcb5cd8 /packages | |
parent | dc6c4a21d46909dad59f4bd16cb6d4fc29fcce77 (diff) |
move all bash to ash shell scripts
this gerrit would be the first step
to not to use any GPL-3.0 and plus license
Issue-ID: POLICY-2847
Change-Id: I09a571f14ef8c6983f9051068c2bad5acc173787
Signed-off-by: Taka Cho <takamune.cho@att.com>
Diffstat (limited to 'packages')
-rw-r--r-- | packages/base/src/files/bin/configure-maven | 6 | ||||
-rw-r--r-- | packages/base/src/files/bin/monitor | 180 | ||||
-rw-r--r-- | packages/base/src/files/bin/policy | 39 | ||||
-rwxr-xr-x | packages/base/src/files/etc/cron.d/monitor.cron | 21 | ||||
-rw-r--r-- | packages/base/src/files/etc/profile.d/env.sh | 10 | ||||
-rw-r--r-- | packages/docker/src/main/docker/Dockerfile | 4 | ||||
-rw-r--r-- | packages/docker/src/main/docker/pdpd-entrypoint.sh | 70 |
7 files changed, 152 insertions, 178 deletions
diff --git a/packages/base/src/files/bin/configure-maven b/packages/base/src/files/bin/configure-maven index 7da5f6a4..34d6de70 100644 --- a/packages/base/src/files/bin/configure-maven +++ b/packages/base/src/files/bin/configure-maven @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env ash # ============LICENSE_START======================================================= # ONAP @@ -20,14 +20,14 @@ source ${POLICY_HOME}/etc/profile.d/env.sh -if [[ ${DEBUG} == y ]]; then +if [ "${DEBUG}" = "y" ]; then set -x fi HOME_M2="${HOME}"/.m2 mkdir -p "${HOME_M2}" 2> /dev/null -if [[ -z "${SNAPSHOT_REPOSITORY_URL}" && -z "${RELEASE_REPOSITORY_URL}" ]]; then +if [ -z "${SNAPSHOT_REPOSITORY_URL}" ] && [ -z "${RELEASE_REPOSITORY_URL}" ]; then ln -s -f "${POLICY_HOME}"/etc/m2/standalone-settings.xml "${HOME_M2}"/settings.xml else ln -s -f "${POLICY_HOME}"/etc/m2/settings.xml "${HOME_M2}"/settings.xml diff --git a/packages/base/src/files/bin/monitor b/packages/base/src/files/bin/monitor index 6d40f7e2..864582f1 100644 --- a/packages/base/src/files/bin/monitor +++ b/packages/base/src/files/bin/monitor @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env ash # ============LICENSE_START======================================================= # ONAP @@ -21,122 +21,118 @@ source ${POLICY_HOME}/etc/profile.d/env.sh function usage() { - echo -n "syntax: $(basename $0) " - echo "[--debug]" + echo -n "syntax: $(basename $0) " + echo "[--debug]" } function log() { - echo "$(date +"%Y-%m-%d_%H-%M-%S") $1" >> ${POLICY_HOME}/logs/monitor.log + echo "$(date +"%Y-%m-%d_%H-%M-%S") $1" >> ${POLICY_HOME}/logs/monitor.log } function monitor() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi - - CONTROLLER=$1 - STATUS=$2 - - if [[ -z ${CONTROLLER} ]]; then - log "WARNING: invalid invocation: no component provided" - return - fi - - if [[ -z ${STATUS} ]]; then - log "WARNING: invalid invocation: no on/off/uninstalled switch provided for ${CONTROLLER}" - return - fi - - if [[ "${STATUS}" == "off" ]]; then - off ${CONTROLLER} - else - if [[ "${STATUS}" == "on" ]]; then - on ${CONTROLLER} - fi - fi + if [ "$DEBUG" = "y" ]; then + echo "-- monitor --" + set -x + fi + + CONTROLLER=$1 + STATUS=$2 + + if [ -z "${CONTROLLER}" ]; then + log "WARNING: invalid invocation: no component provided" + return + fi + + if [ -z "${STATUS}" ]; then + log "WARNING: invalid invocation: no on/off/uninstalled switch provided for ${CONTROLLER}" + return + fi + + if [ "${STATUS}" = "off" ]; then + off ${CONTROLLER} + else + if [ "${STATUS}" = "on" ]; then + on ${CONTROLLER} + fi + fi } function on() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi - - CONTROLLER=$1 - - ${POLICY_HOME}/bin/${CONTROLLER} status - if [[ $? != 0 ]]; then - log "starting ${CONTROLLER}" - - # need to make sure we don't pass the lock file descriptor - ${POLICY_HOME}/bin/${CONTROLLER} umstart {cfg}>&- - else - log "OK: ${CONTROLLER} (UP)" - fi + if [ "$DEBUG" = "y" ]; then + echo "-- on --" + set -x + fi + + CONTROLLER=$1 + + ${POLICY_HOME}/bin/${CONTROLLER} status + if [ $? -ne 0 ]; then + log "starting ${CONTROLLER}" + + # need to make sure we don't pass the lock file descriptor + ${POLICY_HOME}/bin/${CONTROLLER} umstart 200>&- + else + log "OK: ${CONTROLLER} (UP)" + fi } function off() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi - - CONTROLLER=$1 - - ${POLICY_HOME}/bin/${CONTROLLER} status - if [[ $? != 0 ]]; then - log "OK: ${CONTROLLER} (DOWN)" - - else - log "stopping ${CONTROLLER}" - ${POLICY_HOME}/bin/${CONTROLLER} umstop - fi + if [ "$DEBUG" = "y" ]; then + echo "-- off --" + set -x + fi + + CONTROLLER=$1 + + ${POLICY_HOME}/bin/${CONTROLLER} status + if [ $? -ne 0 ]; then + log "OK: ${CONTROLLER} (DOWN)" + + else + log "stopping ${CONTROLLER}" + ${POLICY_HOME}/bin/${CONTROLLER} umstop + fi } function process_config() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi - - CONF_FILE=${POLICY_HOME}/etc/monitor/monitor.cfg - while read line || [ -n "${line}" ]; do - if [[ -n ${line} ]] && [[ ${line} != *#* ]]; then - controller=$(echo "${line}" | awk -F = '{print $1;}') - status=$(echo "${line}" | awk -F = '{print $2;}') - if [[ -n ${controller} ]] && [[ -n ${status} ]]; then - monitor ${controller} ${status} - fi - fi - done < "${CONF_FILE}" - return 0 + if [ "$DEBUG" = "y" ]; then + echo "-- process_config --" + set -x + fi + local lines=$(grep "^[^#;]" ${CON_FILE} 2> /dev/null) + for line in ${lines} ; do + controller=$(echo "${line}" | awk -F = '{print $1;}') + status=$(echo "${line}" | awk -F = '{print $2;}') + if [ -n "${controller}" ] && [ -n "${status}" ]; then + monitor ${controller} ${status} + fi + done + return 0 } log "Enter monitor" DEBUG=n until [[ -z "$1" ]]; do - case $1 in - -d|--debug|debug) DEBUG=y - set -x - ;; - *) usage - exit 1 - ;; - esac - shift + case $1 in + -d|--debug|debug) DEBUG=y + set -x + ;; + *) usage + exit 1 + ;; + esac + shift done if pidof -o %PPID -x $(basename $0) > /dev/null 2>&1; then - log "WARNING: $(basename $0) from the previous iteration still running. Exiting." - exit 1 + log "WARNING: $(basename $0) from the previous iteration still running. Exiting." + exit 1 fi +CONF_FILE=${POLICY_HOME}/etc/monitor/monitor.cfg . ${POLICY_HOME}/etc/profile.d/env.sh -if flock ${cfg} ; then - process_config -fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock - - +if flock 200 ; then + process_config +fi 200>>${CONF_FILE}.lock diff --git a/packages/base/src/files/bin/policy b/packages/base/src/files/bin/policy index 9bc294d8..3ba75f0d 100644 --- a/packages/base/src/files/bin/policy +++ b/packages/base/src/files/bin/policy @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env ash # ============LICENSE_START======================================================= # ONAP @@ -25,8 +25,8 @@ function usage() { } function check_x_file() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- check_x_file --" set -x fi @@ -39,8 +39,8 @@ function check_x_file() { } function policy_op() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- policy_op --" set -x fi @@ -53,13 +53,13 @@ function policy_op() { ${BIN_SCRIPT} ${operation} >/tmp/out$$ echo " L [${controller}]: $(sed ':a;N;$!ba;s/\n/ /g' /tmp/out$$)" else - echo " L [${controller}]: -" + echo " L [${controller}]: -" fi } function policy_status() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- policy_status --" set -x fi @@ -67,14 +67,14 @@ function policy_status() { policy_op "status" NUM_CRONS=$(crontab -l 2>/dev/null | wc -l) - echo " ${NUM_CRONS} cron jobs installed." + echo " ${NUM_CRONS} cron jobs installed." echo echo "[features]" features status local databases=$(ls -d "${POLICY_HOME}"/etc/db/migration/*/ 2>/dev/null) - if [[ -n ${databases} ]]; then + if [ -n "${databases}" ]; then echo "[migration]" db-migrator -s ALL -o ok fi @@ -82,8 +82,8 @@ function policy_status() { } function policy_start() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- policy_start --" set -x fi @@ -91,8 +91,8 @@ function policy_start() { } function policy_exec() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- policy_exec --" set -x fi @@ -103,8 +103,8 @@ function policy_exec() { } function policy_stop() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- policy_stop --" set -x fi @@ -119,15 +119,14 @@ function policy_stop() { source ${POLICY_HOME}/etc/profile.d/env.sh -if [[ ${DEBUG} == y ]]; then +if [ "${DEBUG}" = "y" ]; then echo "-- $0 $* --" set -x fi BIN_SCRIPT="bin/policy-management-controller" OPERATION=none - -until [[ -z "$1" ]]; do +until [ -z "$1" ]; do case $1 in -d | --debug | debug) DEBUG=y @@ -166,7 +165,7 @@ halt) ;; ;; esac -if [[ -z ${POLICY_HOME} ]]; then +if [ -z "${POLICY_HOME}" ]; then echo "error: POLICY_HOME is unset." exit 1 fi diff --git a/packages/base/src/files/etc/cron.d/monitor.cron b/packages/base/src/files/etc/cron.d/monitor.cron deleted file mode 100755 index 338c1d44..00000000 --- a/packages/base/src/files/etc/cron.d/monitor.cron +++ /dev/null @@ -1,21 +0,0 @@ -### -# ============LICENSE_START======================================================= -# ONAP -# ================================================================================ -# Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END========================================================= -### - -* * * * * bash -l -c '${POLICY_HOME}/bin/monitor >/dev/null 2>&1' diff --git a/packages/base/src/files/etc/profile.d/env.sh b/packages/base/src/files/etc/profile.d/env.sh index 9ffd026c..a1b9fa7d 100644 --- a/packages/base/src/files/etc/profile.d/env.sh +++ b/packages/base/src/files/etc/profile.d/env.sh @@ -1,16 +1,16 @@ -#!/bin/bash +#!/bin/ash ### # ============LICENSE_START======================================================= # ONAP # ================================================================================ -# Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. +# Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -28,7 +28,7 @@ templateRegex='^\$\{\{POLICY_HOME}}$' -if [[ -z "${POLICY_HOME}" ]]; then +if [ -z "${POLICY_HOME}" ]; then templatedPolicyHome='${{POLICY_HOME}}' if [[ ! ${templatedPolicyHome} =~ ${templateRegex} ]]; then POLICY_HOME=${templatedPolicyHome} diff --git a/packages/docker/src/main/docker/Dockerfile b/packages/docker/src/main/docker/Dockerfile index 0ddb829e..691a01e2 100644 --- a/packages/docker/src/main/docker/Dockerfile +++ b/packages/docker/src/main/docker/Dockerfile @@ -61,14 +61,14 @@ COPY --chown=policy:policy /maven/install-drools.zip pdpd-entrypoint.sh $POLICY_ WORKDIR $POLICY_INSTALL USER policy:policy -SHELL ["/bin/bash", "-c"] +SHELL ["/bin/ash", "-c"] RUN unzip -o install-drools.zip && \ rm install-drools.zip && \ chown -R policy:policy * && \ mkdir -p $POLICY_HOME/logs $POLICY_HOME/config $HOME/.m2 && \ tar -C $POLICY_HOME -xvf base-${BUILD_VERSION_DROOLS}.tar.gz --no-same-owner && \ unzip policy-management-${BUILD_VERSION_DROOLS}.zip -d $POLICY_HOME && \ - echo "source $POLICY_HOME/etc/profile.d/env.sh" >> "$HOME/.bashrc" && \ + echo "source $POLICY_HOME/etc/profile.d/env.sh" >> "$HOME/.profile" && \ mv pdpd-entrypoint.sh $POLICY_HOME/bin/ && \ chmod 700 $POLICY_HOME/bin/* && \ chmod 600 $POLICY_HOME/config/* && \ diff --git a/packages/docker/src/main/docker/pdpd-entrypoint.sh b/packages/docker/src/main/docker/pdpd-entrypoint.sh index fb98e86a..56b53e3e 100644 --- a/packages/docker/src/main/docker/pdpd-entrypoint.sh +++ b/packages/docker/src/main/docker/pdpd-entrypoint.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env ash # ######################################################################## # Copyright 2019-2020 AT&T Intellectual Property. All rights reserved @@ -18,19 +18,19 @@ function maven { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "${DEBUG}" = "y" ]; then + echo "-- maven --" set -x fi - if [[ -f "${POLICY_INSTALL_INIT}"/settings.xml ]]; then + if [ -f "${POLICY_INSTALL_INIT}"/settings.xml ]; then if ! cmp -s "${POLICY_INSTALL_INIT}"/settings.xml "${POLICY_HOME}"/etc/m2/settings.xml; then echo "overriding settings.xml" cp -f "${POLICY_INSTALL_INIT}"/settings.xml "${POLICY_HOME}"/etc/m2 fi fi - if [[ -f "${POLICY_INSTALL_INIT}"/standalone-settings.xml ]]; then + if [ -f "${POLICY_INSTALL_INIT}"/standalone-settings.xml ]; then if ! cmp -s "${POLICY_INSTALL_INIT}"/standalone-settings.xml "${POLICY_HOME}"/etc/m2/standalone-settings.xml; then echo "overriding standalone-settings.xml" cp -f "${POLICY_INSTALL_INIT}"/standalone-settings.xml "${POLICY_HOME}"/etc/m2 @@ -39,8 +39,8 @@ function maven { } function systemConfs { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "${DEBUG}" = "y" ]; then + echo "-- systemConfs --" set -x fi @@ -61,8 +61,8 @@ function systemConfs { } function features { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "${DEBUG}" = "y" ]; then + echo "-- features --" set -x fi @@ -79,8 +79,8 @@ function features { } function scripts { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "${DEBUG}" = "y" ]; then + echo "-- scripts --" set -x fi @@ -99,26 +99,26 @@ function scripts { } function security { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "${DEBUG}" = "y" ]; then + echo "-- security --" set -x fi - if [[ -f "${POLICY_INSTALL_INIT}"/policy-keystore ]]; then + if [ -f "${POLICY_INSTALL_INIT}"/policy-keystore ]; then if ! cmp -s "${POLICY_INSTALL_INIT}"/policy-keystore "${POLICY_HOME}"/etc/ssl/policy-keystore; then echo "overriding policy-keystore" cp -f "${POLICY_INSTALL_INIT}"/policy-keystore "${POLICY_HOME}"/etc/ssl fi fi - if [[ -f ${POLICY_INSTALL_INIT}/policy-truststore ]]; then + if [ -f "${POLICY_INSTALL_INIT}"/policy-truststore ]; then if ! cmp -s "${POLICY_INSTALL_INIT}"/policy-truststore "${POLICY_HOME}"/etc/ssl/policy-truststore; then echo "overriding policy-truststore" cp -f "${POLICY_INSTALL_INIT}"/policy-truststore "${POLICY_HOME}"/etc/ssl fi fi - if [[ -f "${POLICY_INSTALL_INIT}"/aaf-cadi.keyfile ]]; then + if [ -f "${POLICY_INSTALL_INIT}"/aaf-cadi.keyfile ]; then if ! cmp -s "${POLICY_INSTALL_INIT}"/aaf-cadi.keyfile "${POLICY_HOME}"/config/aaf-cadi.keyfile; then echo "overriding aaf-cadi.keyfile" cp -f "${POLICY_INSTALL_INIT}"/aaf-cadi.keyfile "${POLICY_HOME}"/config/aaf-cadi.keyfile @@ -127,8 +127,8 @@ function security { } function serverConfig { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "${DEBUG}" = "y" ]; then + echo "-- serverConfig --" set -x fi @@ -145,24 +145,24 @@ function serverConfig { } function db { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "${DEBUG}" = "y" ]; then + echo "-- db --" set -x fi - if [[ -z ${SQL_HOST} ]]; then + if [ -z "${SQL_HOST}" ]; then return 0 fi echo "Wating for ${SQL_HOST} ." - timeout 120 bash -c 'until nc -vz "${SQL_HOST}" 3306; do echo -n "."; sleep 1; done'; echo $? + timeout 120 ash -c 'until nc -vz "${SQL_HOST}" 3306; do echo -n "."; sleep 1; done'; echo $? "${POLICY_HOME}"/bin/db-migrator -s ALL -o upgrade } function inspect { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "${DEBUG}" = "y" ]; then + echo "-- inspect --" set -x fi @@ -179,8 +179,8 @@ function inspect { } function reload { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "${DEBUG}" = "y" ]; then + echo "-- reload --" set -x fi @@ -195,8 +195,8 @@ function reload { } function start { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "${DEBUG}" = "y" ]; then + echo "-- start --" set -x fi @@ -205,8 +205,8 @@ function start { } function configure { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "${DEBUG}" = "y" ]]; then + echo "-- configure --" set -x fi @@ -215,8 +215,8 @@ function configure { } function vmBoot { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "${DEBUG}" = "y" ]; then + echo "-- vmBoot --" set -x fi @@ -227,8 +227,8 @@ function vmBoot { } function dockerBoot { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "${DEBUG}" = "y" ]; then + echo "-- dockerBoot --" set -x fi @@ -240,7 +240,7 @@ function dockerBoot { policy exec } -if [[ ${DEBUG} == y ]]; then +if [ "${DEBUG}" = "y" ]; then echo "-- $0 $* --" set -x fi |