aboutsummaryrefslogtreecommitdiffstats
path: root/priv/templates/extended_bin
diff options
context:
space:
mode:
authorLuis Rascao <[email protected]>2016-10-23 23:47:39 +0100
committerLuis Rascao <[email protected]>2016-10-27 18:57:39 +0100
commitf0e0d1acc7e4b645e9dac38e8323bbc1cb8fb03c (patch)
tree9c418e34ca331ca3ab63eaa723e7406ba77a5515 /priv/templates/extended_bin
parent42dcb2a4c2ca74eec5c756767d53317ad8e0c227 (diff)
downloadrelx-f0e0d1acc7e4b645e9dac38e8323bbc1cb8fb03c.tar.gz
relx-f0e0d1acc7e4b645e9dac38e8323bbc1cb8fb03c.tar.bz2
relx-f0e0d1acc7e4b645e9dac38e8323bbc1cb8fb03c.zip
Fix replace os vars functionality
The first run would correctly replace the environment variables, however it would also overwrite the original vm.args and sys.config thus preventing any further substitution in subsequent runs. Dev mode runs were also broken, all runs after the first were required to also define the RELX_REPLACE_OS_VARS variable in order not to overwrite the current vm.args with the original one, this prevented simply attaching to an already running node that was started this way. Add tests to exercise this functionality.
Diffstat (limited to 'priv/templates/extended_bin')
-rwxr-xr-xpriv/templates/extended_bin66
1 files changed, 34 insertions, 32 deletions
diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin
index 7a9f0c7..e844e46 100755
--- a/priv/templates/extended_bin
+++ b/priv/templates/extended_bin
@@ -98,28 +98,6 @@ if [ -z "$VMARGS_PATH" ]; then
fi
fi
-orig_vmargs_path="$VMARGS_PATH.orig"
-if [ $RELX_REPLACE_OS_VARS ]; then
- #Make sure we don't break dev mode by keeping the symbolic link to
- #the user's vm.args
- if [ ! -L "$orig_vmargs_path" ]; then
- #we're in copy mode, rename the vm.args file to vm.args.orig
- mv "$VMARGS_PATH" "$orig_vmargs_path"
- fi
-
- awk '{while(match($0,"[$]{[^}]*}")) {var=substr($0,RSTART+2,RLENGTH -3);gsub("[$]{"var"}",ENVIRON[var])}}1' < "$orig_vmargs_path" > "$VMARGS_PATH"
- else
- #We don't need to replace env. vars, just rename the
- #symlink vm.args.orig to vm.args, and keep it as a
- #symlink.
- if [ -L "$orig_vmargs_path" ]; then
- mv "$orig_vmargs_path" "$VMARGS_PATH"
- fi
-fi
-
-# Make sure log directory exists
-mkdir -p "$RUNNER_LOG_DIR"
-
# Use $CWD/sys.config if exists, otherwise releases/VSN/sys.config
if [ -z "$RELX_CONFIG_PATH" ]; then
if [ -f "$RELEASE_ROOT_DIR/sys.config" ]; then
@@ -129,25 +107,49 @@ if [ -z "$RELX_CONFIG_PATH" ]; then
fi
fi
+orig_vmargs_path="$VMARGS_PATH.orig"
+if [ $RELX_REPLACE_OS_VARS ]; then
+ # if there is no vm.args.orig then make a copy of the
+ # the original vm.args
+ if [ ! -f "$orig_vmargs_path" ]; then
+ mv "$VMARGS_PATH" "$orig_vmargs_path"
+ fi
+
+ # apply the environment variable substitution to vm.args.orig
+ # the result is saved to vm.args
+ awk '{while(match($0,"[$]{[^}]*}")) {var=substr($0,RSTART+2,RLENGTH -3);gsub("[$]{"var"}",ENVIRON[var])}}1' < "$orig_vmargs_path" > "$VMARGS_PATH"
+else
+ # if a vm.args.orig is present this means that
+ # env variable substitution has occurred before
+ # so use the original
+ if [ -f "$orig_vmargs_path" ]; then
+ mv "$orig_vmargs_path" "$VMARGS_PATH"
+ fi
+fi
+
orig_relx_config_path="$RELX_CONFIG_PATH.orig"
if [ $RELX_REPLACE_OS_VARS ]; then
- #Make sure we don't break dev mode by keeping the symbolic link to
- #the user's sys.config
- if [ ! -L "$orig_relx_config_path" ]; then
- #We're in copy mode, rename sys.config to sys.config.orig
+ # if there is no sys.config.orig then make a copy of the
+ # the original sys.config
+ if [ ! -f "$orig_relx_config_path" ]; then
mv "$RELX_CONFIG_PATH" "$orig_relx_config_path"
fi
+ # apply the environment variable substitution to sys.config.orig
+ # the result is saved to sys.config
awk '{while(match($0,"[$]{[^}]*}")) {var=substr($0,RSTART+2,RLENGTH -3);gsub("[$]{"var"}",ENVIRON[var])}}1' < "$orig_relx_config_path" > "$RELX_CONFIG_PATH"
- else
- #We don't need to replace env. vars, just rename the
- #symlink sys.config.orig to sys.config. Keep it as
- #a symlink.
- if [ -L "$orig_relx_config_path" ]; then
- mv "$orig_relx_config_path" "$RELX_CONFIG_PATH"
+else
+ # if a sys.config.orig is present this means that
+ # env variable substitution has occurred before
+ # so use the original
+ if [ -f "$orig_relx_config_path" ]; then
+ mv "$orig_relx_config_path" "$RELX_CONFIG_PATH"
fi
fi
+# Make sure log directory exists
+mkdir -p "$RUNNER_LOG_DIR"
+
# Extract the target node name from node.args
NAME_ARG=$(egrep '^-s?name' "$VMARGS_PATH" || true)
if [ -z "$NAME_ARG" ]; then