Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Sync with upstream rebar node template

  • Loading branch information...
commit 39aae44a3d437085b34a27703c748feeae7a6ec5 1 parent 3a8e071
Tuncer Ayaz tuncer authored
44 rel/files/install_upgrade.escript
View
@@ -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()])).
73 rel/files/yaws
View
@@ -50,6 +50,14 @@ if [ -z "$NAME_ARG" ]; then
exit 1
fi
+# Extract the name type and name from the NAME_ARG for REMSH
+REMSH_TYPE=`echo $NAME_ARG | awk '{print $1}'`
+REMSH_NAME=`echo $NAME_ARG | awk '{print $2}'`
+
+# Note the `date +%s`, used to allow multiple remsh to the same node transparently
+REMSH_NAME_ARG="$REMSH_TYPE remsh`date +%s`@`echo $REMSH_NAME | awk -F@ '{print $2}'`"
+REMSH_REMSH_ARG="-remsh $REMSH_NAME"
+
# Extract the target cookie
COOKIE_ARG=`grep '^-setcookie' $VMARGS_PATH`
if [ -z "$COOKIE_ARG" ]; then
@@ -63,6 +71,9 @@ ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
# Setup command to control the node
NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
+# Setup remote shell command to control node
+REMSH="$ERTS_PATH/erl $REMSH_NAME_ARG $REMSH_REMSH_ARG $COOKIE_ARG"
+
# Check the first argument for instructions
case "$1" in
start)
@@ -149,6 +160,41 @@ case "$1" in
exec $ERTS_PATH/to_erl $PIPE_DIR
;;
+ remote_console)
+ # Make sure a node IS running
+ RES=`$NODETOOL ping`
+ ES=$?
+ if [ "$ES" -ne 0 ]; then
+ echo "Node is not running!"
+ exit $ES
+ fi
+
+ shift
+ exec $REMSH
+ ;;
+
+ 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:
@@ -178,8 +224,33 @@ case "$1" in
exec $CMD -- ${1+"$@"}
;;
+ foreground)
+ # start up the release in the foreground for use by runit
+ # or other supervision services
+
+ BOOTFILE=$SCRIPT
+ FOREGROUNDOPTIONS="-noinput +Bd"
+
+ # Setup beam-required vars
+ ROOTDIR=$RUNNER_BASE_DIR
+ BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
+ EMU=beam
+ PROGNAME=`echo $0 | sed 's/.*\///'`
+ CMD="$BINDIR/erlexec $FOREGROUNDOPTIONS -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -config $CONFIG_PATH -args_file $VMARGS_PATH"
+ export EMU
+ export ROOTDIR
+ export BINDIR
+ export PROGNAME
+
+ # Dump environment info for logging purposes
+ echo "Exec: $CMD" -- ${1+"$@"}
+ echo "Root: $ROOTDIR"
+
+ # Start the VM
+ exec $CMD -- ${1+"$@"}
+ ;;
*)
- echo "Usage: $SCRIPT {start|stop|restart|reboot|ping|console|console_clean|attach}"
+ echo "Usage: $SCRIPT {start|foreground|stop|restart|reboot|ping|console|console_clean|attach|remote_console|upgrade}"
exit 1
;;
esac
3  rel/reltool.config
View
@@ -28,7 +28,7 @@
{excl_sys_filters, ["^bin/.*", "^erts.*/bin/(dialyzer|typer)",
"^erts.*/(doc|info|include|lib|man|src)"]},
{excl_app_filters, ["\.gitignore", "^include.mk.in"]},
- {app, yaws, [{mod_cond, app}, {incl_cond, include}, {lib_dir, ".."}]}
+ {app, yaws, [{mod_cond, app}, {incl_cond, include}, {lib_dir, ".."}]}
]}.
{target_dir, "yaws"}.
@@ -38,6 +38,7 @@
{copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"},
{copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"},
{copy, "files/yaws", "bin/yaws"},
+ {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"}
]}.
Please sign in to comment.
Something went wrong with that request. Please try again.