mirror of
https://github.com/correl/rebar.git
synced 2024-11-23 19:19:54 +00:00
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.
This commit is contained in:
parent
5998c6c721
commit
cb5056b2e3
11 changed files with 94 additions and 25 deletions
|
@ -13,8 +13,15 @@
|
||||||
]},
|
]},
|
||||||
{boot_rel, "{{nodeid}}"},
|
{boot_rel, "{{nodeid}}"},
|
||||||
{profile, embedded},
|
{profile, embedded},
|
||||||
|
{excl_archive_filters, [".*"]}, %% Do not archive built libs
|
||||||
{excl_sys_filters, ["^bin/.*",
|
{excl_sys_filters, ["^bin/.*",
|
||||||
"^erts.*/bin/(dialyzer|typer)"]},
|
"^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}]}
|
{app, sasl, [{incl_cond, include}]}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
|
@ -25,8 +32,8 @@
|
||||||
{copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"},
|
{copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"},
|
||||||
{copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"},
|
{copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"},
|
||||||
{copy, "files/{{nodeid}}", "bin/{{nodeid}}"},
|
{copy, "files/{{nodeid}}", "bin/{{nodeid}}"},
|
||||||
|
{copy, "files/sys.config", "releases/\{\{rel_vsn\}\}/sys.config"},
|
||||||
{copy, "files/{{nodeid}}.cmd", "bin/{{nodeid}}.cmd"},
|
{copy, "files/{{nodeid}}.cmd", "bin/{{nodeid}}.cmd"},
|
||||||
{copy, "files/start_erl.cmd", "bin/start_erl.cmd"},
|
{copy, "files/start_erl.cmd", "bin/start_erl.cmd"},
|
||||||
{copy, "files/app.config", "etc/app.config"},
|
{copy, "files/vm.args", "releases/\{\{rel_vsn\}\}/vm.args"}
|
||||||
{copy, "files/vm.args", "etc/vm.args"}
|
|
||||||
]}.
|
]}.
|
||||||
|
|
|
@ -50,6 +50,20 @@ ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
|
||||||
# Setup command to control the node
|
# Setup command to control the node
|
||||||
NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
|
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
|
# Check the first argument for instructions
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
|
@ -147,7 +161,7 @@ case "$1" in
|
||||||
BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
|
BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
|
||||||
EMU=beam
|
EMU=beam
|
||||||
PROGNAME=`echo $0 | sed 's/.*\\///'`
|
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 EMU
|
||||||
export ROOTDIR
|
export ROOTDIR
|
||||||
export BINDIR
|
export BINDIR
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
{chmod, 8#744, "files/nodetool"}.
|
{chmod, 8#744, "files/nodetool"}.
|
||||||
{file, "simplenode.runner", "files/{{nodeid}}"}.
|
{file, "simplenode.runner", "files/{{nodeid}}"}.
|
||||||
{chmod, 8#744, "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.vm.args", "files/vm.args"}.
|
||||||
{template, "simplenode.windows.runner.cmd", "files/{{nodeid}}.cmd"}.
|
{template, "simplenode.windows.runner.cmd", "files/{{nodeid}}.cmd"}.
|
||||||
{file, "simplenode.windows.start_erl.cmd", "files/start_erl.cmd"}.
|
{file, "simplenode.windows.start_erl.cmd", "files/start_erl.cmd"}.
|
||||||
|
|
|
@ -19,8 +19,18 @@
|
||||||
|
|
||||||
@set erl_exe=%node_root%\erts-%erts_version%\bin\erl.exe
|
@set erl_exe=%node_root%\erts-%erts_version%\bin\erl.exe
|
||||||
@set boot_file=%releases_dir%\%release_version%\%node_name%
|
@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%
|
@%erl_exe% %erl_args% -boot %boot_file% -config %app_config% -args_file %vm_args%
|
||||||
|
|
||||||
|
|
|
@ -55,11 +55,16 @@ is_rel_dir(Dir) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% Get release name and version from a reltool.config
|
%% Get release name and version from a reltool.config
|
||||||
get_reltool_release_info(ReltoolConfig) ->
|
get_reltool_release_info([{sys, Config}| _]) ->
|
||||||
%% expect the first rel in the proplist to be the one you want
|
|
||||||
{sys, Config} = get_sys_tuple(ReltoolConfig),
|
|
||||||
{rel, Name, Ver, _} = proplists:lookup(rel, 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 release name and version from a rel file
|
||||||
get_rel_release_info(RelFile) ->
|
get_rel_release_info(RelFile) ->
|
||||||
|
|
|
@ -173,10 +173,17 @@ run_reltool(Server, _Config, ReltoolConfig) ->
|
||||||
[Reason])
|
[Reason])
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
{BootRelName, BootRelVsn} =
|
||||||
|
rebar_rel_utils:get_reltool_release_info(ReltoolConfig),
|
||||||
|
|
||||||
|
ok = create_RELEASES(TargetDir, BootRelName, BootRelVsn),
|
||||||
|
|
||||||
%% Initialize overlay vars with some basics
|
%% Initialize overlay vars with some basics
|
||||||
%% (that can get overwritten)
|
%% (that can get overwritten)
|
||||||
OverlayVars0 = dict:from_list([{erts_vsn, "erts-" ++ erlang:system_info(version)},
|
OverlayVars0 =
|
||||||
{target_dir, TargetDir}]),
|
dict:from_list([{erts_vsn, "erts-" ++ erlang:system_info(version)},
|
||||||
|
{rel_vsn, BootRelVsn},
|
||||||
|
{target_dir, TargetDir}]),
|
||||||
|
|
||||||
%% Load up any variables specified by overlay_vars
|
%% Load up any variables specified by overlay_vars
|
||||||
OverlayVars1 = overlay_vars(OverlayVars0, ReltoolConfig),
|
OverlayVars1 = overlay_vars(OverlayVars0, ReltoolConfig),
|
||||||
|
@ -312,3 +319,15 @@ execute_overlay([Other | _Rest], _Vars, _BaseDir, _TargetDir) ->
|
||||||
apply_file_info(InFile, OutFile) ->
|
apply_file_info(InFile, OutFile) ->
|
||||||
{ok, FileInfo} = file:read_file_info(InFile),
|
{ok, FileInfo} = file:read_file_info(InFile),
|
||||||
ok = file:write_file_info(OutFile, FileInfo).
|
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.
|
|
@ -32,6 +32,8 @@
|
||||||
|
|
||||||
-export(['generate-upgrade'/2]).
|
-export(['generate-upgrade'/2]).
|
||||||
|
|
||||||
|
-define(TMP, "_tmp").
|
||||||
|
|
||||||
%% ====================================================================
|
%% ====================================================================
|
||||||
%% Public API
|
%% Public API
|
||||||
%% ====================================================================
|
%% ====================================================================
|
||||||
|
@ -141,22 +143,21 @@ run_systools(NewVer, Name) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
boot_files(TargetDir, Ver, Name) ->
|
boot_files(TargetDir, Ver, Name) ->
|
||||||
Tmp = "_tmp",
|
ok = file:make_dir(filename:join([".", ?TMP])),
|
||||||
ok = file:make_dir(filename:join([".", Tmp])),
|
ok = file:make_dir(filename:join([".", ?TMP, "releases"])),
|
||||||
ok = file:make_dir(filename:join([".", Tmp, "releases"])),
|
ok = file:make_dir(filename:join([".", ?TMP, "releases", Ver])),
|
||||||
ok = file:make_dir(filename:join([".", Tmp, "releases", Ver])),
|
|
||||||
ok = file:make_symlink(
|
ok = file:make_symlink(
|
||||||
filename:join(["start.boot"]),
|
filename:join(["start.boot"]),
|
||||||
filename:join([".", Tmp, "releases", Ver, Name ++ ".boot"])),
|
filename:join([".", ?TMP, "releases", Ver, Name ++ ".boot"])),
|
||||||
{ok, _} = file:copy(
|
{ok, _} = file:copy(
|
||||||
filename:join([TargetDir, "releases", Ver, "start_clean.boot"]),
|
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) ->
|
make_tar(NameVer) ->
|
||||||
Filename = NameVer ++ ".tar.gz",
|
Filename = NameVer ++ ".tar.gz",
|
||||||
{ok, Cwd} = file:get_cwd(),
|
{ok, Cwd} = file:get_cwd(),
|
||||||
Absname = filename:join([Cwd, Filename]),
|
Absname = filename:join([Cwd, Filename]),
|
||||||
ok = file:set_cwd("_tmp"),
|
ok = file:set_cwd(?TMP),
|
||||||
ok = erl_tar:extract(Absname, [compressed]),
|
ok = erl_tar:extract(Absname, [compressed]),
|
||||||
ok = file:delete(Absname),
|
ok = file:delete(Absname),
|
||||||
{ok, Tar} = erl_tar:open(Absname, [write, compressed]),
|
{ok, Tar} = erl_tar:open(Absname, [write, compressed]),
|
||||||
|
@ -176,7 +177,7 @@ cleanup(NameVer) ->
|
||||||
],
|
],
|
||||||
lists:foreach(fun(F) -> ok = file:delete(F) end, Files),
|
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
|
%% adapted from http://www.erlang.org/doc/system_principles/create_target.html
|
||||||
remove_dir_tree(Dir) ->
|
remove_dir_tree(Dir) ->
|
||||||
|
|
|
@ -50,6 +50,20 @@ ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
|
||||||
# Setup command to control the node
|
# Setup command to control the node
|
||||||
NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
|
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
|
# Check the first argument for instructions
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
|
@ -147,7 +161,7 @@ case "$1" in
|
||||||
BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
|
BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
|
||||||
EMU=beam
|
EMU=beam
|
||||||
PROGNAME=`echo $0 | sed 's/.*\\///'`
|
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 EMU
|
||||||
export ROOTDIR
|
export ROOTDIR
|
||||||
export BINDIR
|
export BINDIR
|
||||||
|
|
|
@ -8,4 +8,3 @@
|
||||||
{error_logger_mf_maxfiles, 5} % 5 files max
|
{error_logger_mf_maxfiles, 5} % 5 files max
|
||||||
]}
|
]}
|
||||||
].
|
].
|
||||||
|
|
|
@ -20,6 +20,6 @@
|
||||||
{copy, "files/erl", "{{erts_vsn}}/bin/erl"},
|
{copy, "files/erl", "{{erts_vsn}}/bin/erl"},
|
||||||
{copy, "files/nodetool", "{{erts_vsn}}/bin/nodetool"},
|
{copy, "files/nodetool", "{{erts_vsn}}/bin/nodetool"},
|
||||||
{copy, "files/dummy", "bin/dummy"},
|
{copy, "files/dummy", "bin/dummy"},
|
||||||
{copy, "files/app.config", "etc/app.config"},
|
{copy, "files/sys.config", "releases/\{\{rel_vsn\}\}/sys.config"},
|
||||||
{copy, "files/vm.args", "etc/vm.args"}
|
{copy, "files/vm.args", "releases/\{\{rel_vsn\}\}/vm.args"}
|
||||||
]}.
|
]}.
|
||||||
|
|
Loading…
Reference in a new issue