summaryrefslogtreecommitdiff
path: root/priv/templates
diff options
context:
space:
mode:
authorMatt Campbell <matthew.campbell@asolutions.com>2012-01-09 16:37:44 -0600
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2012-04-17 19:56:41 +0200
commit6f85854414a51a7ea8ce85f2fb68b77d7d381098 (patch)
treeda95fd3389a149405c1e1769776b6ec10199de1b /priv/templates
parent9c1a877bbe514afe20ac3264b87f0764ffb8b243 (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')
-rw-r--r--priv/templates/simplenode.install_upgrade.escript44
-rw-r--r--priv/templates/simplenode.reltool.config3
-rwxr-xr-xpriv/templates/simplenode.runner24
-rw-r--r--priv/templates/simplenode.template1
-rw-r--r--priv/templates/simplenode.windows.runner.cmd36
5 files changed, 102 insertions, 6 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()])).
diff --git a/priv/templates/simplenode.reltool.config b/priv/templates/simplenode.reltool.config
index c03d4f1..932b148 100644
--- a/priv/templates/simplenode.reltool.config
+++ b/priv/templates/simplenode.reltool.config
@@ -34,8 +34,9 @@
{copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"},
{copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"},
{copy, "files/{{nodeid}}", "bin/{{nodeid}}"},
- {copy, "files/sys.config", "releases/\{\{rel_vsn\}\}/sys.config"},
{copy, "files/{{nodeid}}.cmd", "bin/{{nodeid}}.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"}
]}.
diff --git a/priv/templates/simplenode.runner b/priv/templates/simplenode.runner
index f6d3f6c..be1cc8f 100755
--- a/priv/templates/simplenode.runner
+++ b/priv/templates/simplenode.runner
@@ -149,6 +149,28 @@ case "$1" in
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)
# .boot file typically just $SCRIPT (ie, the app name)
# however, for debugging, sometimes start_clean.boot is useful:
@@ -204,7 +226,7 @@ case "$1" in
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
;;
esac
diff --git a/priv/templates/simplenode.template b/priv/templates/simplenode.template
index d074681..5d2c49d 100644
--- a/priv/templates/simplenode.template
+++ b/priv/templates/simplenode.template
@@ -10,3 +10,4 @@
{template, "simplenode.vm.args", "files/vm.args"}.
{template, "simplenode.windows.runner.cmd", "files/{{nodeid}}.cmd"}.
{file, "simplenode.windows.start_erl.cmd", "files/start_erl.cmd"}.
+{file, "simplenode.install_upgrade.escript", "files/install_upgrade.escript"}.
diff --git a/priv/templates/simplenode.windows.runner.cmd b/priv/templates/simplenode.windows.runner.cmd
index b9c5824..ef9765d 100644
--- a/priv/templates/simplenode.windows.runner.cmd
+++ b/priv/templates/simplenode.windows.runner.cmd
@@ -2,7 +2,7 @@
@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.
@for /F "delims=" %%I in ("%~dp0..") do @set node_root=%%~fI
@@ -14,20 +14,28 @@
@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 service_name=%node_name%_%release_version%
+@if "%1"=="usage" @goto usage
@if "%1"=="install" @goto install
@if "%1"=="uninstall" @goto uninstall
@if "%1"=="start" @goto start
@if "%1"=="stop" @goto stop
@if "%1"=="restart" @call :stop && @goto start
@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
-@echo Usage: %0 {install|uninstall|start|stop|restart|console}
+@echo Usage: %~n0 {install,uninstall,start,stop,restart,console,query,attach,upgrade}
@goto :EOF
:install
@@ -48,7 +56,27 @@
@goto :EOF
: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
:set_trim