From e72faea77bd6b53288f115ab518f81d5ea607157 Mon Sep 17 00:00:00 2001 From: Alexander Lutay Date: Thu, 6 Sep 2018 15:56:20 +0200 Subject: [PATCH] TT#44061 Reorder all functions in scripts/services on top of the script Otherwise the code in between the functions can be easily missed which cause issues as described in the ticket and will be fixed in the following commit. Change-Id: I57decfcbcd41691d35d085b13881e1e6b5208f6e --- scripts/services | 91 +++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/scripts/services b/scripts/services index 154e4637..63d0351b 100755 --- a/scripts/services +++ b/scripts/services @@ -7,8 +7,11 @@ set -e set -u # support testsuite + FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}" +# load modules + if ! [ -r "${FUNCTIONS}"/main ] ; then printf "Error: %s/main could not be read. Exiting.\n" "${FUNCTIONS}">&2 exit 1 @@ -16,20 +19,7 @@ fi . "${FUNCTIONS}"/main -# main script - -DRYRUN='false' -if [[ "${1:-}" == "test" ]] || [[ "${1:-}" == "--dry-run" ]]; then - DRYRUN='true' -elif [[ -n "${1:-}" ]] ; then - log_error "Unsupported option(s) given: $*" - log_info "Did you mean '--dry-run'?" - exit 1 -fi -log_debug "DRYRUN = $DRYRUN" - -TMPFILE="$(mktemp)" -log_debug "TMPFILE = $TMPFILE" +# functions # unify service calls unifyer() { @@ -44,30 +34,6 @@ unifyer() { fi } -for dir in ${CONFIG_POOL} ; do - #shellcheck disable=SC2106 - ( - if ! [[ "${dir}" =~ ^/ ]] ; then - log_error "${dir} is not an absolute path" - continue - fi - cd "${dir}" - if [ ! -d .git ] ; then - log_info "$dir has no support of .services" - continue - fi - for file in $(git status --porcelain | sed 's/^...//') ; do - if [ -r "$file" ] && [ -r "${SERVICES_POOL_BASE}/${dir}/${file}".services ] ; then - log_debug "unifyer ${SERVICES_POOL_BASE}/${dir}/${file}.services" - unifyer "${SERVICES_POOL_BASE}/${dir}/${file}".services - elif [ -r "$file" ] && [ -r "${SERVICES_POOL_BASE}/${dir}/$(dirname "$file")"/ngcpcfg.services ] ; then - log_debug "unifyer ${SERVICES_POOL_BASE}/${dir}/$(dirname "$file")/ngcpcfg.services" - unifyer "${SERVICES_POOL_BASE}/${dir}/$(dirname "$file")/ngcpcfg.services" - fi - done - ) -done - exec_wrapper() { if $DRYRUN ; then log_info "TEST MODE: Would execute action for ${line}" @@ -91,11 +57,6 @@ exec_wrapper() { fi } -if ! [ -s "$TMPFILE" ] ; then - log_debug "No services file(s) reported - nothing to do." - exit 0 -fi - # get rid of "./" and "//" in file names normalize_files() { NORMALIZED_FILES="$(mktemp)" @@ -136,6 +97,50 @@ execute() { ngcp-service queue-run } +# main script + +DRYRUN='false' +if [[ "${1:-}" == "test" ]] || [[ "${1:-}" == "--dry-run" ]]; then + DRYRUN='true' +elif [[ -n "${1:-}" ]] ; then + log_error "Unsupported option(s) given: $*" + log_info "Did you mean '--dry-run'?" + exit 1 +fi +log_debug "DRYRUN = $DRYRUN" + +TMPFILE="$(mktemp)" +log_debug "TMPFILE = $TMPFILE" + +for dir in ${CONFIG_POOL} ; do + #shellcheck disable=SC2106 + ( + if ! [[ "${dir}" =~ ^/ ]] ; then + log_error "${dir} is not an absolute path" + continue + fi + cd "${dir}" + if [ ! -d .git ] ; then + log_info "$dir has no support of .services" + continue + fi + for file in $(git status --porcelain | sed 's/^...//') ; do + if [ -r "$file" ] && [ -r "${SERVICES_POOL_BASE}/${dir}/${file}".services ] ; then + log_debug "unifyer ${SERVICES_POOL_BASE}/${dir}/${file}.services" + unifyer "${SERVICES_POOL_BASE}/${dir}/${file}".services + elif [ -r "$file" ] && [ -r "${SERVICES_POOL_BASE}/${dir}/$(dirname "$file")"/ngcpcfg.services ] ; then + log_debug "unifyer ${SERVICES_POOL_BASE}/${dir}/$(dirname "$file")/ngcpcfg.services" + unifyer "${SERVICES_POOL_BASE}/${dir}/$(dirname "$file")/ngcpcfg.services" + fi + done + ) +done + +if ! [ -s "$TMPFILE" ] ; then + log_debug "No services file(s) reported - nothing to do." + exit 0 +fi + if [ -d "/run/systemd/system" ]; then log_debug "systemd needs daemon-reload so the unit files loaded are in sync" log_debug "Running: systemctl daemon-reload 2>&1 || true"