diff options
-rw-r--r-- | examples/relx.config | 2 | ||||
-rw-r--r-- | priv/templates/bin_windows | 17 | ||||
-rwxr-xr-x | priv/templates/extended_bin | 41 | ||||
-rw-r--r-- | priv/templates/extended_bin_windows | 113 | ||||
-rw-r--r-- | src/rlx_config.erl | 3 |
5 files changed, 162 insertions, 14 deletions
diff --git a/examples/relx.config b/examples/relx.config index b19042b..3622d01 100644 --- a/examples/relx.config +++ b/examples/relx.config @@ -45,7 +45,7 @@ %% When we have multiple releases relx needs to know which one to build. You %% can specify that on the command line with the `-n` and `-v` arguments to %% relx. However, it is often more convenient to do it in the config. -{default_release, sexpr, "0.0.2"}. +{default_release, {sexpr, "0.0.2"}}. {release, {sexpr, "0.0.1"}, [sexpr, 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 b/priv/templates/extended_bin index 6c012b2..2cd6d29 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 @@ -180,15 +182,15 @@ 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" $@ } # 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" $@ @@ -248,6 +250,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 @@ -353,7 +373,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 @@ -578,6 +598,7 @@ case "$1" in escript) ## Run an escript under the node's environment + shift if ! relx_escript $@; then exit 1 fi @@ -628,9 +649,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 +666,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'}" "$@" ;; @@ -773,7 +794,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 diff --git a/priv/templates/extended_bin_windows b/priv/templates/extended_bin_windows index 00ecf9b..2d9e0ff 100644 --- a/priv/templates/extended_bin_windows +++ b/priv/templates/extended_bin_windows @@ -42,6 +42,9 @@ @set escript="%bindir%\escript.exe" @set werl="%bindir%\werl.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 @( @@ -99,6 +102,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 +116,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 @@ -137,7 +145,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 ) @@ -148,8 +156,21 @@ :: Find the sys.config file :find_sys_config @set "possible_sys=%rel_dir%\sys.config" -@if exist %possible_sys% ( +@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 +@if not exist "%m_args%" ( + @if exist "%m_args%.orig" ( + ren "%m_args%.orig" vm.args + ) ) @goto :eof @@ -175,7 +196,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/<relname>-<version>.tar.gz" + @echo " releases/<version>/<relname>-<version>.tar.gz" + @echo " releases/<version>/<relname>.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/<relname>-<version>.tar.gz" + @echo " releases/<version>/<relname>-<version>.tar.gz" + @echo " releases/<version>/<relname>.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/<relname>-<version>.tar.gz" + @echo " releases/<version>/<relname>-<version>.tar.gz" + @echo " releases/<version>/<relname>.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%\extensions\%2.cmd" ( + call "%script_dir%\extensions\%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 @@ -243,3 +320,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%\extensions\%1.cmd" ( + shift + call "%script_dir%\extensions\%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 diff --git a/src/rlx_config.erl b/src/rlx_config.erl index b341ae7..4160bba 100644 --- a/src/rlx_config.erl +++ b/src/rlx_config.erl @@ -339,6 +339,9 @@ merge_configs([{Key, Value} | CliTerms], ConfigTerms) -> false -> merge_configs(CliTerms, ConfigTerms++[{Key, Value}]) end; + default_release when Value =:= {undefined, undefined} -> + %% No release specified in cli. Prevent overwriting default_release in ConfigTerms. + merge_configs(CliTerms, lists:keymerge(1, ConfigTerms, [{Key, Value}])); _ -> merge_configs(CliTerms, lists:reverse(lists:keystore(Key, 1, lists:reverse(ConfigTerms), {Key, Value}))) end. |