diff options
author | Jim Hahn <jrh3@att.com> | 2020-12-02 19:03:23 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-12-02 19:03:23 +0000 |
commit | 1ae36482529aaaa266bf39b69aa2b614a1ab2f1d (patch) | |
tree | 190dea4ed08d5ea812bcced3c073518f1bc775ab /packages/base/src/files/bin | |
parent | f01256145bd9abb97cb9fba3019dcaccaeeca509 (diff) | |
parent | 8583b5150f8ccf3a1d1b0e4849346024763aa838 (diff) |
Merge "move all bash to ash shell scripts"
Diffstat (limited to 'packages/base/src/files/bin')
-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 |
3 files changed, 110 insertions, 115 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 |