aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerge Aleynikov <[email protected]>2015-12-22 08:31:58 -0500
committerSerge Aleynikov <[email protected]>2015-12-22 10:04:05 -0500
commit5b97d6261dd667426c601f486cad0d6b1b5415aa (patch)
treea721734ba7b0a5fa839ea76ba0748d2261de37d7
parenta1da1e6415467c8b6ea69d279a3e7a9ed2c3b468 (diff)
downloadrelx-5b97d6261dd667426c601f486cad0d6b1b5415aa.tar.gz
relx-5b97d6261dd667426c601f486cad0d6b1b5415aa.tar.bz2
relx-5b97d6261dd667426c601f486cad0d6b1b5415aa.zip
Enhance the variable replacement
Add ability to also run shell commands contained in the sys.config. E.g.: # In this example the node name defaults to name of the release # and can be overriden at run-time, appended with current year $ head -1 vm.args -sname ${NODE_NAME:-$REL_NAME}$(date +%Y) # If the $NAME is 'abc2015', and hostname is 'MyHost', below the 'node' # parameter gets set to 'Abc2015@myhost' $ grep node sys.config {node, $(echo ${NAME^})@${HOSTNAME,,}}
-rwxr-xr-xpriv/templates/extended_bin26
1 files changed, 14 insertions, 12 deletions
diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin
index 4a29d44..b6eb297 100755
--- a/priv/templates/extended_bin
+++ b/priv/templates/extended_bin
@@ -6,7 +6,7 @@ SCRIPT=$(readlink -f $0 || true)
[ -z $SCRIPT ] && SCRIPT=$0
SCRIPT_DIR="${SCRIPT%/*}"
RELEASE_ROOT_DIR="${SCRIPT_DIR%/*}"
-REL_NAME="{{ rel_name }}"
+export REL_NAME="{{ rel_name }}"
REL_VSN="{{ rel_vsn }}"
ERTS_VSN="{{ erts_vsn }}"
CODE_LOADING_MODE="${CODE_LOADING_MODE:-embedded}"
@@ -90,7 +90,7 @@ relx_start_command() {
# Replace environment variables
relx_replace_os_vars() {
awk '{
- while(match($0,/\$\{[^{}]+?\}/)) {
+ while(match($0,/\$[{(][^{}()]+?[})]/)) {
s=RSTART; n=RLENGTH;
v0=substr($0,0,s-1); v1=substr($0,s,n); v2=substr($0,n+s,length($0)-s-n+1)
"echo "v1|getline v; $0=v0 v v2
@@ -126,15 +126,10 @@ if [ -z "$RELX_CONFIG_PATH" ]; then
fi
fi
-if [ $RELX_REPLACE_OS_VARS ]; then
- IN=$RELX_CONFIG_PATH
- OUT=${IN##*/}
- RELX_CONFIG_PATH=${IN%.*}.2.${OUT##*.}
- relx_replace_os_vars ${IN} ${RELX_CONFIG_PATH}
-fi
-
# Extract the target node name from node.args
-NAME_ARG=( $(eval echo $(egrep '^-s?name' "$VMARGS_PATH" || true)) )
+# Do this BEFORE possible variable replacement, so that $NAME is available
+# in the replacement phase if needed
+NAME_ARG=( $(egrep '^-s?name' "$VMARGS_PATH" || true) )
if [ -z "${NAME_ARG[*]}" ]; then
echo "vm.args needs to have either -name or -sname parameter."
exit 1
@@ -142,12 +137,19 @@ fi
# Extract the name type and name from the NAME_ARG for REMSH
NAME_TYPE="${NAME_ARG[0]}"
-NAME="${NAME_ARG[1]}"
+export NAME="${NAME_ARG[*]:1}"
+
+if [ $RELX_REPLACE_OS_VARS ]; then
+ IN=$RELX_CONFIG_PATH
+ OUT=${IN##*/}
+ RELX_CONFIG_PATH=${IN%.*}.2.${OUT##*.}
+ relx_replace_os_vars ${IN} ${RELX_CONFIG_PATH}
+fi
PIPE_DIR="${PIPE_DIR:-/tmp/erl_pipes/$NAME/}"
# Extract the target cookie
-COOKIE_ARG=( $(eval echo $(grep '^-setcookie' "$VMARGS_PATH" || true)) )
+COOKIE_ARG=( $(grep '^-setcookie' "$VMARGS_PATH" || true) )
if [ -z "${COOKIE_ARG[*]}" ]; then
echo "vm.args needs to have a -setcookie parameter."
exit 1