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
This commit is contained in:
Matt Campbell 2012-01-09 16:37:44 -06:00 committed by Tuncer Ayaz
parent 9c1a877bbe
commit 6f85854414
5 changed files with 102 additions and 6 deletions

View file

@ -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()])).

View file

@ -34,8 +34,9 @@
{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/install_upgrade.escript", "bin/install_upgrade.escript"},
{copy, "files/sys.config", "releases/\{\{rel_vsn\}\}/sys.config"},
{copy, "files/vm.args", "releases/\{\{rel_vsn\}\}/vm.args"} {copy, "files/vm.args", "releases/\{\{rel_vsn\}\}/vm.args"}
]}. ]}.

View file

@ -149,6 +149,28 @@ case "$1" in
exec $ERTS_PATH/to_erl $PIPE_DIR exec $ERTS_PATH/to_erl $PIPE_DIR
;; ;;
upgrade)
if [ -z "$2" ]; then
echo "Missing upgrade package argument"
echo "Usage: $SCRIPT upgrade {package base name}"
echo "NOTE {package base name} MUST NOT include the .tar.gz suffix"
exit 1
fi
# Make sure a node IS running
RES=`$NODETOOL ping`
ES=$?
if [ "$ES" -ne 0 ]; then
echo "Node is not running!"
exit $ES
fi
node_name=`echo $NAME_ARG | awk '{print $2}'`
erlang_cookie=`echo $COOKIE_ARG | awk '{print $2}'`
$ERTS_PATH/escript $RUNNER_BASE_DIR/bin/install_upgrade.escript $node_name $erlang_cookie $2
;;
console|console_clean) console|console_clean)
# .boot file typically just $SCRIPT (ie, the app name) # .boot file typically just $SCRIPT (ie, the app name)
# however, for debugging, sometimes start_clean.boot is useful: # however, for debugging, sometimes start_clean.boot is useful:
@ -204,7 +226,7 @@ case "$1" in
exec $CMD -- ${1+"$@"} exec $CMD -- ${1+"$@"}
;; ;;
*) *)
echo "Usage: $SCRIPT {start|foreground|stop|restart|reboot|ping|console|console_clean|attach}" echo "Usage: $SCRIPT {start|foreground|stop|restart|reboot|ping|console|console_clean|attach|upgrade}"
exit 1 exit 1
;; ;;
esac esac

View file

@ -10,3 +10,4 @@
{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"}.
{file, "simplenode.install_upgrade.escript", "files/install_upgrade.escript"}.

View file

@ -2,7 +2,7 @@
@set node_name={{nodeid}} @set node_name={{nodeid}}
@rem Get the abolute path to the parent directory, @rem Get the absolute path to the parent directory,
@rem which is assumed to be the node root. @rem which is assumed to be the node root.
@for /F "delims=" %%I in ("%~dp0..") do @set node_root=%%~fI @for /F "delims=" %%I in ("%~dp0..") do @set node_root=%%~fI
@ -14,20 +14,28 @@
@call :set_trim release_version %%J @call :set_trim release_version %%J
) )
@rem extract erlang cookie from vm.args
@set vm_args=%releases_dir%\%release_version%\vm.args
@for /f "usebackq tokens=1-2" %%I in (`findstr /b \-setcookie %vm_args%`) do @set erlang_cookie=%%J
@set erts_bin=%node_root%\erts-%erts_version%\bin @set erts_bin=%node_root%\erts-%erts_version%\bin
@set service_name=%node_name%_%release_version% @set service_name=%node_name%_%release_version%
@if "%1"=="usage" @goto usage
@if "%1"=="install" @goto install @if "%1"=="install" @goto install
@if "%1"=="uninstall" @goto uninstall @if "%1"=="uninstall" @goto uninstall
@if "%1"=="start" @goto start @if "%1"=="start" @goto start
@if "%1"=="stop" @goto stop @if "%1"=="stop" @goto stop
@if "%1"=="restart" @call :stop && @goto start @if "%1"=="restart" @call :stop && @goto start
@if "%1"=="console" @goto console @if "%1"=="console" @goto console
@rem TODO: attach, ping, restart and reboot @if "%1"=="query" @goto query
@if "%1"=="attach" @goto attach
@if "%1"=="upgrade" @goto upgrade
@echo Unknown command: "%1"
:usage :usage
@echo Usage: %0 {install|uninstall|start|stop|restart|console} @echo Usage: %~n0 {install,uninstall,start,stop,restart,console,query,attach,upgrade}
@goto :EOF @goto :EOF
:install :install
@ -48,7 +56,27 @@
@goto :EOF @goto :EOF
:console :console
@start %erts_bin%\werl.exe -boot %releases_dir%\%release_version%\%node_name% @start %erts_bin%\werl.exe -boot %releases_dir%\%release_version%\%node_name% -config %releases_dir%\%release_version%\sys.config -args_file %vm_args% -sname %node_name%
@goto :EOF
:query
@%erts_bin%\erlsrv.exe list %service_name%
@exit /b %ERRORLEVEL%
@goto :EOF
:attach
@for /f "usebackq" %%I in (`hostname`) do @set hostname=%%I
start %erts_bin%\werl.exe -boot %releases_dir%\%release_version%\start_clean -remsh %node_name%@%hostname% -sname console -setcookie %erlang_cookie%
@goto :EOF
:upgrade
@if "%2"=="" (
@echo Missing upgrade package argument
@echo Usage: %~n0 upgrade {package base name}
@echo NOTE {package base name} MUST NOT include the .tar.gz suffix
@goto :EOF
)
@%erts_bin%\escript.exe %node_root%\bin\install_upgrade.escript %node_name% %erlang_cookie% %2
@goto :EOF @goto :EOF
:set_trim :set_trim