Skip to content

Commit

Permalink
Merge pull request #640 from juise/master
Browse files Browse the repository at this point in the history
Add extra args from vm.args into escripts and erl
  • Loading branch information
lrascao authored Feb 15, 2018
2 parents af3ae8a + 310b704 commit 86d415f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
19 changes: 18 additions & 1 deletion priv/templates/extended_bin
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ relx_rem_sh() {
# Setup remote shell command to control node
exec "$BINDIR/erl" "$NAME_TYPE" "$id" -remsh "$NAME" -boot start_clean \
-boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
-setcookie "$COOKIE" -hidden -kernel net_ticktime $TICKTIME
-setcookie "$COOKIE" -hidden -kernel net_ticktime $TICKTIME $VM_ARGS
}

# Generate a random id
Expand All @@ -179,6 +179,8 @@ relx_gen_id() {
relx_nodetool() {
command="$1"; shift

escript_emulator_args $ROOTDIR/bin/nodetool

"$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \
-setcookie "$COOKIE" "$command" $@
}
Expand Down Expand Up @@ -228,6 +230,19 @@ replace_os_vars() {
}1' < "$1" > "$2"
}

escript_emulator_args() {
if [ -n "${VM_ARGS}" ]; then
if grep -q '%%!' $1; then
cmd=$(echo sed -i"' '" "'s|%%!.*|%%! ${VM_ARGS}|'" $1)
eval "$cmd"
else
cmd=$(echo sed -i"' '" "'/#!.*/ a \\
%%! ${VM_ARGS}\n'" $1)
eval "$cmd"
fi
fi
}

add_path() {
# Use $CWD/$1 if exists, otherwise releases/VSN/$1
IN_FILE_PATH=$2
Expand Down Expand Up @@ -442,6 +457,8 @@ else
COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')"
fi

VM_ARGS="$(grep -v -E '^#|^-name|^-sname|^-setcookie|^-args_file' "$VMARGS_PATH" | xargs | sed -e 's/ / /g')"

cd "$ROOTDIR"

# Check the first argument for instructions
Expand Down
44 changes: 42 additions & 2 deletions test/rlx_extended_bin_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
all/0,
start_sname_in_other_argsfile/1,
start_preserves_arguments/1,
start_nodetool_with_data_from_argsfile/1,
start_fail_when_no_name/1,
start_fail_when_multiple_names/1,
start_fail_when_missing_argsfile/1,
Expand Down Expand Up @@ -78,7 +79,7 @@ init_per_testcase(_, Config) ->
{state, State1} | Config].

all() ->
[start_sname_in_other_argsfile, start_preserves_arguments,
[start_sname_in_other_argsfile, start_preserves_arguments, start_nodetool_with_data_from_argsfile,
start_fail_when_no_name, start_fail_when_multiple_names,
start_fail_when_missing_argsfile, start_fail_when_nonreadable_argsfile,
start_fail_when_relative_argsfile, start_fail_when_circular_argsfiles,
Expand All @@ -94,7 +95,6 @@ all() ->

ping(Config) ->
LibDir1 = proplists:get_value(lib1, Config),

rlx_test_utils:create_app(LibDir1, "goal_app", "0.0.1", [stdlib,kernel], []),

ConfigFile = filename:join([LibDir1, "relx.config"]),
Expand Down Expand Up @@ -1490,6 +1490,46 @@ start_preserves_arguments(Config) ->
%% a ping should fail after stopping a node
{error, 1, _} = sh(filename:join([OutputDir, "foo", "bin", "foo ping"])).

start_nodetool_with_data_from_argsfile(Config) ->
LibDir1 = proplists:get_value(lib1, Config),

rlx_test_utils:create_app(LibDir1, "goal_app", "0.0.1", [stdlib,kernel], []),

ConfigFile = filename:join([LibDir1, "relx.config"]),
VmArgs = filename:join([LibDir1, "vm.args"]),

rlx_test_utils:write_config(ConfigFile,
[{release, {foo, "0.0.1"},
[goal_app]},
{lib_dirs, [filename:join(LibDir1, "*")]},
{vm_args, VmArgs},
{generate_start_script, true},
{extended_start_script, true}
]),

ec_file:write(VmArgs, "-setcookie cookie\n"
"-sname foo\n\n"
"-proto_dist inet_tcp\n\n"),

OutputDir = filename:join([proplists:get_value(priv_dir, Config),
rlx_test_utils:create_random_name("relx-output")]),

{ok, _State} = relx:do([{relname, foo},
{relvsn, "0.0.1"},
{goals, []},
{lib_dirs, [LibDir1]},
{log_level, 3},
{output_dir, OutputDir},
{config, ConfigFile}], ["release"]),

%% now start/stop the release to make sure the extended script is working
{ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo start"])),
timer:sleep(2000),
{ok, "pong"} = sh(filename:join([OutputDir, "foo", "bin", "foo ping"])),
{ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo stop"])),
%% a ping should fail after stopping a node
{error, 1, _} = sh(filename:join([OutputDir, "foo", "bin", "foo ping"])).

start_fail_when_no_name(Config) ->
LibDir1 = proplists:get_value(lib1, Config),
VmArgs = filename:join([LibDir1, "vm.args"]),
Expand Down

0 comments on commit 86d415f

Please sign in to comment.