aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xpriv/templates/extended_bin1
-rw-r--r--test/rlx_extended_bin_SUITE.erl104
2 files changed, 73 insertions, 32 deletions
diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin
index e8404ea..ac74358 100755
--- a/priv/templates/extended_bin
+++ b/priv/templates/extended_bin
@@ -700,6 +700,7 @@ case "$1" in
EXTENSION_SCRIPT=$(relx_get_extension_script $1)
shift
relx_run_extension $EXTENSION_SCRIPT $@
+ # all extension scripts are expected to exit
else
relx_usage $1
fi
diff --git a/test/rlx_extended_bin_SUITE.erl b/test/rlx_extended_bin_SUITE.erl
index fb95bab..d2bf753 100644
--- a/test/rlx_extended_bin_SUITE.erl
+++ b/test/rlx_extended_bin_SUITE.erl
@@ -51,7 +51,9 @@
builtin_wait_for_process_start_script_hook/1,
mixed_custom_and_builtin_start_script_hooks/1,
builtin_status_script/1, custom_status_script/1,
- extension_script/1]).
+ extension_script/1,
+ extension_script_exit_code/1,
+ extension_script_fail_when_no_exit/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -85,7 +87,10 @@ all() ->
replace_os_vars_custom_location, 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,
- builtin_status_script, custom_status_script, extension_script].
+ builtin_status_script, custom_status_script,
+ extension_script,
+ extension_script_exit_code,
+ extension_script_fail_when_no_exit].
ping(Config) ->
LibDir1 = proplists:get_value(lib1, Config),
@@ -1539,36 +1544,13 @@ start_fail_when_circular_argsfiles(Config) ->
start_fail_with_vmargs(Config, VmArgs, 5).
extension_script(Config) ->
- LibDir1 = proplists:get_value(lib1, Config),
-
- rlx_test_utils:create_full_app(LibDir1, "goal_app", "0.0.1",
- [stdlib,kernel], []),
-
- OutputDir = filename:join([proplists:get_value(priv_dir, Config),
- rlx_test_utils:create_random_name("relx-output")]),
-
- ConfigFile = filename:join([LibDir1, "relx.config"]),
- rlx_test_utils:write_config(ConfigFile,
- [{release, {foo, "0.0.1"},
- [goal_app]},
- {lib_dirs, [filename:join(LibDir1, "*")]},
- {generate_start_script, true},
- {extended_start_script, true},
- {extended_start_script_extensions, [
- {bar, "extensions/bar"}
- ]},
- {overlay, [
- {copy, "./bar", "bin/extensions/bar"}]}
- ]),
-
- %% write the extension script
- ok = file:write_file(filename:join([LibDir1, "./bar"]),
- "#!/bin/bash\n"
- "echo \\{bar, $REL_NAME, \\'$NAME\\', $COOKIE\\}.\n"
- "exit 0"),
-
- {ok, _State} = relx:do(foo, undefined, [], [LibDir1], 3,
- OutputDir, ConfigFile),
+ ExtensionScript =
+ "#!/bin/bash\n"
+ "echo \\{bar, $REL_NAME, \\'$NAME\\', $COOKIE\\}.\n"
+ "exit 0",
+ OutputDir = setup_extension_script(proplists:get_value(lib1, Config),
+ proplists:get_value(priv_dir, Config),
+ ExtensionScript),
os:cmd(filename:join([OutputDir, "foo", "bin", "foo start"])),
timer:sleep(2000),
{ok, "pong"} = sh(filename:join([OutputDir, "foo", "bin", "foo ping"])),
@@ -1579,6 +1561,31 @@ extension_script(Config) ->
{ok, [Term]} = file:consult(filename:join([OutputDir, "bar.txt"])),
{ok, {bar, foo, _, foo} = Term}.
+extension_script_exit_code(Config) ->
+ ExtensionScript =
+ "#!/bin/bash\n"
+ "echo teststring\n"
+ "exit 42\n",
+ OutputDir = setup_extension_script(proplists:get_value(lib1, Config),
+ proplists:get_value(priv_dir, Config),
+ ExtensionScript),
+ %% check that the invocation exit code is the expected one
+ {error, 42, Str} = sh(filename:join([OutputDir, "foo", "bin", "foo bar"])),
+ %% check that the extension script ran
+ {ok, "teststring" = Str}.
+
+extension_script_fail_when_no_exit(Config) ->
+ ExtensionScript =
+ "#!/bin/bash\n"
+ "echo teststring\n",
+ OutputDir = setup_extension_script(proplists:get_value(lib1, Config),
+ proplists:get_value(priv_dir, Config),
+ ExtensionScript),
+ %% check that the invocation exit code is non-zero
+ {error, 1, Str} = sh(filename:join([OutputDir, "foo", "bin", "foo bar"])),
+ %% check that the extension script ran
+ {ok, "teststring" = Str}.
+
%%-------------------------------------------------------------------
%% Helper Function for start_fail_when_* tests
%%-------------------------------------------------------------------
@@ -1612,6 +1619,39 @@ start_fail_with_vmargs(Config, VmArgs, ExpectedCode) ->
%% now start/stop the release to make sure the extended script is working
{error, ExpectedCode, _} = sh(filename:join([OutputDir, "foo", "bin", "foo start"])).
+%%-------------------------------------------------------------------
+%% Helper Functions for extension_script* tests
+%%-------------------------------------------------------------------
+setup_extension_script(LibDir1, PrivDir, ExtensionScript) ->
+ rlx_test_utils:create_full_app(LibDir1, "goal_app", "0.0.1",
+ [stdlib,kernel], []),
+
+ OutputDir = filename:join([PrivDir,
+ rlx_test_utils:create_random_name("relx-output")]),
+
+ ConfigFile = filename:join([LibDir1, "relx.config"]),
+ rlx_test_utils:write_config(ConfigFile,
+ [{release, {foo, "0.0.1"},
+ [goal_app]},
+ {lib_dirs, [filename:join(LibDir1, "*")]},
+ {generate_start_script, true},
+ {extended_start_script, true},
+ {extended_start_script_extensions, [
+ {bar, "extensions/bar"}
+ ]},
+ {overlay, [
+ {copy, "./bar", "bin/extensions/bar"}]}
+ ]),
+
+ %% write the extension script
+ ok = file:write_file(filename:join([LibDir1, "./bar"]),
+ ExtensionScript),
+
+ {ok, _State} = relx:do(foo, undefined, [], [LibDir1], 3,
+ OutputDir, ConfigFile),
+
+ OutputDir.
+
%%%===================================================================
%%% Helper Functions
%%%===================================================================