From cb5056b2e362aa0b1eb0ccfc6009613426682ed5 Mon Sep 17 00:00:00 2001 From: joewilliams Date: Tue, 20 Sep 2011 09:44:41 -0700 Subject: [PATCH] Get rid of app.config app.config has been a long standing erroneous file in rebar. Erlang/OTP documentation suggests a sys.config file instead. This file is stored in the releases/VSN directory. This does a few things but most importantly it ensures your config (contained in the application environment) survives a hot upgrade. It also has the advantage of allowing the configuration of the application to be versioned along side the application code. This patch flips rebar to use sys.config rather than app.config. Additionally it makes this flip to vm.args as well, making them versioned just like sys.config. This patch also includes runner script changes to support the old etc/app.config config file location and support for Windows. Thanks to mokele for the initial work and kick in the pants to make this finially happen. --- priv/templates/simplenode.reltool.config | 11 +++++++-- priv/templates/simplenode.runner | 16 ++++++++++++- ...enode.app.config => simplenode.sys.config} | 0 priv/templates/simplenode.template | 2 +- .../simplenode.windows.start_erl.cmd | 14 +++++++++-- src/rebar_rel_utils.erl | 15 ++++++++---- src/rebar_reltool.erl | 23 +++++++++++++++++-- src/rebar_upgrade.erl | 17 +++++++------- test/upgrade_project/rel/files/dummy | 16 ++++++++++++- .../rel/files/{app.config => sys.config} | 1 - test/upgrade_project/rel/reltool.config | 4 ++-- 11 files changed, 94 insertions(+), 25 deletions(-) rename priv/templates/{simplenode.app.config => simplenode.sys.config} (100%) rename test/upgrade_project/rel/files/{app.config => sys.config} (99%) diff --git a/priv/templates/simplenode.reltool.config b/priv/templates/simplenode.reltool.config index 4248b9c..dc247cd 100644 --- a/priv/templates/simplenode.reltool.config +++ b/priv/templates/simplenode.reltool.config @@ -13,8 +13,15 @@ ]}, {boot_rel, "{{nodeid}}"}, {profile, embedded}, + {excl_archive_filters, [".*"]}, %% Do not archive built libs {excl_sys_filters, ["^bin/.*", "^erts.*/bin/(dialyzer|typer)"]}, + + %% Including HiPE can cause issues generating your first upgrade. + %% If you plan to distribute HiPE in your release remove the + %% following line. + {app, hipe, [{incl_cond, exclude}]}, + {app, sasl, [{incl_cond, include}]} ]}. @@ -25,8 +32,8 @@ {copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"}, {copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"}, {copy, "files/{{nodeid}}", "bin/{{nodeid}}"}, + {copy, "files/sys.config", "releases/\{\{rel_vsn\}\}/sys.config"}, {copy, "files/{{nodeid}}.cmd", "bin/{{nodeid}}.cmd"}, {copy, "files/start_erl.cmd", "bin/start_erl.cmd"}, - {copy, "files/app.config", "etc/app.config"}, - {copy, "files/vm.args", "etc/vm.args"} + {copy, "files/vm.args", "releases/\{\{rel_vsn\}\}/vm.args"} ]}. diff --git a/priv/templates/simplenode.runner b/priv/templates/simplenode.runner index bacce8d..78d6bae 100755 --- a/priv/templates/simplenode.runner +++ b/priv/templates/simplenode.runner @@ -50,6 +50,20 @@ ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin # Setup command to control the node NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG" +# Use releases/VSN/sys.config if it exists otherwise use etc/app.config +if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config" ]; then + CONFIG_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config" +else + CONFIG_PATH="$RUNNER_ETC_DIR/app.config" +fi + +# Use releases/VSN/vm.args if it exists otherwise use etc/vm.args +if [-e "$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args" ]; then + VMARGS_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args" +else + VMARGS_PATH="$RUNNER_ETC_DIR/vm.args" +fi + # Check the first argument for instructions case "$1" in start) @@ -147,7 +161,7 @@ case "$1" in 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 $RUNNER_ETC_DIR/app.config -args_file $RUNNER_ETC_DIR/vm.args -- ${1+"$@"}" + CMD="$BINDIR/erlexec -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -mode embedded -config $CONFIG_PATH -args_file $VMARGS_PATH -- ${1+"$@"}" export EMU export ROOTDIR export BINDIR diff --git a/priv/templates/simplenode.app.config b/priv/templates/simplenode.sys.config similarity index 100% rename from priv/templates/simplenode.app.config rename to priv/templates/simplenode.sys.config diff --git a/priv/templates/simplenode.template b/priv/templates/simplenode.template index 974c6f0..d074681 100644 --- a/priv/templates/simplenode.template +++ b/priv/templates/simplenode.template @@ -6,7 +6,7 @@ {chmod, 8#744, "files/nodetool"}. {file, "simplenode.runner", "files/{{nodeid}}"}. {chmod, 8#744, "files/{{nodeid}}"}. -{file, "simplenode.app.config", "files/app.config"}. +{file, "simplenode.sys.config", "files/sys.config"}. {template, "simplenode.vm.args", "files/vm.args"}. {template, "simplenode.windows.runner.cmd", "files/{{nodeid}}.cmd"}. {file, "simplenode.windows.start_erl.cmd", "files/start_erl.cmd"}. diff --git a/priv/templates/simplenode.windows.start_erl.cmd b/priv/templates/simplenode.windows.start_erl.cmd index b26e98a..f98c285 100644 --- a/priv/templates/simplenode.windows.start_erl.cmd +++ b/priv/templates/simplenode.windows.start_erl.cmd @@ -19,8 +19,18 @@ @set erl_exe=%node_root%\erts-%erts_version%\bin\erl.exe @set boot_file=%releases_dir%\%release_version%\%node_name% -@set app_config=%node_root%\etc\app.config -@set vm_args=%node_root%\etc\vm.args + +@if exist %releases_dir%\%release_version%\sys.config ( + @set app_config=%releases_dir%\%release_version%\sys.config +) @else ( + @set app_config=%node_root%\etc\app.config +) + +@if exist %releases_dir%\%release_version%\vm.args ( + @set vm_args=%releases_dir%\%release_version%\vm.args +) @else ( + @set vm_args=%node_root%\etc\vm.args +) @%erl_exe% %erl_args% -boot %boot_file% -config %app_config% -args_file %vm_args% diff --git a/src/rebar_rel_utils.erl b/src/rebar_rel_utils.erl index bdf58d3..d9a1fc6 100644 --- a/src/rebar_rel_utils.erl +++ b/src/rebar_rel_utils.erl @@ -55,11 +55,16 @@ is_rel_dir(Dir) -> end. %% Get release name and version from a reltool.config -get_reltool_release_info(ReltoolConfig) -> - %% expect the first rel in the proplist to be the one you want - {sys, Config} = get_sys_tuple(ReltoolConfig), +get_reltool_release_info([{sys, Config}| _]) -> {rel, Name, Ver, _} = proplists:lookup(rel, Config), - {Name, Ver}. + {Name, Ver}; +get_reltool_release_info(ReltoolFile) when is_list(ReltoolFile) -> + case file:consult(ReltoolFile) of + {ok, ReltoolConfig} -> + get_reltool_release_info(ReltoolConfig); + _ -> + ?ABORT("Failed to parse ~s~n", [ReltoolFile]) + end. %% Get release name and version from a rel file get_rel_release_info(RelFile) -> @@ -170,4 +175,4 @@ make_proplist([H|T], Acc) -> Ver = element(2, H), make_proplist(T, [{App,Ver}|Acc]); make_proplist([], Acc) -> - Acc. + Acc. \ No newline at end of file diff --git a/src/rebar_reltool.erl b/src/rebar_reltool.erl index b1b4a4c..363b384 100644 --- a/src/rebar_reltool.erl +++ b/src/rebar_reltool.erl @@ -173,10 +173,17 @@ run_reltool(Server, _Config, ReltoolConfig) -> [Reason]) end, + {BootRelName, BootRelVsn} = + rebar_rel_utils:get_reltool_release_info(ReltoolConfig), + + ok = create_RELEASES(TargetDir, BootRelName, BootRelVsn), + %% Initialize overlay vars with some basics %% (that can get overwritten) - OverlayVars0 = dict:from_list([{erts_vsn, "erts-" ++ erlang:system_info(version)}, - {target_dir, TargetDir}]), + OverlayVars0 = + dict:from_list([{erts_vsn, "erts-" ++ erlang:system_info(version)}, + {rel_vsn, BootRelVsn}, + {target_dir, TargetDir}]), %% Load up any variables specified by overlay_vars OverlayVars1 = overlay_vars(OverlayVars0, ReltoolConfig), @@ -312,3 +319,15 @@ execute_overlay([Other | _Rest], _Vars, _BaseDir, _TargetDir) -> apply_file_info(InFile, OutFile) -> {ok, FileInfo} = file:read_file_info(InFile), ok = file:write_file_info(OutFile, FileInfo). + +create_RELEASES(TargetDir, RelName, RelVsn) -> + ReleasesDir = filename:join(TargetDir, "releases"), + case release_handler:create_RELEASES(TargetDir, ReleasesDir, + filename:join([ReleasesDir, RelVsn, RelName ++ ".rel"]), + filename:join(TargetDir, "lib")) of + ok -> + ok; + {error, Reason} -> + ?ABORT("Failed to create RELEASES file: ~p\n", + [Reason]) + end. \ No newline at end of file diff --git a/src/rebar_upgrade.erl b/src/rebar_upgrade.erl index 009715e..0cecaab 100644 --- a/src/rebar_upgrade.erl +++ b/src/rebar_upgrade.erl @@ -32,6 +32,8 @@ -export(['generate-upgrade'/2]). +-define(TMP, "_tmp"). + %% ==================================================================== %% Public API %% ==================================================================== @@ -141,22 +143,21 @@ run_systools(NewVer, Name) -> end. boot_files(TargetDir, Ver, Name) -> - Tmp = "_tmp", - ok = file:make_dir(filename:join([".", Tmp])), - ok = file:make_dir(filename:join([".", Tmp, "releases"])), - ok = file:make_dir(filename:join([".", Tmp, "releases", Ver])), + ok = file:make_dir(filename:join([".", ?TMP])), + ok = file:make_dir(filename:join([".", ?TMP, "releases"])), + ok = file:make_dir(filename:join([".", ?TMP, "releases", Ver])), ok = file:make_symlink( filename:join(["start.boot"]), - filename:join([".", Tmp, "releases", Ver, Name ++ ".boot"])), + filename:join([".", ?TMP, "releases", Ver, Name ++ ".boot"])), {ok, _} = file:copy( filename:join([TargetDir, "releases", Ver, "start_clean.boot"]), - filename:join([".", Tmp, "releases", Ver, "start_clean.boot"])). + filename:join([".", ?TMP, "releases", Ver, "start_clean.boot"])). make_tar(NameVer) -> Filename = NameVer ++ ".tar.gz", {ok, Cwd} = file:get_cwd(), Absname = filename:join([Cwd, Filename]), - ok = file:set_cwd("_tmp"), + ok = file:set_cwd(?TMP), ok = erl_tar:extract(Absname, [compressed]), ok = file:delete(Absname), {ok, Tar} = erl_tar:open(Absname, [write, compressed]), @@ -176,7 +177,7 @@ cleanup(NameVer) -> ], lists:foreach(fun(F) -> ok = file:delete(F) end, Files), - ok = remove_dir_tree("_tmp"). + ok = remove_dir_tree(?TMP). %% adapted from http://www.erlang.org/doc/system_principles/create_target.html remove_dir_tree(Dir) -> diff --git a/test/upgrade_project/rel/files/dummy b/test/upgrade_project/rel/files/dummy index bacce8d..78d6bae 100755 --- a/test/upgrade_project/rel/files/dummy +++ b/test/upgrade_project/rel/files/dummy @@ -50,6 +50,20 @@ ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin # Setup command to control the node NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG" +# Use releases/VSN/sys.config if it exists otherwise use etc/app.config +if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config" ]; then + CONFIG_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config" +else + CONFIG_PATH="$RUNNER_ETC_DIR/app.config" +fi + +# Use releases/VSN/vm.args if it exists otherwise use etc/vm.args +if [-e "$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args" ]; then + VMARGS_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args" +else + VMARGS_PATH="$RUNNER_ETC_DIR/vm.args" +fi + # Check the first argument for instructions case "$1" in start) @@ -147,7 +161,7 @@ case "$1" in 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 $RUNNER_ETC_DIR/app.config -args_file $RUNNER_ETC_DIR/vm.args -- ${1+"$@"}" + CMD="$BINDIR/erlexec -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -mode embedded -config $CONFIG_PATH -args_file $VMARGS_PATH -- ${1+"$@"}" export EMU export ROOTDIR export BINDIR diff --git a/test/upgrade_project/rel/files/app.config b/test/upgrade_project/rel/files/sys.config similarity index 99% rename from test/upgrade_project/rel/files/app.config rename to test/upgrade_project/rel/files/sys.config index 3b7f6bd..d7677e7 100644 --- a/test/upgrade_project/rel/files/app.config +++ b/test/upgrade_project/rel/files/sys.config @@ -8,4 +8,3 @@ {error_logger_mf_maxfiles, 5} % 5 files max ]} ]. - diff --git a/test/upgrade_project/rel/reltool.config b/test/upgrade_project/rel/reltool.config index 22cec5e..9672abc 100644 --- a/test/upgrade_project/rel/reltool.config +++ b/test/upgrade_project/rel/reltool.config @@ -20,6 +20,6 @@ {copy, "files/erl", "{{erts_vsn}}/bin/erl"}, {copy, "files/nodetool", "{{erts_vsn}}/bin/nodetool"}, {copy, "files/dummy", "bin/dummy"}, - {copy, "files/app.config", "etc/app.config"}, - {copy, "files/vm.args", "etc/vm.args"} + {copy, "files/sys.config", "releases/\{\{rel_vsn\}\}/sys.config"}, + {copy, "files/vm.args", "releases/\{\{rel_vsn\}\}/vm.args"} ]}.