aboutsummaryrefslogtreecommitdiffstats
path: root/test/rlx_extended_bin_SUITE.erl
diff options
context:
space:
mode:
authorLuis Rascao <[email protected]>2017-05-14 02:15:05 +0100
committerLuis Rascao <[email protected]>2017-05-15 17:27:56 +0100
commit82f6c94a4d8ef1cf2be0becc5816d0646e5a50cc (patch)
tree0859e7e9a796f69dd26ebc015c8c7b0ca9d5f199 /test/rlx_extended_bin_SUITE.erl
parentc1fa56db1ec4cc4aa6975f4efee0c189452a251d (diff)
downloadrelx-82f6c94a4d8ef1cf2be0becc5816d0646e5a50cc.tar.gz
relx-82f6c94a4d8ef1cf2be0becc5816d0646e5a50cc.tar.bz2
relx-82f6c94a4d8ef1cf2be0becc5816d0646e5a50cc.zip
Add custom status hook to extended script
Provide a status command to start script which, by default, runs a builtin hook that simply prints which applications are running in the node. This hook can then be customized to print whatever the user wants by adding {status, [{custom, "path/to/hook"}]} to already existing extended_start_script_hooks.
Diffstat (limited to 'test/rlx_extended_bin_SUITE.erl')
-rw-r--r--test/rlx_extended_bin_SUITE.erl79
1 files changed, 77 insertions, 2 deletions
diff --git a/test/rlx_extended_bin_SUITE.erl b/test/rlx_extended_bin_SUITE.erl
index c3f534a..c049209 100644
--- a/test/rlx_extended_bin_SUITE.erl
+++ b/test/rlx_extended_bin_SUITE.erl
@@ -41,7 +41,8 @@
builtin_wait_for_vm_start_script_hook/1,
builtin_pid_start_script_hook/1,
builtin_wait_for_process_start_script_hook/1,
- mixed_custom_and_builtin_start_script_hooks/1]).
+ mixed_custom_and_builtin_start_script_hooks/1,
+ builtin_status_script/1, custom_status_script/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -70,7 +71,8 @@ all() ->
remote_console, replace_os_vars, replace_os_vars_multi_node, replace_os_vars_included_config,
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_wait_for_process_start_script_hook, mixed_custom_and_builtin_start_script_hooks,
+ builtin_status_script, custom_status_script].
ping(Config) ->
LibDir1 = proplists:get_value(lib1, Config),
@@ -1318,6 +1320,79 @@ mixed_custom_and_builtin_start_script_hooks(Config) ->
{pre_stop, foo, _, foo},
{post_stop, foo, _, foo}]} = file:consult(filename:join([OutputDir, "foo", "test"])).
+builtin_status_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}
+ ]),
+
+ {ok, _State} = relx:do(foo, undefined, [], [LibDir1], 3,
+ OutputDir, ConfigFile),
+ os:cmd(filename:join([OutputDir, "foo", "bin", "foo start"])),
+ timer:sleep(2000),
+ {ok, "pong"} = sh(filename:join([OutputDir, "foo", "bin", "foo ping"])),
+ %% write the status to a file
+ {ok, StatusStr} = sh(filename:join([OutputDir, "foo", "bin", "foo status"])),
+ ec_file:write(filename:join([OutputDir, "status.txt"]),
+ StatusStr ++ ".\n"),
+ os:cmd(filename:join([OutputDir, "foo", "bin", "foo stop"])),
+ {ok, [Status]} = file:consult(filename:join([OutputDir, "status.txt"])),
+ Apps = lists:map(fun({App, _, _}) -> App end, Status),
+ {ok, [goal_app, kernel, stdlib] = lists:sort(Apps)}.
+
+custom_status_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_hooks, [
+ {status, [
+ {custom, "hooks/status"}
+ ]}
+ ]},
+ {overlay, [
+ {copy, "./status", "bin/hooks/status"}]}
+ ]),
+
+ %% write the hook status script
+ ok = file:write_file(filename:join([LibDir1, "./status"]),
+ "#!/bin/bash\n# $*\necho \\{status, $REL_NAME, \\'$NAME\\', $COOKIE\\}."),
+
+ {ok, _State} = relx:do(foo, undefined, [], [LibDir1], 3,
+ OutputDir, ConfigFile),
+ os:cmd(filename:join([OutputDir, "foo", "bin", "foo start"])),
+ timer:sleep(2000),
+ {ok, "pong"} = sh(filename:join([OutputDir, "foo", "bin", "foo ping"])),
+ %% write the status to a file
+ {ok, StatusStr} = sh(filename:join([OutputDir, "foo", "bin", "foo status"])),
+ ec_file:write(filename:join([OutputDir, "status.txt"]), StatusStr),
+ os:cmd(filename:join([OutputDir, "foo", "bin", "foo stop"])),
+ {ok, [Status]} = file:consult(filename:join([OutputDir, "status.txt"])),
+ {ok, {status, foo, _, foo} = Status}.
+
%%%===================================================================
%%% Helper Functions
%%%===================================================================