소스 검색

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.
pull/3/head
joewilliams 13 년 전
부모
커밋
cb5056b2e3
11개의 변경된 파일94개의 추가작업 그리고 25개의 파일을 삭제
  1. +9
    -2
      priv/templates/simplenode.reltool.config
  2. +15
    -1
      priv/templates/simplenode.runner
  3. +0
    -0
      priv/templates/simplenode.sys.config
  4. +1
    -1
      priv/templates/simplenode.template
  5. +12
    -2
      priv/templates/simplenode.windows.start_erl.cmd
  6. +10
    -5
      src/rebar_rel_utils.erl
  7. +21
    -2
      src/rebar_reltool.erl
  8. +9
    -8
      src/rebar_upgrade.erl
  9. +15
    -1
      test/upgrade_project/rel/files/dummy
  10. +0
    -1
      test/upgrade_project/rel/files/sys.config
  11. +2
    -2
      test/upgrade_project/rel/reltool.config

+ 9
- 2
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"}
]}.

+ 15
- 1
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

priv/templates/simplenode.app.config → priv/templates/simplenode.sys.config 파일 보기


+ 1
- 1
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"}.

+ 12
- 2
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%

+ 10
- 5
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.

+ 21
- 2
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.

+ 9
- 8
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) ->

+ 15
- 1
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

test/upgrade_project/rel/files/app.config → test/upgrade_project/rel/files/sys.config 파일 보기

@ -8,4 +8,3 @@
{error_logger_mf_maxfiles, 5} % 5 files max
]}
].

+ 2
- 2
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"}
]}.

불러오는 중...
취소
저장