From d78af6a84362d828756d6916b84812c0d9429b83 Mon Sep 17 00:00:00 2001 From: Luis Rascao Date: Wed, 8 Aug 2018 00:51:49 +0100 Subject: Check for pipe write permission on start/attach A common pitfall when starting up Erlang nodes is to start them as root and then fail silently when switching to another user, improve this by providing a helpful error message when this happens. --- priv/templates/extended_bin | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index 11a0abc..78f25e0 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -492,6 +492,11 @@ case "$1" in test -z "$PIPE_BASE_DIR" || mkdir -m 1777 -p "$PIPE_BASE_DIR" mkdir -p "$PIPE_DIR" + if [ ! -w "$PIPE_DIR" ] + then + echo "failed to start, user '$USER' does not have write privileges on '$PIPE_DIR', either delete it or run node as a different user" + exit 1 + fi relx_run_hooks "$PRE_START_HOOKS" "$BINDIR/run_erl" -daemon "$PIPE_DIR" "$RUNNER_LOG_DIR" \ @@ -555,6 +560,12 @@ case "$1" in exit 1 fi + if [ ! -w "$PIPE_DIR" ] + then + echo "failed to attach, user '$USER' does not have sufficient privileges on '$PIPE_DIR', please run node as a different user" + exit 1 + fi + shift exec "$BINDIR/to_erl" "$PIPE_DIR" ;; -- cgit v1.2.3 From d12106901342491ad24252b976dc36ac95fa57c1 Mon Sep 17 00:00:00 2001 From: shamis Date: Wed, 19 Sep 2018 07:50:24 +0000 Subject: using %hostname% in service install --- priv/templates/extended_bin_windows | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'priv') diff --git a/priv/templates/extended_bin_windows b/priv/templates/extended_bin_windows index d30d78d..00ecf9b 100644 --- a/priv/templates/extended_bin_windows +++ b/priv/templates/extended_bin_windows @@ -183,10 +183,10 @@ :install set args=%erl_opts% -setcookie %cookie% ++ -rootdir \"%rootdir%\" set start_erl=%erts_dir%\bin\start_erl.exe -set description=Erlang node %node_name% in %rootdir% +set description=Erlang node %node_name%%hostname% in %rootdir% @if "" == "%2" ( :: Install the service - %erlsrv% add %service_name% %node_type% "%node_name%" -c "%description%" -w "%rootdir%" -m "%start_erl%" -args "%args%" -stopaction "init:stop()." + %erlsrv% add %service_name% %node_type% "%node_name%%hostname%" -c "%description%" -w "%rootdir%" -m "%start_erl%" -args "%args%" -stopaction "init:stop()." ) else ( :: relup and reldown goto relup -- cgit v1.2.3 From 3d82071245e1c658eef0e70bae297a574c07e6d9 Mon Sep 17 00:00:00 2001 From: Luis Rascao Date: Thu, 9 Aug 2018 00:25:59 +0100 Subject: Capture internal start script arguments --- priv/templates/extended_bin | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index 78f25e0..57f4cac 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -312,6 +312,16 @@ relx_run_hooks() { done } +relx_disable_hooks() { + PRE_START_HOOKS="" + POST_START_HOOKS="" + PRE_STOP_HOOKS="" + POST_STOP_HOOKS="" + PRE_INSTALL_UPGRADE_HOOKS="" + POST_INSTALL_UPGRADE_HOOKS="" + STATUS_HOOK="" +} + relx_is_extension() { EXTENSION=$1 case "$EXTENSION" in @@ -346,6 +356,26 @@ relx_run_extension() { [ "$SCRIPT_DIR/$EXTENSION_SCRIPT" ] && . "$SCRIPT_DIR/$EXTENSION_SCRIPT" $@ } +# given a list of arguments, identify the internal ones +# --relx-disable-hooks +# and process them accordingly +process_internal_args() { + for arg in $@ + do + shift + case "$arg" in + --relx-disable-hooks) + relx_disable_hooks + ;; + *) + ;; + esac + done +} + +# process internal arguments +process_internal_args $@ + find_erts_dir export ROOTDIR="$RELEASE_ROOT_DIR" export BINDIR="$ERTS_DIR/bin" -- cgit v1.2.3 From e9a8b13668ca3dd1470b8b65320e1491c213c521 Mon Sep 17 00:00:00 2001 From: Luis Rascao Date: Thu, 9 Aug 2018 00:26:31 +0100 Subject: Prevent double hook invocation on 'start' command --- priv/templates/extended_bin | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index 57f4cac..a06c2c3 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -530,7 +530,7 @@ case "$1" in 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" + "exec \"$RELEASE_ROOT_DIR/bin/$REL_NAME\" \"$START_OPTION\" --relx-disable-hooks $ARGS" relx_run_hooks "$POST_START_HOOKS" ;; @@ -705,6 +705,7 @@ case "$1" in echo "$RELEASE_ROOT_DIR" logger -t "$REL_NAME[$$]" "Starting up" + relx_run_hooks "$PRE_START_HOOKS" # Start the VM exec "$BINDIR/erlexec" $FOREGROUNDOPTIONS \ -boot "$BOOTFILE" -mode "$CODE_LOADING_MODE" \ @@ -712,6 +713,9 @@ case "$1" in -config "$RELX_CONFIG_PATH" \ -args_file "$VMARGS_PATH" \ -pa ${__code_paths} -- "$@" + # exec will replace the current image and nothing else gets + # executed from this point on, this explains the absence + # of the pre start hook ;; rpc) # Make sure a node IS running -- cgit v1.2.3 From 23a708b7fdfee85635cb9e1650bc400e93d19514 Mon Sep 17 00:00:00 2001 From: slepher Date: Tue, 30 Oct 2018 15:23:16 +0800 Subject: fix --relx-disable-hooks cause start_boot start fail --- priv/templates/extended_bin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index a06c2c3..6c012b2 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -530,7 +530,7 @@ case "$1" in relx_run_hooks "$PRE_START_HOOKS" "$BINDIR/run_erl" -daemon "$PIPE_DIR" "$RUNNER_LOG_DIR" \ - "exec \"$RELEASE_ROOT_DIR/bin/$REL_NAME\" \"$START_OPTION\" --relx-disable-hooks $ARGS" + "exec \"$RELEASE_ROOT_DIR/bin/$REL_NAME\" \"$START_OPTION\" $ARGS --relx-disable-hooks" relx_run_hooks "$POST_START_HOOKS" ;; -- cgit v1.2.3 From 387033d01f9b3c105829dad284f3d520c2590826 Mon Sep 17 00:00:00 2001 From: eldarko Date: Fri, 16 Nov 2018 15:30:57 +0100 Subject: Don't write to release bin/ directory Let the user provide writable $ROOTDIR/tmp so it can be used for temporary files --- priv/templates/extended_bin | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index a06c2c3..a228413 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -180,9 +180,9 @@ relx_gen_id() { relx_nodetool() { command="$1"; shift - escript_emulator_args $ROOTDIR/bin/nodetool + ESCRIPT_TMP=$(escript_emulator_args_tmp $ROOTDIR/bin/nodetool) - "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \ + "$ERTS_DIR/bin/escript" "$ESCRIPT_TMP" "$NAME_TYPE" "$NAME" \ -setcookie "$COOKIE" "$command" $@ } @@ -248,6 +248,24 @@ escript_emulator_args() { fi } +escript_emulator_args_tmp() { + # + # If the user provided $ROOTDIR/tmp directory then don't override + # original files of the package but use temporary files instead + # + local TMP_DIR="$ROOTDIR/tmp"; + + if [ -d "$TMP_DIR" ] && [ -w "$TMP_DIR" ]; then + local TMP_FILE="$TMP_DIR/$(basename $1)" + cp $1 $TMP_FILE + escript_emulator_args $TMP_FILE + echo $TMP_FILE + else + escript_emulator_args $1 + echo $1 + fi +} + add_path() { # Use $CWD/$1 if exists, otherwise releases/VSN/$1 IN_FILE_PATH=$2 @@ -628,9 +646,9 @@ case "$1" in relx_run_hooks "$PRE_INSTALL_UPGRADE_HOOKS" - escript_emulator_args $ROOTDIR/bin/install_upgrade.escript + ESCRIPT_TMP=$(escript_emulator_args_tmp $ROOTDIR/bin/install_upgrade.escript) - exec "$BINDIR/escript" "$ROOTDIR/bin/install_upgrade.escript" \ + exec "$BINDIR/escript" "$ESCRIPT_TMP" \ "$COMMAND" "{'$REL_NAME', \"$NAME_TYPE\", '$NAME', '$COOKIE'}" "$@" relx_run_hooks "$POST_INSTALL_UPGRADE_HOOKS" @@ -645,9 +663,9 @@ case "$1" in COMMAND="$1"; shift - escript_emulator_args $ROOTDIR/bin/install_upgrade.escript + ESCRIPT_TMP=$(escript_emulator_args_tmp $ROOTDIR/bin/install_upgrade.escript) - exec "$BINDIR/escript" "$ROOTDIR/bin/install_upgrade.escript" \ + exec "$BINDIR/escript" "$ESCRIPT_TMP" \ "versions" "{'$REL_NAME', \"$NAME_TYPE\", '$NAME', '$COOKIE'}" "$@" ;; -- cgit v1.2.3 From 5a5e2c66969f0377328d1d1db9f359c43ec9e903 Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Tue, 27 Nov 2018 18:55:14 +0100 Subject: run named erl nodes to auto-set cookie --- priv/templates/extended_bin | 4 +++- priv/templates/extended_bin_windows | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index 78f25e0..854cf6a 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -127,10 +127,12 @@ 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" -boot no_dot_erlang -sasl errlog_type error -noshell -eval "$code")" + __erl_root="$("$__erl" -sname dummy -boot no_dot_erlang -sasl errlog_type error -noshell -eval "$code")" ERTS_DIR="$__erl_root/erts-$ERTS_VSN" ROOTDIR="$__erl_root" fi diff --git a/priv/templates/extended_bin_windows b/priv/templates/extended_bin_windows index 00ecf9b..045a80c 100644 --- a/priv/templates/extended_bin_windows +++ b/priv/templates/extended_bin_windows @@ -137,7 +137,7 @@ @for /f "delims=" %%i in ('where erl') do @( set erl=%%i ) -@set dir_cmd="%erl%" -boot no_dot_erlang -noshell -eval "io:format(\"~s\", [filename:nativename(code:root_dir())])." -s init stop +@set dir_cmd="%erl%" -sname dummy -boot no_dot_erlang -noshell -eval "io:format(\"~s\", [filename:nativename(code:root_dir())])." -s init stop @for /f "delims=" %%i in ('%%dir_cmd%%') do @( set erl_root=%%i ) -- cgit v1.2.3 From 41284ccc88e89f576309698f1a3691c5e8942b2e Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Wed, 16 Jan 2019 22:08:27 +0000 Subject: Enable passing arguments with spaces to extensions --- priv/templates/extended_bin | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index a228413..6b01b38 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -371,7 +371,7 @@ relx_run_extension() { shift # all extension script locations are expected to be # relative to the start script location - [ "$SCRIPT_DIR/$EXTENSION_SCRIPT" ] && . "$SCRIPT_DIR/$EXTENSION_SCRIPT" $@ + [ "$SCRIPT_DIR/$EXTENSION_SCRIPT" ] && . "$SCRIPT_DIR/$EXTENSION_SCRIPT" "$@" } # given a list of arguments, identify the internal ones @@ -791,7 +791,7 @@ case "$1" in if [ "$IS_EXTENSION" = "1" ]; then EXTENSION_SCRIPT=$(relx_get_extension_script $1) shift - relx_run_extension $EXTENSION_SCRIPT $@ + relx_run_extension $EXTENSION_SCRIPT "$@" # all extension scripts are expected to exit else relx_usage $1 -- cgit v1.2.3 From 7fa443af83c26663ad569dda99a0ce4925e17477 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Fri, 15 Apr 2016 15:54:10 +1000 Subject: Fix renaming of .orig configuration files on Windows Fix .orig rename commands in bin_windows 1. .orig was being prepended second argument rather than appended to the first argument 2. Windows' ren command expects the second argument to be just a file name (not contain drive or path components) 3. Tidy up appending of .orig, place inside double quotes rather than outside of quotes. This matches the usage a few lines later: @if exist "%rel_dir%\%rel_name%.boot" ( Copy rename commands from bin_windows to extended_bin_windows. --- priv/templates/bin_windows | 17 +++++++++++++++++ priv/templates/extended_bin_windows | 7 +++++++ 2 files changed, 24 insertions(+) (limited to 'priv') diff --git a/priv/templates/bin_windows b/priv/templates/bin_windows index b3ce796..19c0d2d 100644 --- a/priv/templates/bin_windows +++ b/priv/templates/bin_windows @@ -73,6 +73,23 @@ cd %rootdir% @set "possible_sys=%rel_dir%\sys.config" @if exist "%possible_sys%" ( set sys_config=-config "%possible_sys%" +) else ( + @if exist "%possible_sys%.orig" ( + ren "%possible_sys%.orig" sys.config + set sys_config=-config "%possible_sys%" + ) +) + +:: Find the vm.args file +:find_vm_args +@set "possible_vm_args=%rel_dir%\vm.args" +@if exist "%possible_vm_args%" ( + set vm_args="%possible_vm_args%" +) else ( + @if exist "%possible_vm_args%.orig" ( + ren "%possible_vm_args%.orig" vm.args + set vm_args="%possible_vm_args%" + ) ) @goto :eof diff --git a/priv/templates/extended_bin_windows b/priv/templates/extended_bin_windows index 045a80c..694c5c7 100644 --- a/priv/templates/extended_bin_windows +++ b/priv/templates/extended_bin_windows @@ -151,6 +151,13 @@ @if exist %possible_sys% ( set sys_config=-config "%possible_sys%" ) +@if exist "%possible_sys%.orig" ( + ren "%possible_sys%.orig" sys.config + set sys_config=-config "%possible_sys%" +) +@if exist "%rel_dir%\vm.args.orig" ( + ren "%rel_dir%\vm.args.orig" vm.args +) @goto :eof :: set boot_script variable -- cgit v1.2.3 From 50c50a5cc4727ed6a982e27fafff8568b5e83d39 Mon Sep 17 00:00:00 2001 From: Tino Breddin Date: Thu, 31 Jan 2019 09:37:07 +0100 Subject: Add sys.config and vm.args check to extended win32 bin --- priv/templates/extended_bin_windows | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'priv') diff --git a/priv/templates/extended_bin_windows b/priv/templates/extended_bin_windows index 694c5c7..ec70c47 100644 --- a/priv/templates/extended_bin_windows +++ b/priv/templates/extended_bin_windows @@ -148,15 +148,21 @@ :: Find the sys.config file :find_sys_config @set "possible_sys=%rel_dir%\sys.config" -@if exist %possible_sys% ( - set sys_config=-config "%possible_sys%" -) -@if exist "%possible_sys%.orig" ( - ren "%possible_sys%.orig" sys.config +@if exist "%possible_sys%" ( set sys_config=-config "%possible_sys%" +) else ( + @if exist "%possible_sys%.orig" ( + ren "%possible_sys%.orig" sys.config + set sys_config=-config "%possible_sys%" + ) ) -@if exist "%rel_dir%\vm.args.orig" ( - ren "%rel_dir%\vm.args.orig" vm.args + +:: Find the vm.args file +:find_vm_args +@if not exist "%m_args%" ( + @if exist "%m_args%.orig" ( + ren "%m_args%.orig" vm.args + ) ) @goto :eof -- cgit v1.2.3 From c5068c10dec0ac0126809396a6ec7a6ec2c75081 Mon Sep 17 00:00:00 2001 From: Tino Breddin Date: Wed, 6 Feb 2019 15:52:45 +0100 Subject: Add extensions to win32 extended_bin --- priv/templates/extended_bin_windows | 94 ++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) (limited to 'priv') diff --git a/priv/templates/extended_bin_windows b/priv/templates/extended_bin_windows index ec70c47..2556c41 100644 --- a/priv/templates/extended_bin_windows +++ b/priv/templates/extended_bin_windows @@ -42,6 +42,7 @@ @set escript="%bindir%\escript.exe" @set werl="%bindir%\werl.exe" @set nodetool="%release_root_dir%\bin\nodetool" +@set extensions={{ extensions }} :: Extract node type and name from vm.args @for /f "usebackq tokens=1-2" %%I in (`findstr /b "\-name \-sname" "%vm_args%"`) do @( @@ -99,6 +100,7 @@ copy "%rel_dir%\%rel_name%.boot" "%rel_dir%\start.boot" >nul ) +@if "%1"=="help" @goto usage @if "%1"=="install" @goto install @if "%1"=="uninstall" @goto uninstall @if "%1"=="start" @goto start @@ -112,6 +114,10 @@ @if "%1"=="attach" @goto attach @if "%1"=="remote_console" @goto attach @if "%1"=="" @goto usage + +@call :is_extension "%1" +@if "%ERRORLEVEL%"=="0" @goto run_extension + @echo Unknown command: "%1" @goto :eof @@ -188,7 +194,63 @@ :: Display usage information :usage -@echo usage: %~n0 ^(install^|uninstall^|start^|stop^|restart^|upgrade^|downgrade^|console^|ping^|list^|attach^|remote_console^) +@if "%2"=="install" ( + @echo "Usage: %rel_name% install [VERSION]" + @echo "Installs a release package VERSION, it assumes that this" + @echo "release package tarball has already been deployed at one" + @echo "of the following locations:" + @echo " releases/-.tar.gz" + @echo " releases//-.tar.gz" + @echo " releases//.tar.gz" + @echo "" + @echo " --no-permanent Install release package VERSION but" + @echo " don't make it permanent" + @goto :eof +) +@if "%2"=="uninstall" ( + @echo "Usage: %rel_name% uninstall [VERSION]" + @echo "Uninstalls a release VERSION, it will only accept" + @echo "versions that are not currently in use" + @goto :eof +) +@if "%2"=="upgrade" ( + @echo "Usage: %rel_name% upgrade [VERSION]" + @echo "Upgrades the currently running release to VERSION, it assumes" + @echo "that a release package tarball has already been deployed at one" + @echo "of the following locations:" + @echo " releases/-.tar.gz" + @echo " releases//-.tar.gz" + @echo " releases//.tar.gz" + @echo "" + @echo " --no-permanent Install release package VERSION but" + @echo " don't make it permanent" + @goto :eof +) +@if "%2"=="downgrade" ( + @echo "Usage: %rel_name% downgrade [VERSION]" + @echo "Downgrades the currently running release to VERSION, it assumes" + @echo "that a release package tarball has already been deployed at one" + @echo "of the following locations:" + @echo " releases/-.tar.gz" + @echo " releases//-.tar.gz" + @echo " releases//.tar.gz" + @echo "" + @echo " --no-permanent Install release package VERSION but" + @echo " don't make it permanent" + @goto :eof +) +@call :is_extension "%2" +@if "%ERRORLEVEL%"=="0" ( + @if exist "%script_dir%\%2.cmd" ( + call "%script_dir%\%2.cmd" help + @goto :eof + ) +) +set commands=install uninstall start stop restart upgrade downgrade console ping list attach remote_console +if not "%extensions%"=="" ( + set "commands=%commands% %extensions%" +) +@echo Usage: %~n0 ^(%commands: =^|%^) @goto :eof :: Install the release as a Windows service @@ -256,3 +318,33 @@ set description=Erlang node %node_name%%hostname% in %rootdir% @start "%node_name% attach" %werl% %boot% ^ -remsh %node_name%%hostname% %node_type% console -setcookie %cookie% @goto :eof + +:: Run extension script +:run_extension +@if exist "%script_dir%\%1.cmd" ( + shift + call "%script_dir%\%1.cmd" %* +) + +@goto :eof + +:: Local Functions + +:is_extension + +@set ext=%~1 + +:: Check for entries in the list, not at the ends +@call set ext_test_1=x%%extensions: %ext% =%% + +:: Check for entry at the start of the list +@call set ext_test_2=x%%extensions:%ext% =%% + +:: Check for entry at the end of the list +@call set ext_test_3=x%%extensions: %ext%=%% + +@if not "%ext_test_1%"=="x%extensions%" exit /b 0 +@if not "%ext_test_2%"=="x%extensions%" exit /b 0 +@if not "%ext_test_3%"=="x%extensions%" exit /b 0 + +@exit /b 1 -- cgit v1.2.3 From 1ad337c4458bc5188a67b8ccf01ba4684fb6383e Mon Sep 17 00:00:00 2001 From: Tino Breddin Date: Thu, 7 Feb 2019 09:41:32 +0100 Subject: Fix windows extended bin --- priv/templates/extended_bin_windows | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'priv') diff --git a/priv/templates/extended_bin_windows b/priv/templates/extended_bin_windows index 2556c41..2d9e0ff 100644 --- a/priv/templates/extended_bin_windows +++ b/priv/templates/extended_bin_windows @@ -42,7 +42,9 @@ @set escript="%bindir%\escript.exe" @set werl="%bindir%\werl.exe" @set nodetool="%release_root_dir%\bin\nodetool" -@set extensions={{ extensions }} +@set "extensions0={{ extensions }}" +@set "extensions1=%extensions0:|= %" +@set "extensions=%extensions1: undefined=%" :: Extract node type and name from vm.args @for /f "usebackq tokens=1-2" %%I in (`findstr /b "\-name \-sname" "%vm_args%"`) do @( @@ -241,8 +243,8 @@ ) @call :is_extension "%2" @if "%ERRORLEVEL%"=="0" ( - @if exist "%script_dir%\%2.cmd" ( - call "%script_dir%\%2.cmd" help + @if exist "%script_dir%\extensions\%2.cmd" ( + call "%script_dir%\extensions\%2.cmd" help @goto :eof ) ) @@ -321,9 +323,9 @@ set description=Erlang node %node_name%%hostname% in %rootdir% :: Run extension script :run_extension -@if exist "%script_dir%\%1.cmd" ( +@if exist "%script_dir%\extensions\%1.cmd" ( shift - call "%script_dir%\%1.cmd" %* + call "%script_dir%\extensions\%1.cmd" %* ) @goto :eof @@ -332,16 +334,16 @@ set description=Erlang node %node_name%%hostname% in %rootdir% :is_extension -@set ext=%~1 +@set "ext=%~1" :: Check for entries in the list, not at the ends -@call set ext_test_1=x%%extensions: %ext% =%% +@call set "ext_test_1=x%%extensions: %ext% =%%" :: Check for entry at the start of the list -@call set ext_test_2=x%%extensions:%ext% =%% +@call set "ext_test_2=x%%extensions:%ext% =%%" :: Check for entry at the end of the list -@call set ext_test_3=x%%extensions: %ext%=%% +@call set "ext_test_3=x%%extensions: %ext%=%%" @if not "%ext_test_1%"=="x%extensions%" exit /b 0 @if not "%ext_test_2%"=="x%extensions%" exit /b 0 -- cgit v1.2.3 From 3e94923d4a5d683faf84094f60e746e024df4ae3 Mon Sep 17 00:00:00 2001 From: Tino Breddin Date: Thu, 7 Feb 2019 16:39:54 +0100 Subject: Fix relx_escript --- priv/templates/extended_bin | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index e5de981..c1b6fff 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -190,7 +190,7 @@ relx_nodetool() { # Run an escript in the node's environment relx_escript() { - shift; scriptpath="$1"; shift + scriptpath="$1"; shift export RELEASE_ROOT_DIR "$ERTS_DIR/bin/escript" "$ROOTDIR/$scriptpath" $@ @@ -598,6 +598,7 @@ case "$1" in escript) ## Run an escript under the node's environment + shift if ! relx_escript $@; then exit 1 fi -- cgit v1.2.3 From edad2b498ad12ee2860a09f80e7862efadf0eff2 Mon Sep 17 00:00:00 2001 From: Anthony Molinaro Date: Thu, 21 Feb 2019 10:17:07 -0800 Subject: Attempt at a fix for vm.args usage (#688) * Attempt at a fix for vm.args usage * bump sleep time to see if it fixes tests on travis --- priv/templates/extended_bin | 49 ++++----------------------------------------- 1 file changed, 4 insertions(+), 45 deletions(-) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index 2cd6d29..7e6dd29 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -170,7 +170,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" \ - -setcookie "$COOKIE" -hidden -kernel net_ticktime $TICKTIME $VM_ARGS + -setcookie "$COOKIE" -hidden -kernel net_ticktime $TICKTIME } # Generate a random id @@ -182,9 +182,7 @@ relx_gen_id() { relx_nodetool() { command="$1"; shift - ESCRIPT_TMP=$(escript_emulator_args_tmp $ROOTDIR/bin/nodetool) - - "$ERTS_DIR/bin/escript" "$ESCRIPT_TMP" "$NAME_TYPE" "$NAME" \ + "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \ -setcookie "$COOKIE" "$command" $@ } @@ -233,41 +231,6 @@ replace_os_vars() { }1' < "$1" > "$2" } -escript_emulator_args() { - if [ -n "${VM_ARGS}" ]; then - if grep -q '%%!' $1; then - cmd=$(echo sed -i"'.prev'" "'/%%!.*/ s| ${VM_ARGS}||'" $1) - eval "$cmd" - cmd=$(echo sed -i"'.prev'" "'/%%!.*/ s|$| ${VM_ARGS}|'" $1) - eval "$cmd" - rm ${1}.prev - else - cmd=$(echo sed -i"'.prev'" "'/#!.*/ a \\ -%%! ${VM_ARGS}\n'" $1) - eval "$cmd" - rm ${1}.prev - fi - fi -} - -escript_emulator_args_tmp() { - # - # If the user provided $ROOTDIR/tmp directory then don't override - # original files of the package but use temporary files instead - # - local TMP_DIR="$ROOTDIR/tmp"; - - if [ -d "$TMP_DIR" ] && [ -w "$TMP_DIR" ]; then - local TMP_FILE="$TMP_DIR/$(basename $1)" - cp $1 $TMP_FILE - escript_emulator_args $TMP_FILE - echo $TMP_FILE - else - escript_emulator_args $1 - echo $1 - fi -} - add_path() { # Use $CWD/$1 if exists, otherwise releases/VSN/$1 IN_FILE_PATH=$2 @@ -649,9 +612,7 @@ case "$1" in relx_run_hooks "$PRE_INSTALL_UPGRADE_HOOKS" - ESCRIPT_TMP=$(escript_emulator_args_tmp $ROOTDIR/bin/install_upgrade.escript) - - exec "$BINDIR/escript" "$ESCRIPT_TMP" \ + exec "$BINDIR/escript" "$ROOTDIR/bin/install_upgrade.escript" \ "$COMMAND" "{'$REL_NAME', \"$NAME_TYPE\", '$NAME', '$COOKIE'}" "$@" relx_run_hooks "$POST_INSTALL_UPGRADE_HOOKS" @@ -665,10 +626,8 @@ case "$1" in fi COMMAND="$1"; shift - - ESCRIPT_TMP=$(escript_emulator_args_tmp $ROOTDIR/bin/install_upgrade.escript) - exec "$BINDIR/escript" "$ESCRIPT_TMP" \ + exec "$BINDIR/escript" "$ROOTDIR/bin/install_upgrade.escript" \ "versions" "{'$REL_NAME', \"$NAME_TYPE\", '$NAME', '$COOKIE'}" "$@" ;; -- cgit v1.2.3 From a0706e46bc9b976afe80a0a8c0bbcc595f6b0b63 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sun, 31 Mar 2019 20:09:34 -0600 Subject: RUNNER_LOG_DIR is only used in 'start' so only make it there (#699) --- priv/templates/extended_bin | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index 7e6dd29..76d2d38 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -457,9 +457,6 @@ esac # Export the variable so that it's available in the 'eval' calls export NAME -# Make sure log directory exists -mkdir -p "$RUNNER_LOG_DIR" - test -z "$PIPE_DIR" && PIPE_BASE_DIR='/tmp/erl_pipes/' PIPE_DIR="${PIPE_DIR:-/tmp/erl_pipes/$NAME/}" @@ -511,6 +508,9 @@ case "$1" in exit 1 fi + # Make sure log directory exists + mkdir -p "$RUNNER_LOG_DIR" + 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" -- cgit v1.2.3 From efdef34f8f896e450ac9665d529e0b690773df96 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Mon, 1 Apr 2019 09:21:19 -0600 Subject: use RELX_OUT_FILE_PATH even when generating from .src files (#700) --- priv/templates/extended_bin | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index 76d2d38..059f5bf 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -250,9 +250,9 @@ check_replace_os_vars() { SRC_FILE_PATH="$IN_FILE_PATH.src" ORIG_FILE_PATH="$IN_FILE_PATH.orig" if [ -f "$SRC_FILE_PATH" ]; then + OUT_FILE_PATH=$(make_out_file_path $IN_FILE_PATH) replace_os_vars "$SRC_FILE_PATH" "$OUT_FILE_PATH" elif [ $RELX_REPLACE_OS_VARS ]; then - # Create a new file in the same location as original OUT_FILE_PATH=$(make_out_file_path $IN_FILE_PATH) # If vm.args.orig or sys.config.orig is present then use that if [ -f "$ORIG_FILE_PATH" ]; then @@ -272,7 +272,8 @@ check_replace_os_vars() { else # If vm.arg.orig or sys.config.orig is present then use that if [ -f "$ORIG_FILE_PATH" ]; then - cp "$ORIG_FILE_PATH" "$OUT_FILE_PATH" + OUT_FILE_PATH=$(make_out_file_path $IN_FILE_PATH) + cp "$ORIG_FILE_PATH" "$OUT_FILE_PATH" fi fi echo $OUT_FILE_PATH -- cgit v1.2.3 From 13c28fd4d5bfd2f91eeb4ff96ace3a2c321664f7 Mon Sep 17 00:00:00 2001 From: Tino Breddin Date: Tue, 19 Mar 2019 13:42:36 +0100 Subject: Fix parameter shift on win32 for extension commands --- priv/templates/extended_bin_windows | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'priv') diff --git a/priv/templates/extended_bin_windows b/priv/templates/extended_bin_windows index 2d9e0ff..6d8f084 100644 --- a/priv/templates/extended_bin_windows +++ b/priv/templates/extended_bin_windows @@ -324,8 +324,9 @@ set description=Erlang node %node_name%%hostname% in %rootdir% :: Run extension script :run_extension @if exist "%script_dir%\extensions\%1.cmd" ( - shift - call "%script_dir%\extensions\%1.cmd" %* + set _extension_params=%* + call set _extension_params=%%_extension_params:*%1=%% + call "%script_dir%\extensions\%1.cmd" %%_extension_params%% ) @goto :eof -- cgit v1.2.3 From 2a4ff9a61f50adce4c86b5414bf81e29bc013160 Mon Sep 17 00:00:00 2001 From: Tino Breddin Date: Fri, 5 Apr 2019 22:30:22 +0200 Subject: 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 --- priv/templates/extended_bin | 27 ++++++++++++----- priv/templates/extended_bin_windows | 58 +++++++++++++++++++++++++++---------- 2 files changed, 63 insertions(+), 22 deletions(-) (limited to 'priv') 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" diff --git a/priv/templates/extended_bin_windows b/priv/templates/extended_bin_windows index 6d8f084..0db46cc 100644 --- a/priv/templates/extended_bin_windows +++ b/priv/templates/extended_bin_windows @@ -37,17 +37,18 @@ @set vm_args=%rel_dir%\vm.args @set progname=erl.exe @set clean_boot_script=%release_root_dir%\bin\start_clean -@set erlsrv="%bindir%\erlsrv.exe" -@set epmd="%bindir%\epmd.exe" -@set escript="%bindir%\escript.exe" -@set werl="%bindir%\werl.exe" -@set nodetool="%release_root_dir%\bin\nodetool" +@set "erlsrv=%bindir%\erlsrv.exe" +@set "epmd=%bindir%\epmd.exe" +@set "escript=%bindir%\escript.exe" +@set "werl=%bindir%\werl.exe" +@set "erl=%bindir%\erl.exe" +@set "nodetool=%release_root_dir%\bin\nodetool" @set "extensions0={{ extensions }}" @set "extensions1=%extensions0:|= %" @set "extensions=%extensions1: undefined=%" :: Extract node type and name from vm.args -@for /f "usebackq tokens=1-2" %%I in (`findstr /b "\-name \-sname" "%vm_args%"`) do @( +@for /f "usebackq tokens=1-2" %%I in ('findstr /b "\-name \-sname" "%vm_args%"') do @( set node_type=%%I set node_name=%%J ) @@ -77,7 +78,7 @@ ) :: Extract cookie from vm.args -@for /f "usebackq tokens=1-2" %%I in (`findstr /b \-setcookie "%vm_args%"`) do @( +@for /f "usebackq tokens=1-2" %%I in ('findstr /b \-setcookie "%vm_args%"') do @( set cookie=%%J ) @@ -86,7 +87,7 @@ :: Collect any additional VM args into erl_opts @setlocal EnableDelayedExpansion -@for /f "usebackq tokens=1-2" %%I in (`findstr /r "^[^#]" "%vm_args%"`) do @( +@for /f "usebackq tokens=1-2" %%I in ('findstr /r "^[^#]" "%vm_args%"') do @( if not "%%I" == "-name" ( if not "%%I" == "-sname" ( if not "%%I" == "-setcookie" ( @@ -143,11 +144,10 @@ :: Set the ERTS dir from erl :set_erts_dir_from_erl @for /f "delims=" %%i in ('where erl') do @( - set erl=%%i + set "erl=%%i" ) -@set dir_cmd="%erl%" -sname dummy -boot no_dot_erlang -noshell -eval "io:format(\"~s\", [filename:nativename(code:root_dir())])." -s init stop -@for /f "delims=" %%i in ('%%dir_cmd%%') do @( - set erl_root=%%i +@for /f "delims=" %%i in ('"%erl%" -boot no_dot_erlang -noshell -eval "io:format(\"~s\", [filename:nativename(code:root_dir())])." -s init stop') do @( + set "erl_root=%%i" ) @set "erts_dir=%erl_root%\erts-%erts_vsn%" @set "rootdir=%erl_root%" @@ -164,12 +164,13 @@ set sys_config=-config "%possible_sys%" ) ) +@goto :eof :: Find the vm.args file :find_vm_args -@if not exist "%m_args%" ( - @if exist "%m_args%.orig" ( - ren "%m_args%.orig" vm.args +@if not exist "%vm_args%" ( + @if exist "%vm_args%.orig" ( + ren "%vm_args%.orig" vm.args ) ) @goto :eof @@ -278,6 +279,7 @@ set description=Erlang node %node_name%%hostname% in %rootdir% :: Start the Windows service :start +@call :ensure_dot_erlang_cookie @%erlsrv% start %service_name% @goto :eof @@ -299,6 +301,7 @@ set description=Erlang node %node_name%%hostname% in %rootdir% :: Start a console :console +@call :ensure_dot_erlang_cookie @set boot=-boot "%boot_script%" -boot_var RELEASE_DIR "%release_root_dir%" @start "%rel_name% console" %werl% %boot% %sys_config% ^ -args_file "%vm_args%" @@ -351,3 +354,28 @@ set description=Erlang node %node_name%%hostname% in %rootdir% @if not "%ext_test_3%"=="x%extensions%" exit /b 0 @exit /b 1 + +:ensure_dot_erlang_cookie + +:: Run a dummy distributed erlang node just to ensure that %HOMEPATH%\.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. + +:: Create random dummy node name +@set /a "_rand_nr=%RANDOM%+100000" +@set "dummy_name=dummy-%_rand_nr%" + +:: Run node and capture output in local var +@for /f "delims=" %%i in ('%erl% -sname %dummy_name% -boot no_dot_erlang -noshell -eval "halt()."') do @( + set "dummy_node_output=%%i" +) + +:: Check for execution error +@if "%dummy_node_output%" neq "" @( + echo Creating .erlang.cookie failed: "%dummy_node_output%" +) + +:: Clear all local variables +@set "dummy_node_output=" + +@exit /b 0 -- cgit v1.2.3 From a6107ec667820de9f6b6d6ae835b0f3b7e613a58 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 12 Apr 2019 08:11:14 -0600 Subject: don't require a cookie in the start script (#708) * don't require a cookie in the start script * remove ensure cookie function from windows script * Add updated cookie handling for win32 --- priv/templates/extended_bin | 62 +++++++++++++++++-------------------- priv/templates/extended_bin_windows | 39 +++++++---------------- 2 files changed, 39 insertions(+), 62 deletions(-) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index fde6729..e224c62 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -136,17 +136,6 @@ find_erts_dir() { 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)" @@ -161,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 @@ -456,6 +454,21 @@ NAME_ARG=$(eval echo "${NAME_ARG}") NAME_TYPE="$(echo "$NAME_ARG" | awk '{print $1}')" NAME="$(echo "$NAME_ARG" | awk '{print $2}')" +# 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 "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 + # User can specify an sname without @hostname # This will fail when creating remote shell # So here we check for @ and add @hostname if missing @@ -470,21 +483,6 @@ export NAME test -z "$PIPE_DIR" && PIPE_BASE_DIR='/tmp/erl_pipes/' PIPE_DIR="${PIPE_DIR:-/tmp/erl_pipes/$NAME/}" -# Extract the target 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 - 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')" cd "$ROOTDIR" @@ -521,8 +519,6 @@ 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" @@ -693,8 +689,6 @@ 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" diff --git a/priv/templates/extended_bin_windows b/priv/templates/extended_bin_windows index 0db46cc..16e3d96 100644 --- a/priv/templates/extended_bin_windows +++ b/priv/templates/extended_bin_windows @@ -77,9 +77,18 @@ set "hostname=@%hostname%" ) -:: Extract cookie from vm.args +:: Extract the target cookie +:: Do this before relx_get_nodename so we can use it and not create a ~/.erlang.cookie @for /f "usebackq tokens=1-2" %%I in ('findstr /b \-setcookie "%vm_args%"') do @( - set cookie=%%J + set "cookie=%%J" +) +@set "default_cookie_file=%USERPROFILE%\.erlang.cookie" +@if "%cookie%" == "" @( + if exist "%default_cookie_file%" ( + set /p cookie=<%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. + ) ) :: Write the erl.ini file to set up paths relative to this script @@ -279,7 +288,6 @@ set description=Erlang node %node_name%%hostname% in %rootdir% :: Start the Windows service :start -@call :ensure_dot_erlang_cookie @%erlsrv% start %service_name% @goto :eof @@ -301,7 +309,6 @@ set description=Erlang node %node_name%%hostname% in %rootdir% :: Start a console :console -@call :ensure_dot_erlang_cookie @set boot=-boot "%boot_script%" -boot_var RELEASE_DIR "%release_root_dir%" @start "%rel_name% console" %werl% %boot% %sys_config% ^ -args_file "%vm_args%" @@ -355,27 +362,3 @@ set description=Erlang node %node_name%%hostname% in %rootdir% @exit /b 1 -:ensure_dot_erlang_cookie - -:: Run a dummy distributed erlang node just to ensure that %HOMEPATH%\.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. - -:: Create random dummy node name -@set /a "_rand_nr=%RANDOM%+100000" -@set "dummy_name=dummy-%_rand_nr%" - -:: Run node and capture output in local var -@for /f "delims=" %%i in ('%erl% -sname %dummy_name% -boot no_dot_erlang -noshell -eval "halt()."') do @( - set "dummy_node_output=%%i" -) - -:: Check for execution error -@if "%dummy_node_output%" neq "" @( - echo Creating .erlang.cookie failed: "%dummy_node_output%" -) - -:: Clear all local variables -@set "dummy_node_output=" - -@exit /b 0 -- cgit v1.2.3 From 4825a495febf31f5be172d1a7e9b89a1514f1b5c Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 12 Apr 2019 14:32:04 -0600 Subject: include dist and epmd arguments from vm.args in remote shell and nodetool calls (#710) * remove unused VM_ARGS variable * include dist args in extended start scripts other calls --- priv/templates/extended_bin | 31 ++++++++++++++++++++++++++----- priv/templates/nodetool | 32 ++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 19 deletions(-) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index e224c62..cfeb859 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -176,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 } @@ -189,8 +189,16 @@ relx_gen_id() { relx_nodetool() { command="$1"; shift - "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \ - -setcookie "$COOKIE" "$command" $@ + if [ -z "${START_EPMD}" ]; then + ERL_FLAGS="${ERL_FLAGS} ${MAYBE_DIST_ARGS}" "$ERTS_DIR/bin/escript" \ + "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \ + -setcookie "$COOKIE" "$command" $@ + else + ERL_FLAGS="${ERL_FLAGS} ${MAYBE_DIST_ARGS}" "$ERTS_DIR/bin/escript" \ + "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \ + $START_EPMD -setcookie "$COOKIE" "$command" $@ + fi + } # Run an escript in the node's environment @@ -454,6 +462,21 @@ NAME_ARG=$(eval echo "${NAME_ARG}") NAME_TYPE="$(echo "$NAME_ARG" | awk '{print $1}')" NAME="$(echo "$NAME_ARG" | awk '{print $2}')" +# 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)" @@ -483,8 +506,6 @@ export NAME test -z "$PIPE_DIR" && PIPE_BASE_DIR='/tmp/erl_pipes/' PIPE_DIR="${PIPE_DIR:-/tmp/erl_pipes/$NAME/}" -VM_ARGS="$(grep -v -E '^#|^-name|^-sname|^-setcookie|^-heart|^-args_file' "$VMARGS_PATH" | xargs | sed -e 's/ / /g')" - cd "$ROOTDIR" # Check the first argument for instructions diff --git a/priv/templates/nodetool b/priv/templates/nodetool index 816be9c..62fa02e 100644 --- a/priv/templates/nodetool +++ b/priv/templates/nodetool @@ -8,9 +8,10 @@ %% ------------------------------------------------------------------- main(Args) -> - ok = start_epmd(), %% Extract the args - {RestArgs, TargetNode} = process_args(Args, [], undefined), + {RestArgs, TargetNode, StartEpmd} = process_args(Args, [], undefined, true), + + ok = start_epmd(StartEpmd), %% See if the node is currently running -- if it's not, we'll bail case {net_kernel:hidden_connect_node(TargetNode), net_adm:ping(TargetNode)} of @@ -87,25 +88,28 @@ main(Args) -> end, net_kernel:stop(). -process_args([], Acc, TargetNode) -> - {lists:reverse(Acc), TargetNode}; -process_args(["-setcookie", Cookie | Rest], Acc, TargetNode) -> +process_args([], Acc, TargetNode, StartEpmd) -> + {lists:reverse(Acc), TargetNode, StartEpmd}; +process_args(["-setcookie", Cookie | Rest], Acc, TargetNode, StartEpmd) -> erlang:set_cookie(node(), list_to_atom(Cookie)), - process_args(Rest, Acc, TargetNode); -process_args(["-name", TargetName | Rest], Acc, _) -> + process_args(Rest, Acc, TargetNode, StartEpmd); +process_args(["-start_epmd", StartEpmd | Rest], Acc, TargetNode, _StartEpmd) -> + process_args(Rest, Acc, TargetNode, list_to_atom(StartEpmd)); +process_args(["-name", TargetName | Rest], Acc, _, StartEpmd) -> ThisNode = append_node_suffix(TargetName, "_maint_"), {ok, _} = net_kernel:start([ThisNode, longnames]), - process_args(Rest, Acc, nodename(TargetName)); -process_args(["-sname", TargetName | Rest], Acc, _) -> + process_args(Rest, Acc, nodename(TargetName), StartEpmd); +process_args(["-sname", TargetName | Rest], Acc, _, StartEpmd) -> ThisNode = append_node_suffix(TargetName, "_maint_"), {ok, _} = net_kernel:start([ThisNode, shortnames]), - process_args(Rest, Acc, nodename(TargetName)); -process_args([Arg | Rest], Acc, Opts) -> - process_args(Rest, [Arg | Acc], Opts). - + process_args(Rest, Acc, nodename(TargetName), StartEpmd); +process_args([Arg | Rest], Acc, Opts, StartEpmd) -> + process_args(Rest, [Arg | Acc], Opts, StartEpmd). -start_epmd() -> +start_epmd(true) -> [] = os:cmd("\"" ++ epmd_path() ++ "\" -daemon"), + ok; +start_epmd(_) -> ok. epmd_path() -> -- cgit v1.2.3 From 8ff1e44cebf3aee09969a9324c04074ba87f10b9 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sun, 14 Apr 2019 07:21:04 -0600 Subject: add dist name and cookie to ERL_FLAGS for nodetool (#712) * remove deprecated hex field from .app.src * start nodetool dist node in erl flags --- priv/templates/extended_bin | 20 +++++++++++++------- priv/templates/nodetool | 15 +++++++++++---- 2 files changed, 24 insertions(+), 11 deletions(-) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index cfeb859..a4cba4a 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -189,16 +189,22 @@ relx_gen_id() { relx_nodetool() { command="$1"; shift + # 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}" "$ERTS_DIR/bin/escript" \ - "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \ - -setcookie "$COOKIE" "$command" $@ + 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}" "$ERTS_DIR/bin/escript" \ - "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \ - $START_EPMD -setcookie "$COOKIE" "$command" $@ + 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 diff --git a/priv/templates/nodetool b/priv/templates/nodetool index 62fa02e..9e24f32 100644 --- a/priv/templates/nodetool +++ b/priv/templates/nodetool @@ -96,16 +96,23 @@ process_args(["-setcookie", Cookie | Rest], Acc, TargetNode, StartEpmd) -> process_args(["-start_epmd", StartEpmd | Rest], Acc, TargetNode, _StartEpmd) -> process_args(Rest, Acc, TargetNode, list_to_atom(StartEpmd)); process_args(["-name", TargetName | Rest], Acc, _, StartEpmd) -> - ThisNode = append_node_suffix(TargetName, "_maint_"), - {ok, _} = net_kernel:start([ThisNode, longnames]), + maybe_start_node(TargetName, longnames), process_args(Rest, Acc, nodename(TargetName), StartEpmd); process_args(["-sname", TargetName | Rest], Acc, _, StartEpmd) -> - ThisNode = append_node_suffix(TargetName, "_maint_"), - {ok, _} = net_kernel:start([ThisNode, shortnames]), + maybe_start_node(TargetName, shortnames), process_args(Rest, Acc, nodename(TargetName), StartEpmd); process_args([Arg | Rest], Acc, Opts, StartEpmd) -> process_args(Rest, [Arg | Acc], Opts, StartEpmd). +maybe_start_node(TargetName, Names) -> + case erlang:node() of + 'nonode@nohost' -> + ThisNode = append_node_suffix(TargetName, "_maint_"), + {ok, _} = net_kernel:start([ThisNode, Names]); + _ -> + ok + end. + start_epmd(true) -> [] = os:cmd("\"" ++ epmd_path() ++ "\" -daemon"), ok; -- cgit v1.2.3