aboutsummaryrefslogtreecommitdiffstats
path: root/priv/templates/extended_bin
diff options
context:
space:
mode:
authorTino Breddin <[email protected]>2019-04-05 22:30:22 +0200
committerTristan Sloughter <[email protected]>2019-04-05 14:30:22 -0600
commit2a4ff9a61f50adce4c86b5414bf81e29bc013160 (patch)
treec1693035becacbc2bdc36fa48ef5f6d233d5ed1a /priv/templates/extended_bin
parent33ac6064760e6b78e6d4a9b67efc1a5b0d69e3e8 (diff)
downloadrelx-2a4ff9a61f50adce4c86b5414bf81e29bc013160.tar.gz
relx-2a4ff9a61f50adce4c86b5414bf81e29bc013160.tar.bz2
relx-2a4ff9a61f50adce4c86b5414bf81e29bc013160.zip
Refactor creation of .erlang.cookie for use in start/console procedures (#690)
* Randomize dummy node name The static name used so far would result in name clashing when running the script multiple times in short succession. * Fix find_sys_config routine in win32 extended bin * Remove escaping of double quotes * Fix dummy command syntax * Refactor creation of .erlang.cookie at startup * Fix dummy node logic for win32
Diffstat (limited to 'priv/templates/extended_bin')
-rwxr-xr-xpriv/templates/extended_bin27
1 files changed, 20 insertions, 7 deletions
diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin
index 059f5bf..fde6729 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,17 +127,26 @@ 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
}
+ensure_dot_erlang_cookie() {
+ # Run a dummy distributed erlang node just to ensure that $HOME/.erlang.cookie exists.
+ # This action is best-effort and could fail because of the way the system is set up.
+ # Failures are logged, but ignored.
+ DUMMY_NAME="dummy-$(relx_gen_id)"
+ if ! output="$($ERTS_DIR/bin/erl -sname ${DUMMY_NAME} -boot no_dot_erlang -noshell -eval "halt()")"
+ then
+ echo "Creating .erlang.cookie failed: ${output}"
+ fi
+}
+
# Get node pid
relx_get_pid() {
if output="$(relx_nodetool rpcterms os getpid)"
@@ -310,10 +319,10 @@ relx_is_extension() {
EXTENSION=$1
case "$EXTENSION" in
{{{ extensions }}})
- echo "1"
+ echo "1"
;;
*)
- echo "0"
+ echo "0"
;;
esac
}
@@ -324,7 +333,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""
@@ -512,6 +521,8 @@ case "$1" in
# Make sure log directory exists
mkdir -p "$RUNNER_LOG_DIR"
+ ensure_dot_erlang_cookie
+
relx_run_hooks "$PRE_START_HOOKS"
"$BINDIR/run_erl" -daemon "$PIPE_DIR" "$RUNNER_LOG_DIR" \
"exec \"$RELEASE_ROOT_DIR/bin/$REL_NAME\" \"$START_OPTION\" $ARGS --relx-disable-hooks"
@@ -682,6 +693,8 @@ case "$1" in
-pa ${__code_paths} -- "$@"
echo "Root: $ROOTDIR"
+ ensure_dot_erlang_cookie
+
# Log the startup
echo "$RELEASE_ROOT_DIR"
logger -t "$REL_NAME[$$]" "Starting up"