From c3e1cb68d4ef0e692895491d29e7c29066d30b56 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Tue, 7 May 2013 12:45:51 +0200 Subject: [PATCH] support additional configuration yml files via configuration directory Files in configuration directory EXTRA_CONFIG_DIR (being /etc/ngcp-config/config.d/ by default) with the suffix yml (so e.g. a file named pbx.yml can be shipped by an external Debian package) are additionally taken into consideration as main configuration files. Those extra configuration file(s) have higher precedence than the other yml configuration files (config.yml, network.yml,...), *except* for constants.yml which has the power to override all settings, including the ones from files inside EXTRA_CONFIG_DIR. Closes: sipwise-#3059 --- docs/ngcpcfg.txt | 9 ++++++++- etc/ngcp-config/ngcpcfg.cfg | 1 + functions/main | 8 ++++++++ helper/build_config | 6 +++--- scripts/build | 27 ++++++++++++++++++++++----- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/docs/ngcpcfg.txt b/docs/ngcpcfg.txt index 9fe9c47a..e315f98a 100644 --- a/docs/ngcpcfg.txt +++ b/docs/ngcpcfg.txt @@ -71,6 +71,12 @@ provides global variables used inside ngcpcfg and its helper scripts. This file is *not* supposed to be modified by the user (without having a very good reason). +* _/etc/ngcp-config/config.d/_: optional configuration directory with additional +yml configuration files. Files inside this directory aren't supposed to be +added or modified by the user. The purpose of this configuration directory is +that software packages can enable/disable certain features through configuration +options on demand. + * _/etc/ngcp-config/ngcpcfg.d/_: configuration directory for ngcpcfg itself. Files with suffix '.cfg' inside this directory are sourced after /etc/ngcp-config/ngcpcfg.cfg has been read. Files inside this directory are @@ -78,7 +84,8 @@ Files with suffix '.cfg' inside this directory are sourced after [IMPORTANT] Configuration file priority: constants.yml takes precedence over -config.local.yml, over config.$HOSTNAME.yml, over config.yml. +all files in _/etc/ngcp-config/config.d/_, over config.local.yml, +over config.$HOSTNAME.yml, over config.yml. High Availability setup specific configuration files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/etc/ngcp-config/ngcpcfg.cfg b/etc/ngcp-config/ngcpcfg.cfg index 2f3e6cca..416fcb3c 100644 --- a/etc/ngcp-config/ngcpcfg.cfg +++ b/etc/ngcp-config/ngcpcfg.cfg @@ -9,6 +9,7 @@ HOST_CONFIG="${NGCPCTL_MAIN}/config.$(hostname).yml" LOCAL_CONFIG="${NGCPCTL_MAIN}/config.local.yml" CONSTANTS_CONFIG="${NGCPCTL_MAIN}/constants.yml" NETWORK_CONFIG="${NGCPCTL_MAIN}/network.yml" +EXTRA_CONFIG_DIR="${NGCPCTL_MAIN}/config.d/" # configuration files that should be managed CONFIG_POOL='/etc' diff --git a/functions/main b/functions/main index 7e64bbe6..dbb402aa 100644 --- a/functions/main +++ b/functions/main @@ -79,6 +79,12 @@ if ! [ -d "$TEMPLATE_POOL" ] ; then log_error "No template directory (${TEMPLATE_POOL}) found - exiting." exit 1 fi + +if [ -d "${EXTRA_CONFIG_DIR:-}" ] && ls ${EXTRA_CONFIG_DIR}/*.yml &>/dev/null ; then + log_debug "EXTRA_CONFIG_DIR is configured and *.yml files are present, setting EXTRA_CONFIG_FILES" + EXTRA_CONFIG_FILES=${EXTRA_CONFIG_DIR}/*.yml +fi + ## }}} ## environment variables {{{ @@ -99,6 +105,8 @@ export LOCAL_CONFIG export NGCPCTL_CONFIG export CONSTANTS_CONFIG export NETWORK_CONFIG +export EXTRA_CONFIG_DIR +export EXTRA_CONFIG_FILES ## }}} ## HA / carrier features {{{ diff --git a/helper/build_config b/helper/build_config index 8c98ba85..f426bf99 100755 --- a/helper/build_config +++ b/helper/build_config @@ -67,8 +67,8 @@ umask 0077 TT_WRAPPER="${HELPER}/tt2-wrapper" log_debug "Output file ${output_file} based on ${input_file}" -log_debug "Executing: $TT_WRAPPER ${input_file} ${host_conf:-} ${local_conf:-} $NGCPCTL_CONFIG ${NETWORK_CONFIG:-} $CONSTANTS_CONFIG > ${output_file}" -if "$TT_WRAPPER" "${input_file}" ${host_conf:-} ${local_conf:-} "$NGCPCTL_CONFIG" "${NETWORK_CONFIG:-}" "$CONSTANTS_CONFIG" > "${output_file}" 2>/dev/null ; then +log_debug "Executing: $TT_WRAPPER ${input_file} ${host_conf:-} ${local_conf:-} $NGCPCTL_CONFIG ${NETWORK_CONFIG:-} ${EXTRA_CONFIG_FILES:-} $CONSTANTS_CONFIG > ${output_file}" +if "$TT_WRAPPER" "${input_file}" ${host_conf:-} ${local_conf:-} "$NGCPCTL_CONFIG" "${NETWORK_CONFIG:-}" ${EXTRA_CONFIG_FILES:-} "$CONSTANTS_CONFIG" > "${output_file}" 2>/dev/null ; then log_info "Generating ${output_file}: OK" RC=0 else @@ -76,7 +76,7 @@ else RC=1 log_info "NOTE: Check those files for valid syntax and encoding:" - for f in "${input_file}" ${host_conf:-} ${local_conf:-} "$NGCPCTL_CONFIG" "${NETWORK_CONFIG:-}" "$CONSTANTS_CONFIG" ; do + for f in "${input_file}" ${host_conf:-} ${local_conf:-} "$NGCPCTL_CONFIG" "${NETWORK_CONFIG:-}" ${EXTRA_CONFIG_FILES:-} "$CONSTANTS_CONFIG" ; do [ -r "$f" ] && log_info "$f" done log_info "Running /usr/share/ngcp-ngcpcfg/helper/tt2-wrapper should provide more details." diff --git a/scripts/build b/scripts/build index e80d5c3f..4343de0d 100755 --- a/scripts/build +++ b/scripts/build @@ -30,7 +30,7 @@ if [ -n "${1:-}" ] ; then fi # make sure encoding is OK -for f in ${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} ${CONSTANTS_CONFIG:-} ; do +for f in ${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} ${EXTRA_CONFIG_FILES:-} ${CONSTANTS_CONFIG:-} ; do if [ -r "$f" ] && ! file "$f" | grep -qe "UTF-8" -qe "ASCII" ; then log_error "Encoding check of ${f} fails: neither ASCII nor UTF-8." log_error "Please convert ${f} to UTF-8." @@ -45,7 +45,7 @@ for f in ${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG done # check for valid YAML syntax -for f in ${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} ${CONSTANTS_CONFIG:-} ; do +for f in ${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} ${EXTRA_CONFIG_FILES:-} ${CONSTANTS_CONFIG:-} ; do if [ -r "$f" ] ; then # use YAML::Tiny for checking log_debug "Validating main YAML syntax of ${f}" @@ -78,15 +78,32 @@ else exit 0 fi + trigger_rebuild=false + + if [ -n "${EXTRA_CONFIG_FILES:-}" ] ; then + for file in $EXTRA_CONFIG_FILES ; do + if git diff-index --name-only HEAD | grep -qe "$(basename $file)" ; then + log_debug "modification in EXTRA_CONFIG_FILES file $file found" + trigger_rebuild=true + break # no reason for further checks + fi + done + fi + if git diff-index --name-only HEAD | grep \ -qe "$(basename $NGCPCTL_CONFIG)" \ -qe "$(basename $HOST_CONFIG)" \ -qe "$(basename $LOCAL_CONFIG)" \ -qe "$(basename $NETWORK_CONFIG)" \ -qe "$(basename $CONSTANTS_CONFIG)" ; then - log_info "Main configuation files has been changed, running full rebuild." - log_debug "Executing: build_config_files $*" - build_config_files "$*" + log_debug "modification in main configuration file found" + trigger_rebuild=true + fi + + if $trigger_rebuild ; then + log_info "Main configuation file(s) has been changed, running full rebuild." + log_debug "Executing: build_config_files $*" + build_config_files "$*" fi if git diff-index --name-only HEAD | grep -q templates/ || \