Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obtain release node name from Erlang VM instead of OS #553

Merged
merged 1 commit into from
Dec 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions priv/templates/extended_bin
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ relx_run_hooks() {
done
}

find_erts_dir
export ROOTDIR="$RELEASE_ROOT_DIR"
export BINDIR="$ERTS_DIR/bin"
export EMU="beam"
export PROGNAME="erl"
export LD_LIBRARY_PATH="$ERTS_DIR/lib:$LD_LIBRARY_PATH"
ERTS_LIB_DIR="$(dirname "$ERTS_DIR")/lib"

VMARGS_PATH=$(add_path vm.args $VMARGS_PATH)
# Extract the target node name from node.args
NAME_ARG=$(egrep '^-s?name' "$VMARGS_PATH" || true)
Expand All @@ -280,7 +288,7 @@ NAME="$(echo "$NAME_ARG" | awk '{print $2}')"
# So here we check for @ and add @hostname if missing
case "${NAME}" in
*@*) ;; # Nothing to do
*) NAME=${NAME}@$(hostname -s);; # Add @hostname
*) NAME=${NAME}@$(relx_get_nodename);; # Add @hostname
esac

# Export the variable so that it's available in the 'eval' calls
Expand Down Expand Up @@ -309,14 +317,6 @@ else
COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')"
fi

find_erts_dir
export ROOTDIR="$RELEASE_ROOT_DIR"
export BINDIR="$ERTS_DIR/bin"
export EMU="beam"
export PROGNAME="erl"
export LD_LIBRARY_PATH="$ERTS_DIR/lib:$LD_LIBRARY_PATH"
ERTS_LIB_DIR="$(dirname "$ERTS_DIR")/lib"

cd "$ROOTDIR"

# Check the first argument for instructions
Expand Down
45 changes: 42 additions & 3 deletions test/rlx_extended_bin_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
init_per_testcase/2,
all/0,
ping/1,
shortname_ping/1,
attach/1,
pid/1,
restart/1,
Expand Down Expand Up @@ -62,9 +63,8 @@ init_per_testcase(_, Config) ->
{state, State1} | Config].

all() ->
[ping, attach, pid, restart, reboot, escript,
remote_console, replace_os_vars,
replace_os_vars_dev_mode, replace_os_vars_twice,
[ping, shortname_ping, attach, pid, restart, reboot, escript,
remote_console, replace_os_vars, replace_os_vars_dev_mode, replace_os_vars_twice,
custom_start_script_hooks, builtin_wait_for_vm_start_script_hook,
builtin_pid_start_script_hook, builtin_wait_for_process_start_script_hook,
mixed_custom_and_builtin_start_script_hooks].
Expand Down Expand Up @@ -102,6 +102,45 @@ ping(Config) ->
%% a ping should fail after stopping a node
{error, 1, _} = sh(filename:join([OutputDir, "foo", "bin", "foo ping"])).

shortname_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"]),
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, "-sname foo\n\n"
"-setcookie cookie\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"])).

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

Expand Down