aboutsummaryrefslogtreecommitdiffstats
path: root/priv/templates/extended_bin
diff options
context:
space:
mode:
Diffstat (limited to 'priv/templates/extended_bin')
-rwxr-xr-xpriv/templates/extended_bin94
1 files changed, 64 insertions, 30 deletions
diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin
index 059f5bf..a4cba4a 100755
--- a/priv/templates/extended_bin
+++ b/priv/templates/extended_bin
@@ -19,7 +19,7 @@ fi
# OSX does not support readlink '-f' flag, work
# around that
-case $OSTYPE in
+case $OSTYPE in
darwin*)
SCRIPT=$(readlink $0 || true)
;;
@@ -127,12 +127,10 @@ find_erts_dir() {
if [ -d "$__erts_dir" ]; then
ERTS_DIR="$__erts_dir";
ROOTDIR="$RELEASE_ROOT_DIR"
- # run a dummy distributed erlang node just to ensure that a cookie exists
- $ERTS_DIR/bin/erl -sname dummy -boot no_dot_erlang -noshell -eval "halt()"
else
__erl="$(which erl)"
code="io:format(\"~s\", [code:root_dir()]), halt()."
- __erl_root="$("$__erl" -sname dummy -boot no_dot_erlang -sasl errlog_type error -noshell -eval "$code")"
+ __erl_root="$("$__erl" -boot no_dot_erlang -sasl errlog_type error -noshell -eval "$code")"
ERTS_DIR="$__erl_root/erts-$ERTS_VSN"
ROOTDIR="$__erl_root"
fi
@@ -152,10 +150,19 @@ relx_get_pid() {
relx_get_nodename() {
id="longname$(relx_gen_id)-${NAME}"
- "$BINDIR/erl" -boot start_clean \
- -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
- -eval '[_,H]=re:split(atom_to_list(node()),"@",[unicode,{return,list}]), io:format("~s~n",[H]), halt()' \
- -noshell ${NAME_TYPE} $id
+ if [ -z "$COOKIE" ]; then
+ "$BINDIR/erl" -boot start_clean \
+ -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
+ -eval '[_,H]=re:split(atom_to_list(node()),"@",[unicode,{return,list}]), io:format("~s~n",[H]), halt()' \
+ -noshell ${NAME_TYPE} $id
+ else
+ # running with setcookie prevents a ~/.erlang.cookie from being created
+ "$BINDIR/erl" -boot start_clean \
+ -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
+ -eval '[_,H]=re:split(atom_to_list(node()),"@",[unicode,{return,list}]), io:format("~s~n",[H]), halt()' \
+ -setcookie ${COOKIE} \
+ -noshell ${NAME_TYPE} $id
+ fi
}
# Connect to a remote node
@@ -169,7 +176,7 @@ relx_rem_sh() {
# Setup remote shell command to control node
exec "$BINDIR/erl" "$NAME_TYPE" "$id" -remsh "$NAME" -boot start_clean \
- -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
+ -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" $MAYBE_DIST_ARGS \
-setcookie "$COOKIE" -hidden -kernel net_ticktime $TICKTIME
}
@@ -182,8 +189,22 @@ relx_gen_id() {
relx_nodetool() {
command="$1"; shift
- "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \
- -setcookie "$COOKIE" "$command" $@
+ # Generate a unique id used to allow multiple nodetool calls to the
+ # same node transparently
+ nodetool_id="maint$(relx_gen_id)-${NAME}"
+
+ if [ -z "${START_EPMD}" ]; then
+ ERL_FLAGS="${ERL_FLAGS} ${MAYBE_DIST_ARGS} ${NAME_TYPE} $nodetool_id -setcookie ${COOKIE}" \
+ "$ERTS_DIR/bin/escript" \
+ "$ROOTDIR/bin/nodetool" \
+ "$NAME_TYPE" "$NAME" \
+ "$command" $@
+ else
+ ERL_FLAGS="${ERL_FLAGS} ${MAYBE_DIST_ARGS} ${NAME_TYPE} $nodetool_id -setcookie ${COOKIE}" \
+ "$ERTS_DIR/bin/escript" \
+ "$ROOTDIR/bin/nodetool" \
+ $START_EPMD "$NAME_TYPE" "$NAME" "$command" $@
+ fi
}
# Run an escript in the node's environment
@@ -310,10 +331,10 @@ relx_is_extension() {
EXTENSION=$1
case "$EXTENSION" in
{{{ extensions }}})
- echo "1"
+ echo "1"
;;
*)
- echo "0"
+ echo "0"
;;
esac
}
@@ -324,7 +345,7 @@ relx_get_extension_script() {
# of the form:
# foo_extension="path/to/foo_script";bar_extension="path/to/bar_script"
{{{extension_declarations}}}
- # get the command extension (eg. foo) and
+ # get the command extension (eg. foo) and
# obtain the actual script filename that it
# refers to (eg. "path/to/foo_script"
eval echo "$"${EXTENSION}_extension""
@@ -447,36 +468,49 @@ NAME_ARG=$(eval echo "${NAME_ARG}")
NAME_TYPE="$(echo "$NAME_ARG" | awk '{print $1}')"
NAME="$(echo "$NAME_ARG" | awk '{print $2}')"
-# User can specify an sname without @hostname
-# This will fail when creating remote shell
-# So here we check for @ and add @hostname if missing
-case "${NAME}" in
- *@*) ;; # Nothing to do
- *) NAME=${NAME}@$(relx_get_nodename);; # Add @hostname
-esac
-
-# Export the variable so that it's available in the 'eval' calls
-export NAME
-
-test -z "$PIPE_DIR" && PIPE_BASE_DIR='/tmp/erl_pipes/'
-PIPE_DIR="${PIPE_DIR:-/tmp/erl_pipes/$NAME/}"
+# Extract dist arguments
+MAYBE_DIST_ARGS=""
+PROTO_DIST="$(grep '^-proto_dist' "$VMARGS_PATH" || true)"
+if [ "$PROTO_DIST" ]; then
+ MAYBE_DIST_ARGS="${PROTO_DIST}"
+fi
+START_EPMD="$(grep '^-start_epmd' "$VMARGS_PATH" || true)"
+if [ "$START_EPMD" ]; then
+ MAYBE_DIST_ARGS="${MAYBE_DIST_ARGS} ${START_EPMD}"
+fi
+EPMD_MODULE="$(grep '^-epmd_module' "$VMARGS_PATH" || true)"
+if [ "$EPMD_MODULE" ]; then
+ MAYBE_DIST_ARGS="${MAYBE_DIST_ARGS} ${EPMD_MODULE}"
+fi
# Extract the target cookie
+# Do this before relx_get_nodename so we can use it and not create a ~/.erlang.cookie
COOKIE_ARG="$(grep '^-setcookie' "$VMARGS_PATH" || true)"
DEFAULT_COOKIE_FILE="$HOME/.erlang.cookie"
if [ -z "$COOKIE_ARG" ]; then
if [ -f "$DEFAULT_COOKIE_FILE" ]; then
COOKIE="$(cat $DEFAULT_COOKIE_FILE)"
else
- echo "vm.args needs to have a -setcookie, or $DEFAULT_COOKIE_FILE (its permission must be 400) is required."
- exit 1
+ echo "No cookie is set or found. This limits the scripts functionality, installing, upgrading, rpc and getting a list of versions will not work."
fi
else
# Extract cookie name from COOKIE_ARG
COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')"
fi
-VM_ARGS="$(grep -v -E '^#|^-name|^-sname|^-setcookie|^-heart|^-args_file' "$VMARGS_PATH" | xargs | sed -e 's/ / /g')"
+# User can specify an sname without @hostname
+# This will fail when creating remote shell
+# So here we check for @ and add @hostname if missing
+case "${NAME}" in
+ *@*) ;; # Nothing to do
+ *) NAME=${NAME}@$(relx_get_nodename);; # Add @hostname
+esac
+
+# Export the variable so that it's available in the 'eval' calls
+export NAME
+
+test -z "$PIPE_DIR" && PIPE_BASE_DIR='/tmp/erl_pipes/'
+PIPE_DIR="${PIPE_DIR:-/tmp/erl_pipes/$NAME/}"
cd "$ROOTDIR"