Debian Codegraph @

priv/templates/simplenode.install_upgrade.escript

raw
1 #!/usr/bin/env escript
2 %%! -noshell -noinput
3 %% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
4 %% ex: ft=erlang ts=4 sw=4 et
5 %% This file is left for backward-compatibility.
6 %% You, probably, shouldn't include it to new projects.
7
8
9 main([NodeName, Cookie, ReleasePackage]) ->
10 io:format("WARNING: 'install_upgrade.escript' is deprecated! "
11 "Use 'nodetool upgrade' instead.~n"),
12 NodeRoot = filename:dirname(filename:dirname(escript:script_name())),
13 NodeTool = which_nodetool(NodeRoot),
14 process_flag(trap_exit, true),
15 Port = erlang:open_port(
16 {spawn_executable, NodeTool},
17 [{args, ["-sname", NodeName,
18 "-setcookie", Cookie,
19 "upgrade", ReleasePackage]},
20 binary, exit_status, use_stdio, stderr_to_stdout, hide]),
21 port_loop(Port);
22 main(_) ->
23 halt(1).
24
25
26 which_nodetool(NodeRoot) ->
27 %% ${RELEASE_ROOT}/
28 %% bin/install_upgrade.escript
29 %% bin/nodetool ?
30 %% erts-<erts_ver>/bin/nodetool ?
31 %% releases/<app_ver>/nodetool ?
32 %% releases/start_erl.data
33 {ok, Content} = file:read_file(filename:join([NodeRoot, "releases", "start_erl.data"])),
34 [ErtsVsn, AppVsn] = binary:split(Content, <<" ">>),
35 Probes = [
36 filename:join([NodeRoot, "bin", "nodetool"]),
37 filename:join([NodeRoot, <<"erts-", ErtsVsn/binary>>, "bin", "nodetool"]),
38 filename:join([NodeRoot, "releases", AppVsn, "bin", "nodetool"])
39 ],
40 case lists:dropwhile(fun(Path) -> not filelib:is_regular(Path) end, Probes) of
41 [] ->
42 io:format("ERROR: can't find 'nodetool' in ~p.~n", [Probes]),
43 halt(2);
44 [Path | _] ->
45 Path
46 end.
47
48 port_loop(Port) ->
49 receive
50 {Port, {data, Data}} ->
51 io:put_chars(Data),
52 port_loop(Port);
53 {Port, {exit_status, Status}} ->
54 halt(Status)
55 end.