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
sync-replication
Michael Prokop 12 years ago
parent 3436c08361
commit c3e1cb68d4

@ -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 is *not* supposed to be modified by the user (without having a very good
reason). 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. * _/etc/ngcp-config/ngcpcfg.d/_: configuration directory for ngcpcfg itself.
Files with suffix '.cfg' inside this directory are sourced after Files with suffix '.cfg' inside this directory are sourced after
/etc/ngcp-config/ngcpcfg.cfg has been read. Files inside this directory are /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] [IMPORTANT]
Configuration file priority: constants.yml takes precedence over 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 High Availability setup specific configuration files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@ -9,6 +9,7 @@ HOST_CONFIG="${NGCPCTL_MAIN}/config.$(hostname).yml"
LOCAL_CONFIG="${NGCPCTL_MAIN}/config.local.yml" LOCAL_CONFIG="${NGCPCTL_MAIN}/config.local.yml"
CONSTANTS_CONFIG="${NGCPCTL_MAIN}/constants.yml" CONSTANTS_CONFIG="${NGCPCTL_MAIN}/constants.yml"
NETWORK_CONFIG="${NGCPCTL_MAIN}/network.yml" NETWORK_CONFIG="${NGCPCTL_MAIN}/network.yml"
EXTRA_CONFIG_DIR="${NGCPCTL_MAIN}/config.d/"
# configuration files that should be managed # configuration files that should be managed
CONFIG_POOL='/etc' CONFIG_POOL='/etc'

@ -79,6 +79,12 @@ if ! [ -d "$TEMPLATE_POOL" ] ; then
log_error "No template directory (${TEMPLATE_POOL}) found - exiting." log_error "No template directory (${TEMPLATE_POOL}) found - exiting."
exit 1 exit 1
fi 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 {{{ ## environment variables {{{
@ -99,6 +105,8 @@ export LOCAL_CONFIG
export NGCPCTL_CONFIG export NGCPCTL_CONFIG
export CONSTANTS_CONFIG export CONSTANTS_CONFIG
export NETWORK_CONFIG export NETWORK_CONFIG
export EXTRA_CONFIG_DIR
export EXTRA_CONFIG_FILES
## }}} ## }}}
## HA / carrier features {{{ ## HA / carrier features {{{

@ -67,8 +67,8 @@ umask 0077
TT_WRAPPER="${HELPER}/tt2-wrapper" TT_WRAPPER="${HELPER}/tt2-wrapper"
log_debug "Output file ${output_file} based on ${input_file}" 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}" 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:-}" "$CONSTANTS_CONFIG" > "${output_file}" 2>/dev/null ; then 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" log_info "Generating ${output_file}: OK"
RC=0 RC=0
else else
@ -76,7 +76,7 @@ else
RC=1 RC=1
log_info "NOTE: Check those files for valid syntax and encoding:" 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" [ -r "$f" ] && log_info "$f"
done done
log_info "Running /usr/share/ngcp-ngcpcfg/helper/tt2-wrapper <file> should provide more details." log_info "Running /usr/share/ngcp-ngcpcfg/helper/tt2-wrapper <file> should provide more details."

@ -30,7 +30,7 @@ if [ -n "${1:-}" ] ; then
fi fi
# make sure encoding is OK # 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 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 "Encoding check of ${f} fails: neither ASCII nor UTF-8."
log_error "Please convert ${f} to 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 done
# check for valid YAML syntax # 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 if [ -r "$f" ] ; then
# use YAML::Tiny for checking # use YAML::Tiny for checking
log_debug "Validating main YAML syntax of ${f}" log_debug "Validating main YAML syntax of ${f}"
@ -78,13 +78,30 @@ else
exit 0 exit 0
fi 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 \ if git diff-index --name-only HEAD | grep \
-qe "$(basename $NGCPCTL_CONFIG)" \ -qe "$(basename $NGCPCTL_CONFIG)" \
-qe "$(basename $HOST_CONFIG)" \ -qe "$(basename $HOST_CONFIG)" \
-qe "$(basename $LOCAL_CONFIG)" \ -qe "$(basename $LOCAL_CONFIG)" \
-qe "$(basename $NETWORK_CONFIG)" \ -qe "$(basename $NETWORK_CONFIG)" \
-qe "$(basename $CONSTANTS_CONFIG)" ; then -qe "$(basename $CONSTANTS_CONFIG)" ; then
log_info "Main configuation files has been changed, running full rebuild." 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 $*" log_debug "Executing: build_config_files $*"
build_config_files "$*" build_config_files "$*"
fi fi

Loading…
Cancel
Save