diff --git a/bin/emqx.cmd b/bin/emqx.cmd index 8b9686462..257c1b2ce 100644 --- a/bin/emqx.cmd +++ b/bin/emqx.cmd @@ -8,8 +8,10 @@ :: * restart - run the stop command and start command :: * uninstall - uninstall the service and kill a running node :: * ping - check if the node is running +:: * ctl - run management commands :: * console - start the Erlang release in a `werl` Windows shell :: * attach - connect to a running node and open an interactive console +:: * remote_console - same as attach :: * list - display a listing of installed Erlang services :: * usage - display available commands @@ -24,6 +26,9 @@ @set script=%~n0 +@set EPMD_ARG=-start_epmd false -epmd_module ekka_epmd -proto_dist ekka +@set ERL_FLAGS=%EPMD_ARG% + :: Discover the release root directory from the directory :: of this script @set script_dir=%~dp0 @@ -46,7 +51,7 @@ @set service_name=%rel_name%_%rel_vsn% @set bindir=%erts_dir%\bin @set progname=erl.exe -@set clean_boot_script=%rel_root_dir%\bin\start_clean +@set clean_boot_script=%rel_dir%\start_clean @set erlsrv="%bindir%\erlsrv.exe" @set epmd="%bindir%\epmd.exe" @set escript="%bindir%\escript.exe" @@ -83,8 +88,10 @@ ::@if "%1"=="downgrade" @goto relup @if "%1"=="console" @goto console @if "%1"=="ping" @goto ping +@if "%1"=="ctl" @goto ctl @if "%1"=="list" @goto list @if "%1"=="attach" @goto attach +@if "%1"=="remote_console" @goto attach @if "%1"=="" @goto usage @echo Unknown command: "%1" @@ -239,7 +246,7 @@ cd /d %rel_root_dir% @echo off cd /d %rel_root_dir% @echo on -@start "bin\%rel_name% console" %werl% -boot "%boot_script%" %args% +%erl_exe% -boot "%boot_script%" %args% @echo emqx is started! @goto :eof @@ -248,6 +255,12 @@ cd /d %rel_root_dir% @%escript% %nodetool% ping %node_type% "%node_name%" -setcookie "%node_cookie%" @goto :eof +:: ctl to execute management commands +:ctl +@for /f "usebackq tokens=1*" %%i in (`echo %*`) DO @ set params=%%j +@%escript% %nodetool% %node_type% "%node_name%" -setcookie "%node_cookie%" rpc_infinity emqx_ctl run_command %params% +@goto :eof + :: List installed Erlang services :list @%erlsrv% list %service_name% @@ -255,9 +268,8 @@ cd /d %rel_root_dir% :: Attach to a running node :attach -:: @start "%node_name% attach" -@start "%node_name% attach" %werl% -boot "%clean_boot_script%" ^ - -remsh %node_name% %node_type% console_%node_name% -setcookie %node_cookie% +:: @start "%node_name% attach" +%erl_exe% -boot "%clean_boot_script%" -remsh %node_name% %node_type% remsh_%node_name% -setcookie %node_cookie% @goto :eof :: Trim variable diff --git a/bin/emqx_ctl.cmd b/bin/emqx_ctl.cmd index ae9cad2e7..dffb84804 100644 --- a/bin/emqx_ctl.cmd +++ b/bin/emqx_ctl.cmd @@ -2,91 +2,10 @@ @set args=%* -:: Set variables that describe the release -@set rel_name=emqx -@set rel_vsn={{ release_version }} -@set erts_vsn={{ erts_vsn }} -@set erl_opts={{ erl_opts }} - :: Discover the release root directory from the directory :: of this script @set script_dir=%~dp0 @for %%A in ("%script_dir%\..") do @( set rel_root_dir=%%~fA ) -@set rel_dir=%rel_root_dir%\releases\%rel_vsn% -@set emqx_conf=%rel_root_dir%\etc\emqx.conf - -@call :find_erts_dir - -@set bindir=%erts_dir%\bin -@set progname=erl.exe -@set escript="%bindir%\escript.exe" -@set nodetool="%rel_root_dir%\bin\nodetool" -@set node_type="-name" - -:: Extract node name from emqx.conf -@for /f "usebackq delims=\= tokens=2" %%I in (`findstr /b node\.name "%emqx_conf%"`) do @( - @call :set_trim node_name %%I -) - -:: Extract node cookie from emqx.conf -@for /f "usebackq delims=\= tokens=2" %%I in (`findstr /b node\.cookie "%emqx_conf%"`) do @( - @call :set_trim node_cookie= %%I -) - -:: Write the erl.ini file to set up paths relative to this script -@call :write_ini - -:: If a start.boot file is not present, copy one from the named .boot file -@if not exist "%rel_dir%\start.boot" ( - copy "%rel_dir%\%rel_name%.boot" "%rel_dir%\start.boot" >nul -) - -@%escript% %nodetool% %node_type% "%node_name%" -setcookie "%node_cookie%" rpc emqx_ctl run_command %args% - -:: Find the ERTS dir -:find_erts_dir -@set possible_erts_dir=%rel_root_dir%\erts-%erts_vsn% -@if exist "%possible_erts_dir%" ( - call :set_erts_dir_from_default -) else ( - call :set_erts_dir_from_erl -) -@goto :eof - -:: Set the ERTS dir from the passed in erts_vsn -:set_erts_dir_from_default -@set erts_dir=%possible_erts_dir% -@set rootdir=%rel_root_dir% -@goto :eof - -:: Set the ERTS dir from erl -:set_erts_dir_from_erl -@for /f "delims=" %%i in ('where erl') do @( - set erl=%%i -) -@set dir_cmd="%erl%" -noshell -eval "io:format(\"~s\", [filename:nativename(code:root_dir())])." -s init stop -@for /f %%i in ('%%dir_cmd%%') do @( - set erl_root=%%i -) -@set erts_dir=%erl_root%\erts-%erts_vsn% -@set rootdir=%erl_root% -@goto :eof - -:: Write the erl.ini file -:write_ini -@set erl_ini=%erts_dir%\bin\erl.ini -@set converted_bindir=%bindir:\=\\% -@set converted_rootdir=%rootdir:\=\\% -@echo [erlang] > "%erl_ini%" -@echo Bindir=%converted_bindir% >> "%erl_ini%" -@echo Progname=%progname% >> "%erl_ini%" -@echo Rootdir=%converted_rootdir% >> "%erl_ini%" -@goto :eof - -:: Trim variable -:set_trim -@set %1=%2 -@goto :eof - +@%rel_root_dir%\bin\emqx.cmd ctl %args%