Skip to content

Commit

Permalink
Ulimit start warning (#525)
Browse files Browse the repository at this point in the history
- Update rebar3 binary to v3.4.7

This allows usage of rebar3 start script hooks
https://www.rebar3.org/v3/docs/releases#section-hooks

- Add rebar pre start hook
- Warn if the ulimit -n is lower than recommended on node start
- make test suite setup (cp_dir()) more portable
  • Loading branch information
uwiger authored and dincho committed Dec 21, 2017
1 parent 1317755 commit 9d6a11b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
44 changes: 42 additions & 2 deletions apps/aecore/test/aecore_suite_utils.erl
Expand Up @@ -29,7 +29,7 @@
await_aehttp/1
]).


-include_lib("kernel/include/file.hrl").
-include_lib("common_test/include/ct.hrl").

%%%=============================================================================
Expand Down Expand Up @@ -242,7 +242,47 @@ setup_node(N, Top, Epoch, Config) ->


cp_dir(From, To) ->
cmd(["cp -r ", From, " ", To]).
ToDir = case lists:last(To) of
$/ ->
filename:join(To, filename:basename(From));
_ ->
To
end,
ok = filelib:ensure_dir(filename:join(ToDir, "foo")),
cp_dir(file:list_dir(From), From, ToDir).

cp_dir({ok, Fs}, From, To) ->
Res =
lists:foldl(
fun(F, Acc) ->
FullF = filename:join(From, F),
case filelib:is_dir(FullF) of
true ->
To1 = filename:join(To, F),
cp_dir(FullF, To1),
[FullF|Acc];
false ->
Tgt = filename:join(To, F),
ok = filelib:ensure_dir(Tgt),
{ok,_} = file:copy(FullF, Tgt),
ok = match_mode(FullF, Tgt),
[FullF|Acc]
end
end, [], Fs),
ct:log("cp_dir(~p, ~p) -> ~p", [From, To, Res]),
ok;
cp_dir({error, _} = Error, From, To) ->
ct:log("cp_dir(~p, ~p) -> ~p", [From, To, Error]),
Error.

match_mode(A, B) ->
case {file:read_link_info(A), file:read_file_info(B)} of
{{ok, #file_info{mode = M}}, {ok, FI}} ->
file:write_file_info(B, FI#file_info{mode = M});
Other ->
ct:log("Error matching mode ~p -> ~p: ~p", [A, B, Other]),
{error, {match_mode, {A, B}, Other}}
end.

cp_file(From, To) ->
{ok, _} = file:copy(From, To),
Expand Down
9 changes: 9 additions & 0 deletions hooks/pre_start.sh
@@ -0,0 +1,9 @@
#!/bin/bash

OPEN_FILES_RECOMMENDED=24576
OPEN_FILES_LIMIT=$(ulimit -n)

if [ "$OPEN_FILES_RECOMMENDED" -gt "$OPEN_FILES_LIMIT" ]; then
echo "WARNING: ulimit -n is $OPEN_FILES_LIMIT; $OPEN_FILES_RECOMMENDED is the recommended minimum."
echo "You are recommended to ensure the node is stopped and raise the maximum number of open files (try 'ulimit -n $OPEN_FILES_RECOMMENDED') before starting the node."
fi
9 changes: 7 additions & 2 deletions rebar.config
Expand Up @@ -31,8 +31,13 @@
{overlay, [{copy, "REVISION", "REVISION"},
{copy, "VERSION" , "VERSION"},
{mkdir, "data/aecore/.genesis"},
{copy, "data/aecore/.genesis/accounts.json", "data/aecore/.genesis/accounts.json"}]},
{extended_start_script, true}]
{copy, "data/aecore/.genesis/accounts.json", "data/aecore/.genesis/accounts.json"},
{copy, "hooks/pre_start.sh", "bin/hooks/pre_start.sh"}]},

{extended_start_script, true},
{extended_start_script_hooks, [
{pre_start, [{custom, "hooks/pre_start.sh"}]}
]}]
}.

{profiles, [{local, [{relx, [{dev_mode, true},
Expand Down
Binary file modified rebar3
Binary file not shown.

0 comments on commit 9d6a11b

Please sign in to comment.