diff options
author | Luis Rascão <[email protected]> | 2017-10-19 05:23:47 +0100 |
---|---|---|
committer | Tristan Sloughter <[email protected]> | 2017-10-18 21:23:47 -0700 |
commit | 9855022433c9e3e08850c13b925b94f3b87df6c3 (patch) | |
tree | c51a6e321b7ba730d04cca06139b71fb9625bdd8 /src/rlx_prv_assembler.erl | |
parent | 5050dd81853923e904080de1da56e049f24459e3 (diff) | |
download | relx-9855022433c9e3e08850c13b925b94f3b87df6c3.tar.gz relx-9855022433c9e3e08850c13b925b94f3b87df6c3.tar.bz2 relx-9855022433c9e3e08850c13b925b94f3b87df6c3.zip |
Start script extensions (#613)
* Extended start script command extensions
Provide a mechanism that allows for the application
to extend the list of commands available to be invoked
from the start script. An application may be able to
define a 'foo' extension that is associated with a 'foo_script'
written and maintained by the applicationr, (this association is
kept in rebar.config), upon invocation of bin/<release_name> foo
the 'foo_script' will then be invoked.
* Add test coverage for extension script
* Ensure extended script usage argument
Diffstat (limited to 'src/rlx_prv_assembler.erl')
-rw-r--r-- | src/rlx_prv_assembler.erl | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/rlx_prv_assembler.erl b/src/rlx_prv_assembler.erl index 2088de6..a6bf5f8 100644 --- a/src/rlx_prv_assembler.erl +++ b/src/rlx_prv_assembler.erl @@ -401,9 +401,12 @@ write_bin_file(State, Release, OutputDir, RelDir) -> extended_start_script_hooks, []), State), + Extensions = rlx_state:get(State, + extended_start_script_extensions, + []), extended_bin_file_contents(OsFamily, RelName, RelVsn, rlx_release:erts(Release), ErlOpts, - Hooks) + Hooks, Extensions) end, %% We generate the start script by default, unless the user %% tells us not too @@ -787,7 +790,7 @@ bin_file_contents(OsFamily, RelName, RelVsn, ErtsVsn, ErlOpts) -> render(Template, [{rel_name, RelName}, {rel_vsn, RelVsn}, {erts_vsn, ErtsVsn}, {erl_opts, ErlOpts}]). -extended_bin_file_contents(OsFamily, RelName, RelVsn, ErtsVsn, ErlOpts, Hooks) -> +extended_bin_file_contents(OsFamily, RelName, RelVsn, ErtsVsn, ErlOpts, Hooks, Extensions) -> Template = case OsFamily of unix -> extended_bin; win32 -> extended_bin_windows @@ -802,6 +805,21 @@ extended_bin_file_contents(OsFamily, RelName, RelVsn, ErtsVsn, ErlOpts, Hooks) - PostInstallUpgradeHooks = string:join(proplists:get_value(post_install_upgrade, Hooks, []), " "), StatusHook = string:join(proplists:get_value(status, Hooks, []), " "), + {ExtensionsList1, ExtensionDeclarations1} = + lists:foldl(fun({Name, Script}, + {ExtensionsList0, ExtensionDeclarations0}) -> + ExtensionDeclaration = atom_to_list(Name) ++ + "_extension=\"" ++ + Script ++ "\"", + {ExtensionsList0 ++ [atom_to_list(Name)], + ExtensionDeclarations0 ++ [ExtensionDeclaration]} + end, {[], []}, Extensions), + % pipe separated string of extensions, to show on the start script usage + % (eg. foo|bar) + ExtensionsList = string:join(ExtensionsList1 ++ ["undefined"], "|"), + % command separated string of extension script declarations + % (eg. foo_extension="path/to/foo_script") + ExtensionDeclarations = string:join(ExtensionDeclarations1, ";"), render(Template, [{rel_name, RelName}, {rel_vsn, RelVsn}, {erts_vsn, ErtsVsn}, {erl_opts, ErlOpts}, {pre_start_hooks, PreStartHooks}, @@ -810,7 +828,9 @@ extended_bin_file_contents(OsFamily, RelName, RelVsn, ErtsVsn, ErlOpts, Hooks) - {post_stop_hooks, PostStopHooks}, {pre_install_upgrade_hooks, PreInstallUpgradeHooks}, {post_install_upgrade_hooks, PostInstallUpgradeHooks}, - {status_hook, StatusHook}]). + {status_hook, StatusHook}, + {extensions, ExtensionsList}, + {extension_declarations, ExtensionDeclarations}]). erl_ini(OutputDir, ErtsVsn) -> ErtsDirName = string:concat("erts-", ErtsVsn), |