TT#37257 Unified scripts/services to Sipwise/Google shell style

Change-Id: I72b0d96516ce83192a82d3e1b30094dfe98260a3
changes/32/23532/6
Alexander Lutay 8 years ago
parent bc1095e596
commit 474b5bd32d

@ -12,7 +12,7 @@ FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
# load modules
if ! [ -r "${FUNCTIONS}"/main ] ; then
if [[ ! -r "${FUNCTIONS}"/main ]]; then
printf "Error: %s/main could not be read. Exiting.\n" "${FUNCTIONS}">&2
exit 1
fi
@ -22,24 +22,24 @@ fi
# functions
exec_wrapper() {
if $DRYRUN ; then
if ${DRYRUN} ; then
log_info "TEST MODE: Would execute action for ${line}"
return 0
fi
log_info "Executing action for $line"
if [ -x "$line" ] ; then
log_debug "$line"
if ! "$line" ; then
log_warn "$line returned with error code, continuing anyway."
log_info "Executing action for ${line}"
if [[ -x "${line}" ]]; then
log_debug "${line}"
if ! "${line}" ; then
log_warn "${line} returned with error code, continuing anyway."
fi
elif [ -r "$line" ] ; then
log_debug "bash $line"
if ! bash "$line" ; then
log_warn "$line returned with error code, continuing anyway."
elif [[ -r "${line}" ]]; then
log_debug "bash ${line}"
if ! bash "${line}" ; then
log_warn "${line} returned with error code, continuing anyway."
fi
else
log_error "Error: $line could not be read."
log_error "Error: ${line} could not be read."
exit 1
fi
}
@ -47,12 +47,12 @@ exec_wrapper() {
# get rid of "./" and "//" in file names
normalize_files() {
NORMALIZED_FILES="$(mktemp)"
log_debug "NORMALIZED_FILES = $NORMALIZED_FILES"
log_debug "NORMALIZED_FILES = ${NORMALIZED_FILES}"
while read -r line ; do
# shellcheck disable=SC2001
echo "$line" | sed -e 's_\./_/_g ; s_//_/_g' >> "${NORMALIZED_FILES}"
done < "$TMPFILE"
echo "${line}" | sed -e 's_\./_/_g ; s_//_/_g' >> "${NORMALIZED_FILES}"
done < "${TMPFILE}"
}
# restart monit services before the rest (see MT#9971)
@ -60,7 +60,7 @@ normalize_files() {
# restart other services in alphabetical order
sort_service_list() {
SORTED_LIST="$(mktemp)"
log_debug "SORTED_LIST = $SORTED_LIST"
log_debug "SORTED_LIST = ${SORTED_LIST}"
grep "${SERVICES_POOL_BASE}"/etc/monit/'.*services' "${NORMALIZED_FILES}" > \
"${SORTED_LIST}" || true
@ -78,7 +78,7 @@ execute() {
ngcp-service queue-start
while read -r line ; do
exec_wrapper "$line"
exec_wrapper "${line}"
done < "${SORTED_LIST}"
log_info "Executing enqueued services actions"
@ -86,7 +86,7 @@ execute() {
}
systed_daemon_reload_preset() {
if [ -d "/run/systemd/system" ]; then
if [[ -d "/run/systemd/system" ]]; then
log_info "Reloading systemd daemon and preset all services"
log_debug "systemd needs daemon-reload so the unit files loaded are in sync"
@ -104,7 +104,7 @@ systed_daemon_reload_preset() {
is_absolute_path() {
local dir="$1"
if [[ ! "${dir}" =~ ^/ ]] ; then
if [[ ! "${dir}" =~ ^/ ]]; then
log_error "${dir} is not an absolute path"
return 1
fi
@ -115,7 +115,7 @@ is_absolute_path() {
is_non_git_folder() {
local dir="$1"
if [[ ! -d "${dir}/.git" ]] ; then
if [[ ! -d "${dir}/.git" ]]; then
log_info "${dir} has no support of .services"
return 1
fi
@ -139,7 +139,7 @@ find_all_services() {
local dir="$1"
while read -r file ; do
if [ ! -r "${file}" ] ; then
if [[ ! -r "${file}" ]]; then
log_warn "Cannot read file '${file}'"
fi
log_debug "Storing ${file} in '${TMPFILE}'"
@ -154,10 +154,10 @@ find_all_changed_services() {
pushd "${dir}" >/dev/null
for file in $(git status --porcelain | sed 's/^...//') ; do
if [ -r "$file" ] && [ -r "${SERVICES_POOL_BASE}/${dir}/${file}".services ] ; then
if [[ -r "${file}" ]] && [[ -r "${SERVICES_POOL_BASE}/${dir}/${file}".services ]]; then
log_debug "Storing ${SERVICES_POOL_BASE}/${dir}/${file}.services in '${TMPFILE}'"
echo "${SERVICES_POOL_BASE}/${dir}/${file}".services
elif [ -r "$file" ] && [ -r "${SERVICES_POOL_BASE}/${dir}/$(dirname "$file")"/ngcpcfg.services ] ; then
elif [[ -r "${file}" ]] && [[ -r "${SERVICES_POOL_BASE}/${dir}/$(dirname "${file}")"/ngcpcfg.services ]]; then
log_debug "Storing ${SERVICES_POOL_BASE}/${dir}/$(dirname "$file")/ngcpcfg.services in '${TMPFILE}'"
echo "${SERVICES_POOL_BASE}/${dir}/$(dirname "$file")/ngcpcfg.services"
fi
@ -173,17 +173,17 @@ FORCE_ALL_SERVICES='false'
if [[ "${1:-}" == "test" ]] || [[ "${1:-}" == "--dry-run" ]]; then
DRYRUN='true'
elif [[ "${1:-}" == "--force-all-services" ]] ; then
elif [[ "${1:-}" == "--force-all-services" ]]; then
FORCE_ALL_SERVICES='true'
fi
log_debug "DRYRUN = $DRYRUN"
log_debug "FORCE_ALL_SERVICES = $FORCE_ALL_SERVICES"
log_debug "DRYRUN = ${DRYRUN}"
log_debug "FORCE_ALL_SERVICES = ${FORCE_ALL_SERVICES}"
log_debug "systed_daemon_reload_preset function"
systed_daemon_reload_preset
TMPFILE="$(mktemp)"
log_debug "TMPFILE = $TMPFILE"
log_debug "TMPFILE = ${TMPFILE}"
for dir in ${CONFIG_POOL} ; do
is_absolute_path "${dir}" || continue
@ -192,7 +192,7 @@ for dir in ${CONFIG_POOL} ; do
generate_list_to_process "${dir}"
done
if ! [ -s "$TMPFILE" ] ; then
if [[ ! -s "${TMPFILE}" ]]; then
log_debug "No services file(s) reported - nothing to do."
exit 0
fi
@ -206,9 +206,9 @@ sort_service_list
log_debug "execute function"
execute
if [ -n "${DEBUG:-}" ] ; then
if [[ -n "${DEBUG:-}" ]]; then
log_debug "Not removing temporary files"
else
rm -f "$TMPFILE" "$NORMALIZED_FILES" "$SORTED_LIST"
rm -f "${TMPFILE}" "${NORMALIZED_FILES}" "${SORTED_LIST}"
fi
## END OF FILE #################################################################

Loading…
Cancel
Save