From 731bd1cadd38736fa90118178dbb64e618531cb4 Mon Sep 17 00:00:00 2001 From: Olivier Boudeville Date: Tue, 11 Aug 2020 14:07:07 +0200 Subject: [PATCH 1/7] First cookie fix: do not poll the VM if not having start/stop hooks to run. --- priv/templates/extended_bin | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index 9f8236ee3..6c09296f5 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -712,13 +712,15 @@ case "$1" in "$BINDIR/run_erl" -daemon "$PIPE_DIR" "$RUNNER_LOG_DIR" \ "exec \"$RELEASE_ROOT_DIR/bin/$REL_NAME\" \"$START_OPTION\" $ARGS --relx-disable-hooks" - # wait for node to be up before running hooks - while ! erl_rpc erlang is_alive > /dev/null 2>&1 - do - sleep 1 - done - - relx_run_hooks "$POST_START_HOOKS" + # Wait for node to be up before running any hooks + if [ -n "$POST_START_HOOKS" ]; then + while ! erl_rpc erlang is_alive > /dev/null 2>&1 + do + sleep 1 + done + + relx_run_hooks "$POST_START_HOOKS" + fi ;; stop) @@ -733,13 +735,15 @@ case "$1" in sleep 1 done - # wait for node to be down before running hooks - while erl_rpc erlang is_alive > /dev/null 2>&1 - do - sleep 1 - done + # Wait for node to be down before running any hooks + if [ -n "$POST_STOP_HOOKS" ]; then + while erl_rpc erlang is_alive > /dev/null 2>&1 + do + sleep 1 + done - relx_run_hooks "$POST_STOP_HOOKS" + relx_run_hooks "$POST_STOP_HOOKS" + fi ;; restart) From d1bca5e18c18f243f1f6dfd9e961cab4c48b1b0d Mon Sep 17 00:00:00 2001 From: Olivier Boudeville Date: Tue, 11 Aug 2020 14:12:43 +0200 Subject: [PATCH 2/7] Second cookie fix: accept any ERLX_OVERRIDE_COOKIE environment variable as a top level cookie source. --- priv/templates/extended_bin | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index 6c09296f5..c98ef1cb8 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -647,17 +647,21 @@ 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")" +if [ -n "$ERLX_OVERRIDE_COOKIE" ]; then + COOKIE="$ERLX_OVERRIDE_COOKIE" +else + 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 "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 - echo "No cookie is set or found. This limits the scripts functionality, installing, upgrading, rpc and getting a list of versions will not work." + # Extract cookie name from COOKIE_ARG + COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')" fi -else - # Extract cookie name from COOKIE_ARG - COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')" fi # User can specify an sname without @hostname From 155a9680c45549b43920ba8d6c0f4f60f73c6c1e Mon Sep 17 00:00:00 2001 From: Olivier Boudeville Date: Tue, 11 Aug 2020 15:30:17 +0200 Subject: [PATCH 3/7] No need to introduce ERLX_OVERRIDE_COOKIE, as the COOKIE variable is already taken into account. Yet it was shadowed if any -setcookie was set on the command-line, which is not the case anymore. --- priv/templates/extended_bin | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index c98ef1cb8..f3e1d82be 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -647,9 +647,7 @@ fi # Extract the target cookie # Do this before relx_get_nodename so we can use it and not create a ~/.erlang.cookie -if [ -n "$ERLX_OVERRIDE_COOKIE" ]; then - COOKIE="$ERLX_OVERRIDE_COOKIE" -else +if [ -z "$COOKIE" ]; then COOKIE_ARG="$(grep '^-setcookie' "$VMARGS_PATH" || true)" DEFAULT_COOKIE_FILE="$HOME/.erlang.cookie" if [ -z "$COOKIE_ARG" ]; then From 0be3b943dc0a7d12d75547edb09e93937bb34a69 Mon Sep 17 00:00:00 2001 From: Olivier Boudeville Date: Tue, 11 Aug 2020 21:32:35 +0200 Subject: [PATCH 4/7] Commit 731bd1cadd38736fa90118178dbb64e618531cb4 mostly reverted: apparently tests rely on return code and synchronicity (is_alive) even in the absence of relx hooks. --- priv/templates/extended_bin | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index f3e1d82be..3545583c4 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -715,15 +715,13 @@ case "$1" in "exec \"$RELEASE_ROOT_DIR/bin/$REL_NAME\" \"$START_OPTION\" $ARGS --relx-disable-hooks" # Wait for node to be up before running any hooks - if [ -n "$POST_START_HOOKS" ]; then - while ! erl_rpc erlang is_alive > /dev/null 2>&1 - do - sleep 1 - done - - relx_run_hooks "$POST_START_HOOKS" - fi - ;; + while ! erl_rpc erlang is_alive > /dev/null 2>&1 + do + sleep 1 + done + + relx_run_hooks "$POST_START_HOOKS" + ;; stop) relx_run_hooks "$PRE_STOP_HOOKS" @@ -738,14 +736,12 @@ case "$1" in done # Wait for node to be down before running any hooks - if [ -n "$POST_STOP_HOOKS" ]; then - while erl_rpc erlang is_alive > /dev/null 2>&1 - do - sleep 1 - done - - relx_run_hooks "$POST_STOP_HOOKS" - fi + while erl_rpc erlang is_alive > /dev/null 2>&1 + do + sleep 1 + done + + relx_run_hooks "$POST_STOP_HOOKS" ;; restart) From ad37eef266104872da726db27b4c729f68ffa4b1 Mon Sep 17 00:00:00 2001 From: Olivier Boudeville Date: Sun, 16 Aug 2020 18:46:00 +0200 Subject: [PATCH 5/7] Minimised differences with upstream. --- priv/templates/extended_bin | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index 3545583c4..8411e2273 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -714,14 +714,14 @@ case "$1" in "$BINDIR/run_erl" -daemon "$PIPE_DIR" "$RUNNER_LOG_DIR" \ "exec \"$RELEASE_ROOT_DIR/bin/$REL_NAME\" \"$START_OPTION\" $ARGS --relx-disable-hooks" - # Wait for node to be up before running any hooks - while ! erl_rpc erlang is_alive > /dev/null 2>&1 + # wait for node to be up before running hooks + while ! erl_rpc erlang is_alive > /dev/null 2>&1 do sleep 1 - done + done relx_run_hooks "$POST_START_HOOKS" - ;; + ;; stop) relx_run_hooks "$PRE_STOP_HOOKS" @@ -735,8 +735,8 @@ case "$1" in sleep 1 done - # Wait for node to be down before running any hooks - while erl_rpc erlang is_alive > /dev/null 2>&1 + # wait for node to be down before running hooks + while erl_rpc erlang is_alive > /dev/null 2>&1 do sleep 1 done From 21a75c22bef08dd0225701e68fe04ff0587f1869 Mon Sep 17 00:00:00 2001 From: Olivier Boudeville Date: Fri, 21 Aug 2020 16:41:06 +0200 Subject: [PATCH 6/7] ERLX_COOKIE preferred to COOKIE. --- priv/templates/extended_bin | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index 8411e2273..03a53251f 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -647,7 +647,9 @@ fi # Extract the target cookie # Do this before relx_get_nodename so we can use it and not create a ~/.erlang.cookie -if [ -z "$COOKIE" ]; then +if [ -n "$ERLX_COOKIE" ]; then + COOKIE="$ERLX_COOKIE" +else COOKIE_ARG="$(grep '^-setcookie' "$VMARGS_PATH" || true)" DEFAULT_COOKIE_FILE="$HOME/.erlang.cookie" if [ -z "$COOKIE_ARG" ]; then From 476fdc903c4dc4c674c683c86eded52d94a9a135 Mon Sep 17 00:00:00 2001 From: Olivier Boudeville Date: Fri, 21 Aug 2020 16:44:29 +0200 Subject: [PATCH 7/7] Managed to mispell RELX. --- priv/templates/extended_bin | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index 03a53251f..2945e3411 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -647,8 +647,8 @@ fi # Extract the target cookie # Do this before relx_get_nodename so we can use it and not create a ~/.erlang.cookie -if [ -n "$ERLX_COOKIE" ]; then - COOKIE="$ERLX_COOKIE" +if [ -n "$RELX_COOKIE" ]; then + COOKIE="$RELX_COOKIE" else COOKIE_ARG="$(grep '^-setcookie' "$VMARGS_PATH" || true)" DEFAULT_COOKIE_FILE="$HOME/.erlang.cookie"