Skip to content

Commit

Permalink
add install upgrade script used by extended start script
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan Sloughter committed Sep 11, 2013
1 parent 8c3d691 commit 416d107
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions src/rlx_prv_assembler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,13 @@ include_erts(State, Release, OutputDir, RelDir) ->
ok = ec_file:copy(filename:join([Prefix, "bin", "start_clean.boot"]),
filename:join([OutputDir, "bin", "start_clean.boot"])),
NodeToolFile = nodetool_contents(),
InstallUpgradeFile = install_upgrade_escript_contents(),
NodeTool = filename:join([LocalErts, "bin", "nodetool"]),
InstallUpgrade = filename:join([LocalErts, "bin", "install_upgrade.escript"]),
ok = file:write_file(NodeTool, NodeToolFile),
ok = file:change_mode(NodeTool, 8#755);
ok = file:write_file(InstallUpgrade, InstallUpgradeFile),
ok = file:change_mode(NodeTool, 8#755),
ok = file:change_mode(InstallUpgrade, 8#755);
false ->
ok
end,
Expand Down Expand Up @@ -839,7 +843,7 @@ case \"$1\" in
node_name=`echo $NAME_ARG | awk '{print $2}'`
erlang_cookie=`echo $COOKIE_ARG | awk '{print $2}'`
$ERTS_DIR/bin/escript $SCRIPT_DIR/bin/install_upgrade.escript $node_name $erlang_cookie $2
$ERTS_DIR/bin/escript $SCRIPT_DIR/install_upgrade.escript $node_name $erlang_cookie $2
;;
console|console_clean|console_boot)
Expand Down Expand Up @@ -910,6 +914,53 @@ esac
exit 0">>].

install_upgrade_escript_contents() ->
[<<"#!/usr/bin/env escript
%%! -noshell -noinput
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
-define(TIMEOUT, 60000).
-define(INFO(Fmt,Args), io:format(Fmt,Args)).
main([NodeName, Cookie, ReleasePackage]) ->
TargetNode = start_distribution(NodeName, Cookie),
{ok, Vsn} = rpc:call(TargetNode, release_handler, unpack_release,
[ReleasePackage], ?TIMEOUT),
?INFO(\"Unpacked Release ~p~n\", [Vsn]),
{ok, OtherVsn, Desc} = rpc:call(TargetNode, release_handler,
check_install_release, [Vsn], ?TIMEOUT),
{ok, OtherVsn, Desc} = rpc:call(TargetNode, release_handler,
install_release, [Vsn], ?TIMEOUT),
?INFO(\"Installed Release ~p~n\", [Vsn]),
ok = rpc:call(TargetNode, release_handler, make_permanent, [Vsn], ?TIMEOUT),
?INFO(\"Made Release ~p Permanent~n\", [Vsn]);
main(_) ->
init:stop(1).
start_distribution(NodeName, Cookie) ->
MyNode = make_script_node(NodeName),
{ok, _Pid} = net_kernel:start([MyNode, shortnames]),
erlang:set_cookie(node(), list_to_atom(Cookie)),
TargetNode = make_target_node(NodeName),
case {net_kernel:hidden_connect_node(TargetNode),
net_adm:ping(TargetNode)} of
{true, pong} ->
ok;
{_, pang} ->
io:format(\"Node ~p not responding to pings.\n\", [TargetNode]),
init:stop(1)
end,
TargetNode.
make_target_node(Node) ->
[_, Host] = string:tokens(atom_to_list(node()), \"@\"),
list_to_atom(lists:concat([Node, \"@\", Host])).
make_script_node(Node) ->
list_to_atom(lists:concat([Node, \"_upgrader_\", os:getpid()])).
">>].

nodetool_contents() ->
[<<"%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
Expand Down

0 comments on commit 416d107

Please sign in to comment.