fix(windows): attach remote_console

This commit is contained in:
Zaiming (Stone) Shi 2022-02-22 21:31:40 +01:00
parent 0fa7b4a7d4
commit d9bb616574
1 changed files with 35 additions and 31 deletions

View File

@ -11,6 +11,7 @@
:: * ctl - run management commands :: * ctl - run management commands
:: * console - start the Erlang release in a `werl` Windows shell :: * console - start the Erlang release in a `werl` Windows shell
:: * attach - connect to a running node and open an interactive console :: * attach - connect to a running node and open an interactive console
:: * remote_console - same as attach
:: * list - display a listing of installed Erlang services :: * list - display a listing of installed Erlang services
:: * usage - display available commands :: * usage - display available commands
@ -23,7 +24,9 @@
@set script=%~n0 @set script=%~n0
:: for remote_console
@set EPMD_ARG=-start_epmd false -epmd_module ekka_epmd -proto_dist ekka @set EPMD_ARG=-start_epmd false -epmd_module ekka_epmd -proto_dist ekka
:: for erl command
@set ERL_FLAGS=%EPMD_ARG% @set ERL_FLAGS=%EPMD_ARG%
:: Discover the release root directory from the directory :: Discover the release root directory from the directory
@ -33,31 +36,31 @@
set rel_root_dir=%%~fA set rel_root_dir=%%~fA
) )
@set rel_dir=%rel_root_dir%\releases\%rel_vsn% @set "rel_dir=%rel_root_dir%\releases\%rel_vsn%"
@set RUNNER_ROOT_DIR=%rel_root_dir% @set "RUNNER_ROOT_DIR=%rel_root_dir%"
@set RUNNER_ETC_DIR=%rel_root_dir%\etc @set "RUNNER_ETC_DIR=%rel_root_dir%\etc"
@set etc_dir=%rel_root_dir%\etc @set "etc_dir=%rel_root_dir%\etc"
@set lib_dir=%rel_root_dir%\lib @set "lib_dir=%rel_root_dir%\lib"
@set data_dir=%rel_root_dir%\data @set "data_dir=%rel_root_dir%\data"
@set emqx_conf=%etc_dir%\emqx.conf @set "emqx_conf=%etc_dir%\emqx.conf"
@call :find_erts_dir @call :find_erts_dir
@call :find_vm_args @call :find_vm_args
@call :find_sys_config @call :find_sys_config
@set boot_file_name=%rel_dir%\start @set "boot_file_name=%rel_dir%\start"
@set service_name=%rel_name%_%rel_vsn% @set "service_name=%rel_name%_%rel_vsn%"
@set bindir=%erts_dir%\bin @set "bindir=%erts_dir%\bin"
@set progname=erl.exe @set progname=erl.exe
@set clean_boot_file_name=%rel_dir%\start_clean @set "clean_boot_file_name=%rel_dir%\start_clean"
@set erlsrv="%bindir%\erlsrv.exe" @set "erlsrv=%bindir%\erlsrv.exe"
@set escript="%bindir%\escript.exe" @set "escript=%bindir%\escript.exe"
@set werl="%bindir%\werl.exe" @set "werl=%bindir%\werl.exe"
@set erl_exe="%bindir%\erl.exe" @set "erl_exe=%bindir%\erl.exe"
@set nodetool="%rel_root_dir%\bin\nodetool" @set "nodetool=%rel_root_dir%\bin\nodetool"
@set cuttlefish="%rel_root_dir%\bin\cuttlefish" @set "cuttlefish=%rel_root_dir%\bin\cuttlefish"
@set node_type="-name" @set node_type=-name
@set schema_mod=emqx_conf_schema @set schema_mod=emqx_conf_schema
@set conf_path="%etc_dir%\emqx.conf" @set conf_path="%etc_dir%\emqx.conf"
@ -65,11 +68,13 @@
@for /f "usebackq delims=" %%I in (`"%escript% %nodetool% hocon -s %schema_mod% -c %conf_path% get node.name"`) do @( @for /f "usebackq delims=" %%I in (`"%escript% %nodetool% hocon -s %schema_mod% -c %conf_path% get node.name"`) do @(
@call :set_trim node_name %%I @call :set_trim node_name %%I
) )
@set node_name=%node_name:"=%
:: Extract node cookie from emqx.conf :: Extract node cookie from emqx.conf
@for /f "usebackq delims=" %%I in (`"%escript% %nodetool% hocon -s %schema_mod% -c %conf_path% get node.cookie"`) do @( @for /f "usebackq delims=" %%I in (`"%escript% %nodetool% hocon -s %schema_mod% -c %conf_path% get node.cookie"`) do @(
@call :set_trim node_cookie %%I @call :set_trim node_cookie %%I
) )
@set node_cookie=%node_cookie:"=%
:: Write the erl.ini file to set up paths relative to this script :: Write the erl.ini file to set up paths relative to this script
@call :write_ini @call :write_ini
@ -89,6 +94,7 @@
@if "%1"=="ctl" @goto ctl @if "%1"=="ctl" @goto ctl
@if "%1"=="list" @goto list @if "%1"=="list" @goto list
@if "%1"=="attach" @goto attach @if "%1"=="attach" @goto attach
@if "%1"=="remote_console" @goto attach
@if "%1"=="" @goto usage @if "%1"=="" @goto usage
@echo Unknown command: "%1" @echo Unknown command: "%1"
@ -96,7 +102,7 @@
:: Find the ERTS dir :: Find the ERTS dir
:find_erts_dir :find_erts_dir
@set possible_erts_dir=%rel_root_dir%\erts-%erts_vsn% @set "possible_erts_dir=%rel_root_dir%\erts-%erts_vsn%"
@if exist "%possible_erts_dir%" ( @if exist "%possible_erts_dir%" (
call :set_erts_dir_from_default call :set_erts_dir_from_default
) else ( ) else (
@ -106,8 +112,8 @@
:: Set the ERTS dir from the passed in erts_vsn :: Set the ERTS dir from the passed in erts_vsn
:set_erts_dir_from_default :set_erts_dir_from_default
@set erts_dir=%possible_erts_dir% @set "erts_dir=%possible_erts_dir%"
@set rootdir=%rel_root_dir% @set "rootdir=%rel_root_dir%"
@goto :eof @goto :eof
:: Set the ERTS dir from erl :: Set the ERTS dir from erl
@ -117,14 +123,14 @@
) )
@set dir_cmd="%erl%" -noshell -eval "io:format(\"~s\", [filename:nativename(code:root_dir())])." -s init stop @set dir_cmd="%erl%" -noshell -eval "io:format(\"~s\", [filename:nativename(code:root_dir())])." -s init stop
@for /f %%i in ('%%dir_cmd%%') do @( @for /f %%i in ('%%dir_cmd%%') do @(
set erl_root=%%i set erl_root=%%i"
) )
@set erts_dir=%erl_root%\erts-%erts_vsn% @set "erts_dir=%erl_root%\erts-%erts_vsn%"
@set rootdir=%erl_root% @set "rootdir=%erl_root%"
@goto :eof @goto :eof
:find_vm_args :find_vm_args
@set possible_vm=%etc_dir%\vm.args @set "possible_vm=%etc_dir%\vm.args"
@if exist "%possible_vm%" ( @if exist "%possible_vm%" (
set args_file=-args_file "%possible_vm%" set args_file=-args_file "%possible_vm%"
) )
@ -132,7 +138,7 @@
:: Find the sys.config file :: Find the sys.config file
:find_sys_config :find_sys_config
@set possible_sys=%etc_dir%\sys.config @set "possible_sys=%etc_dir%\sys.config"
@if exist "%possible_sys%" ( @if exist "%possible_sys%" (
set sys_config=-config "%possible_sys%" set sys_config=-config "%possible_sys%"
) )
@ -164,7 +170,7 @@
:: Write the erl.ini file :: Write the erl.ini file
:write_ini :write_ini
@set erl_ini=%erts_dir%\bin\erl.ini @set "erl_ini=%erts_dir%\bin\erl.ini"
@set converted_bindir=%bindir:\=\\% @set converted_bindir=%bindir:\=\\%
@set converted_rootdir=%rootdir:\=\\% @set converted_rootdir=%rootdir:\=\\%
@echo [erlang] > "%erl_ini%" @echo [erlang] > "%erl_ini%"
@ -175,7 +181,7 @@
:: Display usage information :: Display usage information
:usage :usage
@echo usage: %~n0 ^(install^|uninstall^|start^|stop^|restart^|console^|ping^|ctl^|list^|attach^) @echo usage: %~n0 ^(install^|uninstall^|start^|stop^|restart^|console^|ping^|ctl^|list^|remote_console^|attach^)
@goto :eof @goto :eof
:: Install the release as a Windows service :: Install the release as a Windows service
@ -249,9 +255,7 @@ cd /d %rel_root_dir%
:: Attach to a running node :: Attach to a running node
:attach :attach
:: @start "%node_name% attach" @start "remsh_%nodename%" %werl% -hidden -remsh "%node_name%" -boot "%clean_boot_file_name%" "%node_type%" "remsh_%node_name%" -setcookie "%node_cookie%"
@start "%node_name% attach" %werl% -boot "%clean_boot_file_name%" ^
-remsh %node_name% %node_type% console_%node_name% -setcookie %node_cookie%
@goto :eof @goto :eof
:: Trim variable :: Trim variable