From 1afd1877ff2ee241992852fc6405ffa3fad5e32a Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Mon, 3 Nov 2014 23:20:33 +0100 Subject: [PATCH] MT#9971 Restart monit services before any other services A random order of service restarts might not work because a service might depend on specific monit resource(s). Therefore restart monit before any other service(s). Change-Id: If6eae434014f00a76fdd66aac8c82dfd69b86f1b (cherry picked from commit 4733a4c6821933243bca7fe300fad41479d29470) --- scripts/services | 52 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/scripts/services b/scripts/services index 99372c40..d35a8033 100755 --- a/scripts/services +++ b/scripts/services @@ -26,6 +26,7 @@ fi log_debug "DRYRUN = $DRYRUN" TMPFILE="$(mktemp)" +log_debug "TMPFILE = $TMPFILE" # unify service calls unifyer() { @@ -36,7 +37,7 @@ unifyer() { # happen if /etc/foo/ngcpcfg.services exists # and several file inside /etc/foo are modified) if ! grep -q "^${file}$" "$TMPFILE" ; then - echo "$file" >> $TMPFILE + echo "$file" >> "$TMPFILE" fi } @@ -64,9 +65,6 @@ for dir in ${CONFIG_POOL} ; do done exec_wrapper() { - # normalize path (get rid of "./" and "//") - line="$(echo $1 | sed -e 's/\.\///g ; s/\/\//\//g')" - if $DRYRUN ; then log_info "TEST MODE: Would execute action for ${line}" return 0 @@ -89,10 +87,48 @@ exec_wrapper() { fi } -for line in $(cat $TMPFILE) ; do - exec_wrapper "$line" -done +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)" + log_debug "NORMALIZED_FILES = $NORMALIZED_FILES" + + while read line ; do + echo "$line" | sed -e 's_\./_/_g ; s_//_/_g' >> "${NORMALIZED_FILES}" + done < "$TMPFILE" +} + +# restart monit services before the rest (see MT#9971) +sort_service_list() { + SORTED_LIST="$(mktemp)" + log_debug "SORTED_LIST = $SORTED_LIST" -rm -f "$TMPFILE" + grep '/etc/ngcp-config/templates/etc/monit/.*services' "${NORMALIZED_FILES}" > "${SORTED_LIST}" + grep -v '/etc/ngcp-config/templates/etc/monit/.*services' "${NORMALIZED_FILES}" >> "${SORTED_LIST}" +} + +execute() { + while read line ; do + exec_wrapper "$line" + done < "${SORTED_LIST}" +} + +log_debug "normalize_files function" +normalize_files +log_debug "sort_service_list function" +sort_service_list + +log_debug "execute function" +execute + +if [ -n "${DEBUG:-}" ] ; then + log_debug "Not removing temporary files" +else + rm -f "$TMPFILE" "$NORMALIZED_FILES" "$SORTED_LIST" +fi ## END OF FILE #################################################################