diff --git a/docs/ngcpcfg.txt b/docs/ngcpcfg.txt index 0e6146ab..5f72e12e 100644 --- a/docs/ngcpcfg.txt +++ b/docs/ngcpcfg.txt @@ -99,34 +99,64 @@ hosts changes should be pushed to. Supported template files ~~~~~~~~~~~~~~~~~~~~~~~~ -Example for generating a configuration file named_/etc/foobar/baz_: +Example for generating a configuration file named_/etc/foobar/baz_ (from lower +precedence to higher precedence): * _/etc/ngcp-config/templates/etc/foobar/baz.tt2_: main and default template file, used by template-handler for generating /etc/foobar/baz. Configuration file is usually provided by a Debian package. -* _/etc/ngcp-config/templates/etc/foobar/baz.customtt.tt2_: system specific -template file, but configuration usually isn't provided by a Debian package and -can be modified independent from any Debian package mechanism. - * _/etc/ngcp-config/templates/etc/foobar/baz.tt2.$HA_NODE_: node specific template file. $HA_NODE is determined using the content of /etc/ngcp_ha_node (usually being _sp1_ for the first node and _sp2_ for the second node on the Sipwise Next Generation Platform). Wheras _*customtt.tt2_ files are used on all nodes in a High Availability setup the _*.tt2.$HA_NODE*_ file is specific for the single node only. A common usage case is master vs. slave configuration of a -service. Configuration file is usually provided by a Debian package. Note: -Feature is available in the High Availability setup only. +service. Configuration file is usually provided by a Debian package. +Note: Feature is available in the High Availability setup only. + +* _/etc/ngcp-config/templates/etc/foobar/baz.tt2.$PAIRNAME_: pair specific +template file. Given a PRO pair in a CARRIER environment where two nodes are +named _web01a_ and _web01b_ then $PAIRNAME corresponds to _web01_. This is +useful if there are multiple pairs available but only a specific pair of them +should include some specific configuration. +Note: Feature is available in the High Availability setup only. + +* _/etc/ngcp-config/templates/etc/foobar/baz.tt2.$HOSTNAME_: hostname specific +template file. While $HA_NODE is usually bound to _sp1_ for the first node and +_sp2_ via /etc/ngcp_ha_node it's possible to use host specific template file by +referring to its hostname ($HOSTNAME is determined via (hostname(1)). +Note: Feature is available in the High Availability setup only. + +* _/etc/ngcp-config/templates/etc/foobar/baz.customtt.tt2_: system specific +template file, but configuration usually isn't provided by a Debian package and +can be modified independent from any Debian package mechanism. * _/etc/ngcp-config/templates/etc/foobar/baz.customtt.tt2.$HA_NODE_: node specific template file. Regarding $HA_NODE the same as for _baz.tt2.$HA_NODE_ applies (see previous bullet), but the configuration file usually isn't provided by a Debian package but can be modified independent from any Debian package -mechanism. Note: Feature is available in the High Availability setup only. +mechanism. +Note: Feature is available in the High Availability setup only. + +* _/etc/ngcp-config/templates/etc/foobar/baz.customtt.tt2.$PAIRNAME_: +configuration file similar to +_/etc/ngcp-config/templates/etc/foobar/baz.tt2.$PAIRNAME_ but it's guaranteed +that the file won't be part of any Debian package mechanism. Note: Feature is +available in the High Availability setup only. + +* _/etc/ngcp-config/templates/etc/foobar/baz.customtt.tt2.$HOSTNAME_: +configuration file similar to +_/etc/ngcp-config/templates/etc/foobar/baz.tt2.$HOSTNAME_ but it's guaranteed +that the file won't be part of any Debian package mechanism. Note: Feature is +available in the High Availability setup only. +Note: Feature is available in the High Availability setup only. [IMPORTANT] -Configuration file priority: *.customtt.tt2.$HA_NODE takes precedence over -*.customtt.tt2, over *.tt2.$HA_NODE, over *.tt2. +Configuration file priority: *.customtt.tt2.$HOSTNAME takes precedence over +*.customtt.tt2.$PAIRNAME, over .customtt.tt2.$HA_NODE, over *.customtt.tt2, over +*.tt2.$HOSTNAME, over *.tt2.$PAIRNAME, over *.tt2.$HA_NODE, over *.tt2. + Support action related files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/functions/main b/functions/main index bab04dff..491593b3 100644 --- a/functions/main +++ b/functions/main @@ -203,6 +203,7 @@ fi if [ -r /usr/share/ngcp-ngcpcfg/functions/carrier_features ] ; then . /usr/share/ngcp-ngcpcfg/functions/carrier_features + set_host_and_pair_files # set $HOST_FILE + $PAIR_FILE for usage in generate_template_list fi ## }}} @@ -216,7 +217,7 @@ generate_template_list() { for dir in ${CONFIG_POOL} ; do [ -n "${dir}" ] || ( echo "${dir} doesn't exist" >&2 ; continue ) # iterate over all files - for file in $(find "$TEMPLATE_POOL_BASE/${dir}" -name \*.tt2 -o -name \*.tt2"${HA_FILE:-}") ; do + for file in $(find "$TEMPLATE_POOL_BASE/${dir}" -name \*.tt2 -o -name \*.tt2"${HA_FILE:-}" -o -name \*.tt2"${HOST_FILE:-}" -o -name \*.tt2"${PAIR_FILE:-}") ; do # *NO* arguments provided via cmdline if [ -z "${1:-}" ] ; then echo "$file" >> "${filelist_prepared}" @@ -232,18 +233,42 @@ generate_template_list() { done # remove all filenames where a preferred filename exists - # foo.customtt.tt2.spX > foo.customtt.tt2 > foo.tt2.spX > foo.tt2 + # foo.customtt.tt2.hostname > foo.customtt.tt2.pairname > foo.customtt.tt2.spX > foo.customtt.tt2 > foo.tt2.hostname > foo.tt2.pairname > foo.tt2.spX > foo.tt2 for line in $(cat ${filelist_prepared}); do - # reduce filenames from "foo.*" to "foo" + normalized_filename="$line" + if [ -n "${HA_FILE:-}" ] ; then - normalized_filename="${line%${HA_FILE}}" - else - normalized_filename="${line}" + normalized_filename="${normalized_filename%${HA_FILE}}" + fi + + if [ -n "${HOST_FILE:-}" ] ; then + normalized_filename="${normalized_filename%${HOST_FILE}}" fi + + if [ -n "${PAIR_FILE:-}" ] ; then + normalized_filename="${normalized_filename%${PAIR_FILE}}" + fi + normalized_filename="${normalized_filename%.customtt.tt2}" normalized_filename="${normalized_filename%.tt2}" + # foo.custom.tt2.hostname + if [ -n "${HOST_FILE:-}" ] ; then + if grep -q -- "^${normalized_filename}.customtt.tt2${HOST_FILE}$" "${filelist_prepared}" ; then + echo "${normalized_filename}.customtt.tt2${HOST_FILE}" >> "${filelist_final}" + continue + fi + fi + + # foo.custom.tt2.pairname + if [ -n "${PAIR_FILE:-}" ] ; then + if grep -q -- "^${normalized_filename}.customtt.tt2${PAIR_FILE}$" "${filelist_prepared}" ; then + echo "${normalized_filename}.customtt.tt2${PAIR_FILE}" >> "${filelist_final}" + continue + fi + fi + # foo.customtt.tt2.sp{1,2} if [ -n "${HA_FILE:-}" ] ; then if grep -q -- "^${normalized_filename}.customtt.tt2${HA_FILE:-}" "${filelist_prepared}" ; then @@ -258,6 +283,22 @@ generate_template_list() { continue fi + # foo.tt2.hostname + if [ -n "${HOST_FILE:-}" ] ; then + if grep -q -- "^${normalized_filename}.tt2${HOST_FILE}" "${filelist_prepared}" ; then + echo "${normalized_filename}.tt2${HOST_FILE}" >> "${filelist_final}" + continue + fi + fi + + # foo.tt2.pairname + if [ -n "${HOST_FILE:-}" ] ; then + if grep -q -- "^${normalized_filename}.tt2${PAIR_FILE}" "${filelist_prepared}" ; then + echo "${normalized_filename}.tt2${PAIR_FILE}" >> "${filelist_final}" + continue + fi + fi + # foo.tt2.sp{1,2} if [ -n "${HA_FILE:-}" ] ; then if grep -q -- "^${normalized_filename}.tt2${HA_FILE}" "${filelist_prepared}" ; then @@ -266,7 +307,7 @@ generate_template_list() { fi fi - # file should be used, so list it + # another file not matching any previous checks echo "$line" >> "${filelist_final}" done diff --git a/helper/build_config b/helper/build_config index a7de5a94..6cf79e58 100755 --- a/helper/build_config +++ b/helper/build_config @@ -23,10 +23,12 @@ HELPER="${HELPER:-/usr/share/ngcp-ngcpcfg/helper/}" input_file="$1" # like /etc/ngcp-config/templates/etc/mysql/my.cnf.tt2 # calculate output file {{{ - x=${input_file##${NGCPCTL_MAIN}/templates/} # drop leading /etc/ngcp-config - y=${x%%.tt2} # drop trailing suffix '.tt2' - [ -n "${HA_FILE:-}" ] && y=${y%%.tt2${HA_FILE}} # drop trailing suffix '.tt2.sp{1,2}' - y=${y%%.customtt} # drop trailing suffix '.customtt' + x=${input_file##${NGCPCTL_MAIN}/templates/} # drop leading /etc/ngcp-config + y=${x%%.tt2} # drop trailing suffix '.tt2' + [ -n "${HA_FILE:-}" ] && y=${y%%.tt2${HA_FILE}} # drop trailing suffix '.tt2.sp{1,2}' + [ -n "${PAIR_FILE:-}" ] && y=${y%%.tt2${PAIR_FILE}} # drop trailing suffix '.tt2.pairname' + [ -n "${HOST_FILE:-}" ] && y=${y%%.tt2${HOST_FILE}} # drop trailing suffix '.tt2.hostname' + y=${y%%.customtt} # drop trailing suffix '.customtt' # }}} export output_file="${y}" # like /etc/mysql/my.cnf, export variable # for usage within {pre,post}build scripts