diff options
author | Matt Campbell <matthew.campbell@asolutions.com> | 2012-01-09 16:37:44 -0600 |
---|---|---|
committer | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2012-04-17 19:56:41 +0200 |
commit | 6f85854414a51a7ea8ce85f2fb68b77d7d381098 (patch) | |
tree | da95fd3389a149405c1e1769776b6ec10199de1b /priv/templates/simplenode.install_upgrade.escript | |
parent | 9c1a877bbe514afe20ac3264b87f0764ffb8b243 (diff) |
Improvements to windows node runner script
* Typos and other minor bug fixes
* Add "attach" command (via -remsh)
* Add "upgrade" command to install a hot upgrade package
* Add "upgrade" subcommand to UNIX runner script as well
Diffstat (limited to 'priv/templates/simplenode.install_upgrade.escript')
-rw-r--r-- | priv/templates/simplenode.install_upgrade.escript | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/priv/templates/simplenode.install_upgrade.escript b/priv/templates/simplenode.install_upgrade.escript new file mode 100644 index 0000000..56cea19 --- /dev/null +++ b/priv/templates/simplenode.install_upgrade.escript @@ -0,0 +1,44 @@ +#!/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()])). |