Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Slim release support #52

Merged
merged 4 commits into from

6 participants

@shino

PR for #7 .

By adding {excl_lib, otp_root} to reltool.config,
generate a slim release which does not include erts and otp libraries.
Also the runner script uses appropriate options for slim release.

Example:

$ mkdir slim_sample
$ cd slim_sample
$ cp /path/to/rebar/rebar .
$ ./rebar create-app appid=slim_sample
$ ./rebar compile

$ rm -rf rel
$ mkdir rel
$ cd rel
$ ../rebar create-node nodeid=slim_sample
$ cp reltool.config reltool.config.original

$ vi reltool.config  # edit
$ diff -u reltool.config.original reltool.config
--- reltool.config.original     2013-01-13 22:23:31.597614577 +0900
+++ reltool.config      2013-01-13 22:23:31.601613550 +0900
@@ -1,5 +1,6 @@
 {sys, [
        {lib_dirs, []},
+       {excl_lib, otp_root},
        {erts, [{mod_cond, derived}, {app_file, strip}]},
        {app_file, strip},
        {rel, "slim_sample", "1",
@@ -22,14 +23,14 @@
        {excl_sys_filters, ["^bin/.*", "^erts.*/bin/(dialyzer|typer)",
                            "^erts.*/(doc|info|include|lib|man|src)"]},
        {excl_app_filters, ["\.gitignore"]},
-       {app, slim_sample, [{mod_cond, app}, {incl_cond, include}]}
+       {app, hipe, [{incl_cond, exclude}]},
+       {app, slim_sample, [{mod_cond, app}, {incl_cond, include}, {lib_dir, ".."}]}
       ]}.

 {target_dir, "slim_sample"}.

 {overlay, [
            {mkdir, "log/sasl"},
-           {copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"},
            {copy, "files/nodetool", "releases/\{\{rel_vsn\}\}/nodetool"},
            {copy, "files/slim_sample", "bin/slim_sample"},
            {copy, "files/slim_sample.cmd", "bin/slim_sample.cmd"},

$ ../rebar generate
  • The erts_vsn directory is not created in slim release as it should be. Therefore nodetool script is moved to under releases/$APP_VSN/ (as template) and erl script should be removed from overlay (by editing).
  • In slim release, rebar generate creates a marker file $RUNNER_BASE_DIR/releases/$APP_VSN/runner_script.data. runner scripts know whether slim release or not(=normal) by its content.
  • Exclusion of hipe application is not related to slim release support, just because my Erlang/OTP is built without hipe.
@tuncer tuncer referenced this pull request
Closed

Add slim release support #7

@joewilliams

Have hot upgrade been tested against a slim release?

@shino

Not yet. I will try soon.

@shino

Oops, upgrade does not work against a slim release :-/ ,
I got an error as below.

Eshell V5.9.3.1  (abort with ^G)
(dummy@127.0.0.1)1> release_handler:unpack_release("dummy_2").
{error,{enoent,"/home/shino/tmp/dynamic_upgrade_slim/dummy/rel/dummy_1/releases/dummy_2.rel"}}
@tuncer

@shino, ping?

@choptastic

Hey guys,

Has any progress been made in the slim releases?

@shino

Rebased on master to avoid merge conflict.

Error in upgrade is caused by release_handler. It seems to be not yet slim release compatible.

  • release_handler:extract_tar extracts releases/*.rel under root directory (code:get_root())
  • release_handler:check_rel try to open extracted file under releases directory under slim release.

So this slim release support does not work with upgrade at present.
Can be merged to master? Or is some effort to Erlang/OTP needed before merge?

P.S.

Trace of release_handler calls by redbug (for curious people):

/opt/erlang/R15B03_1_zdss/ is Erlang root and /tmp/slim/dummy/rel/dummy_1/ is
reltool generated directory.

redbug:start("release_handler:'_' -> return", [{print_depth, 10}, {msgs, 1000}]).
ok
(dummy@127.0.0.1)18> release_handler:unpack_release("dummy_2").

(dummy@127.0.0.1)1> redbug:start("release_handler:'_' -> return", [{print_depth, 10}, {msgs, 1000}]).
ok
(dummy@127.0.0.1)2> release_handler:unpack_release("dummy_2").

22:52:53 <{erlang,apply,2}> {release_handler,unpack_release,["dummy_2"]}

22:52:53 <{erlang,apply,2}> {release_handler,call,
                                [{unpack_release,"dummy_2"}]}

22:52:53 <release_handler> {release_handler,handle_call,
                               [{unpack_release,"dummy_2"},
                                {<0.70.0>,#Ref<0.0.0.246>},
                                {state,[],[...],...}]}

22:52:53 <release_handler> {release_handler,do_unpack_release,
                               ["/opt/erlang/R15B03_1_zdss/bin/../lib/erlang",
                                "/tmp/slim/dummy/rel/dummy_1/releases",
                                "dummy_2",
                                [{release,...}]]}

22:52:53 <release_handler> {release_handler,do_check_file,
                               ["/tmp/slim/dummy/rel/dummy_1/releases/dummy_2.tar.gz",
                                regular]}

22:52:53 <release_handler> {release_handler,do_check_file,2} -> ok

22:52:53 <release_handler> {release_handler,extract_rel_file,
                               ["releases/dummy_2.rel",
                                "/tmp/slim/dummy/rel/dummy_1/releases/dummy_2.tar.gz",
                                "/opt/erlang/R15B03_1_zdss/bin/../lib/erlang"]}

22:52:53 <release_handler> {release_handler,extract_rel_file,3} -> ok
{error,{enoent,"/tmp/slim/dummy/rel/dummy_1/releases/dummy_2.rel"}}

22:52:53 <release_handler> {release_handler,check_rel,
                               ["/opt/erlang/R15B03_1_zdss/bin/../lib/erlang",
                                "/tmp/slim/dummy/rel/dummy_1/releases/dummy_2.rel",
                                false]}

22:52:53 <release_handler> {release_handler,check_rel,
                               ["/opt/erlang/R15B03_1_zdss/bin/../lib/erlang",
                                "/tmp/slim/dummy/rel/dummy_1/releases/dummy_2.rel",
                                [],false]}

22:52:53 <release_handler> {release_handler,consult,
                               ["/tmp/slim/dummy/rel/dummy_1/releases/dummy_2.rel",
                                false]}

22:52:53 <release_handler> {release_handler,consult,2} -> {error,enoent}

22:52:53 <release_handler> {release_handler,check_rel,4} -> {throw,
                                                             {error,
                                                              {enoent,
                                                               "/tmp/slim/dummy/rel/dummy_1/releases/dummy_2.rel"}}}

22:52:53 <release_handler> {release_handler,check_rel,3} -> {throw,
                                                             {error,
                                                              {enoent,
                                                               "/tmp/slim/dummy/rel/dummy_1/releases/dummy_2.rel"}}}

22:52:53 <release_handler> {release_handler,do_unpack_release,4} -> {throw,
                                                                     {error,
                                                                      {enoent,
                                                                       "/tmp/slim/dummy/rel/dummy_1/releases/dummy_2.rel"}}}

22:52:53 <release_handler> {release_handler,handle_call,3} -> {reply,
                                                               {error,
                                                                {enoent,
                                                                 "/tmp/slim/dummy/rel/dummy_1/releases/dummy_2.rel"}},
                                                               {state,[],
                                                                "/opt/erlang/R15B03_1_zdss/bin/../lib/erlang",
                                                                "/tmp/slim/dummy/rel/dummy_1/releases",
                                                                [{...}],
                                                                undefined,...}}

22:52:53 <{erlang,apply,2}> {release_handler,call,1} -> {error,
                                                         {enoent,
                                                          "/tmp/slim/dummy/rel/dummy_1/releases/dummy_2.rel"}}

22:52:53 <{erlang,apply,2}> {release_handler,unpack_release,1} -> {error,
                                                                   {enoent,
                                                                    "/tmp/slim/dummy/rel/dummy_1/releases/dummy_2.rel"}}
@tuncer tuncer referenced this pull request in klacke/yaws
Merged

rel: add Windows scripts #148

@shino

Siri told me the workaround

  • unpack relup archive manually, and
  • use release_hander:set_unpacked/2

So now (very simple) upgrading can be done in slim release.
Steps are illustrated at https://github.com/shino/slim-upgrade-sample .

@shino

Workaround to upgrade is found and it may be implemented by upgrade script.
That work is not done yet but filed as the issue above.
Also I added TODO comment to install_upgrade script at the commit 61982e3.

I hope it is now ready for review again :)

@jaredmorrow
Owner

This looks fine to us. Can you rebase this so it merges cleanly and then I'll merge.

@shino

Rebased on current master fa1a2b5 .

@runcom

ping! can this be merged? (It would be good to add some lines in the wiki as well @shino )

@jaredmorrow jaredmorrow merged commit 755c602 into rebar:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
8 priv/templates/simplenode.install_upgrade.escript 100644 → 100755
@@ -6,6 +6,14 @@
-define(TIMEOUT, 60000).
-define(INFO(Fmt,Args), io:format(Fmt,Args)).
+%% TODO: This script currently does NOT support slim releases.
+%% Necessary steps to upgrade a slim release are as follows:
+%% 1. unpack relup archive manually
+%% 2. copy releases directory and necessary libraries
+%% 3. using release_hander:set_unpacked/2 .
+%% For more details, see https://github.com/rebar/rebar/pull/52
+%% and https://github.com/rebar/rebar/issues/202
+
main([NodeName, Cookie, ReleasePackage]) ->
TargetNode = start_distribution(NodeName, Cookie),
{ok, Vsn} = rpc:call(TargetNode, release_handler, unpack_release,
View
2  priv/templates/simplenode.reltool.config
@@ -32,7 +32,7 @@
{overlay, [
{mkdir, "log/sasl"},
{copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"},
- {copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"},
+ {copy, "files/nodetool", "releases/\{\{rel_vsn\}\}/nodetool"},
{copy, "{{nodeid}}/bin/start_clean.boot",
"\{\{erts_vsn\}\}/bin/start_clean.boot"},
{copy, "files/{{nodeid}}", "bin/{{nodeid}}"},
View
46 priv/templates/simplenode.runner
@@ -130,11 +130,43 @@ cd $USE_DIR
# Make sure log directory exists
mkdir -p $USE_DIR/log
-# Add ERTS bin dir to our path
-ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
+RUNNER_SCRIPT_DATA=
+if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/runner_script.data" ]; then
+ RUNNER_SCRIPT_DATA=`cat $RUNNER_BASE_DIR/releases/$APP_VSN/runner_script.data`
+fi
-# Setup command to control the node
-NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
+if [ -z "$RUNNER_SCRIPT_DATA" ]; then
+ ROOTDIR=$RUNNER_BASE_DIR
+ ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
+ if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/nodetool" ]; then
+ NODETOOL="$ERTS_PATH/escript $RUNNER_BASE_DIR/releases/$APP_VSN/nodetool $NAME_ARG $COOKIE_ARG"
+ else
+ NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
+ fi
+ SLIM_ARGS=
+elif [ "$RUNNER_SCRIPT_DATA" = "slim" ]; then
+ # Setup system paths
+ SYSTEM_ERL_PATH=`which erl`
+ if [ ! -x "$SYSTEM_ERL_PATH" ]; then
+ echo "Failed to find erl. Is Erlang/OTP available in PATH?"
+ exit 1
+ fi
+ SYSTEM_HOME_BIN=${SYSTEM_ERL_PATH%/*}
+ ROOTDIR=$SYSTEM_HOME_BIN/../lib/erlang
+ ERTS_PATH=$ROOTDIR/erts-$ERTS_VSN/bin
+ unset SYSTEM_ERL_PATH
+ unset SYSTEM_HOME_BIN
+
+ LOCAL_ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
+ NODETOOL="$ERTS_PATH/escript $RUNNER_BASE_DIR/releases/$APP_VSN/nodetool $NAME_ARG $COOKIE_ARG"
+ unset LOCAL_ERL_PATH
+
+ # Setup additional arguments for slim release
+ SLIM_ARGS="-boot_var RELTOOL_EXT_LIB $RUNNER_BASE_DIR/lib -sasl releases_dir \"$RUNNER_BASE_DIR/releases\""
+else
+ echo "Unknown runner_script.data"
+ exit 1
+fi
# Setup remote shell command to control node
REMSH="$ERTS_PATH/erl -hidden $REMSH_NAME_ARG $REMSH_REMSH_ARG $COOKIE_ARG"
@@ -310,11 +342,10 @@ case "$1" in
;;
esac
# Setup beam-required vars
- ROOTDIR=$RUNNER_BASE_DIR
BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
EMU=beam
PROGNAME=`echo $0 | sed 's/.*\\///'`
- CMD="$BINDIR/erlexec -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -mode embedded -config $CONFIG_PATH -args_file $VMARGS_PATH"
+ CMD="$BINDIR/erlexec $SLIM_ARGS -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -mode embedded -config $CONFIG_PATH -args_file $VMARGS_PATH"
export EMU
export ROOTDIR
export BINDIR
@@ -339,11 +370,10 @@ case "$1" in
FOREGROUNDOPTIONS="-noinput +Bd"
# Setup beam-required vars
- ROOTDIR=$RUNNER_BASE_DIR
BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
EMU=beam
PROGNAME=`echo $0 | sed 's/.*\///'`
- CMD="$BINDIR/erlexec $FOREGROUNDOPTIONS -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -config $CONFIG_PATH -args_file $VMARGS_PATH"
+ CMD="$BINDIR/erlexec $SLIM_ARGS $FOREGROUNDOPTIONS -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -config $CONFIG_PATH -args_file $VMARGS_PATH"
export EMU
export ROOTDIR
export BINDIR
View
8 src/rebar_rel_utils.erl
@@ -37,6 +37,7 @@
get_rel_file_path/2,
load_config/2,
get_sys_tuple/1,
+ get_excl_lib_tuple/1,
get_target_dir/2,
get_root_dir/2,
get_target_parent_dir/2]).
@@ -144,6 +145,13 @@ get_sys_tuple(ReltoolConfig) ->
end.
%%
+%% Look for the {excl_lib, ...} tuple in sys tuple of the reltool.config file.
+%% Without this present, return false.
+%%
+get_excl_lib_tuple(ReltoolConfig) ->
+ lists:keyfind(excl_lib, 1, element(2, get_sys_tuple(ReltoolConfig))).
+
+%%
%% Look for {target_dir, TargetDir} in the reltool config file; if none is
%% found, use the name of the release as the default target directory.
%%
View
33 src/rebar_reltool.erl
@@ -147,15 +147,12 @@ process_overlay(Config, ReltoolConfig) ->
OverlayVars1),
%% Finally, overlay the files specified by the overlay section
- case lists:keyfind(overlay, 1, ReltoolConfig) of
- {overlay, Overlay} when is_list(Overlay) ->
+ case overlay_files(ReltoolConfig) of
+ [] ->
+ ok;
+ Overlay ->
execute_overlay(Overlay, OverlayVars, rebar_utils:get_cwd(),
- TargetDir);
- false ->
- ?INFO("No {overlay, [...]} found in reltool.config.\n", []);
- _ ->
- ?ABORT("{overlay, [...]} entry in reltool.config "
- "must be a list.\n", [])
+ TargetDir)
end.
%%
@@ -292,6 +289,26 @@ dump_spec(Config, Spec) ->
end.
+overlay_files(ReltoolConfig) ->
+ Original = case lists:keyfind(overlay, 1, ReltoolConfig) of
+ {overlay, Overlay} when is_list(Overlay) ->
+ Overlay;
+ false ->
+ ?INFO("No {overlay, [...]} found in reltool.config.\n", []),
+ [];
+ _ ->
+ ?ABORT("{overlay, [...]} entry in reltool.config "
+ "must be a list.\n", [])
+ end,
+ SlimAddition = case rebar_rel_utils:get_excl_lib_tuple(ReltoolConfig) of
+ {excl_lib, otp_root} ->
+ [{create, "releases/{{rel_vsn}}/runner_script.data",
+ "slim\n"}];
+ false ->
+ []
+ end,
+ Original ++ SlimAddition.
+
%% TODO: Merge functionality here with rebar_templater
execute_overlay([], _Vars, _BaseDir, _TargetDir) ->
Something went wrong with that request. Please try again.