feat(windows): simplify emqx_ctl for windows
This commit is contained in:
parent
5a0e3c1c7b
commit
893b844444
10
bin/emqx.cmd
10
bin/emqx.cmd
|
@ -8,6 +8,7 @@
|
||||||
:: * restart - run the stop command and start command
|
:: * restart - run the stop command and start command
|
||||||
:: * uninstall - uninstall the service and kill a running node
|
:: * uninstall - uninstall the service and kill a running node
|
||||||
:: * ping - check if the node is running
|
:: * ping - check if the node is running
|
||||||
|
:: * 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
|
||||||
:: * list - display a listing of installed Erlang services
|
:: * list - display a listing of installed Erlang services
|
||||||
|
@ -85,6 +86,7 @@
|
||||||
@if "%1"=="restart" @call :stop && @goto start
|
@if "%1"=="restart" @call :stop && @goto start
|
||||||
@if "%1"=="console" @goto console
|
@if "%1"=="console" @goto console
|
||||||
@if "%1"=="ping" @goto ping
|
@if "%1"=="ping" @goto ping
|
||||||
|
@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"=="" @goto usage
|
@if "%1"=="" @goto usage
|
||||||
|
@ -173,7 +175,7 @@
|
||||||
|
|
||||||
:: Display usage information
|
:: Display usage information
|
||||||
:usage
|
:usage
|
||||||
@echo usage: %~n0 ^(install^|uninstall^|start^|stop^|restart^|console^|ping^|list^|attach^)
|
@echo usage: %~n0 ^(install^|uninstall^|start^|stop^|restart^|console^|ping^|ctl^|list^|attach^)
|
||||||
@goto :eof
|
@goto :eof
|
||||||
|
|
||||||
:: Install the release as a Windows service
|
:: Install the release as a Windows service
|
||||||
|
@ -234,6 +236,12 @@ cd /d %rel_root_dir%
|
||||||
@%escript% %nodetool% ping %node_type% "%node_name%" -setcookie "%node_cookie%"
|
@%escript% %nodetool% ping %node_type% "%node_name%" -setcookie "%node_cookie%"
|
||||||
@goto :eof
|
@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 installed Erlang services
|
||||||
:list
|
:list
|
||||||
@%erlsrv% list %service_name%
|
@%erlsrv% list %service_name%
|
||||||
|
|
|
@ -1,92 +1,11 @@
|
||||||
:: The batch file for emqx_ctl command
|
:: The batch file for 'emqx ctl' command
|
||||||
|
|
||||||
@set args=%*
|
@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
|
:: Discover the release root directory from the directory
|
||||||
:: of this script
|
:: of this script
|
||||||
@set script_dir=%~dp0
|
@set script_dir=%~dp0
|
||||||
@for %%A in ("%script_dir%\..") do @(
|
@for %%A in ("%script_dir%\..") do @(
|
||||||
set rel_root_dir=%%~fA
|
set rel_root_dir=%%~fA
|
||||||
)
|
)
|
||||||
@set rel_dir=%rel_root_dir%\releases\%rel_vsn%
|
@%rel_root_dir%\bin\emqx.cmd ctl %args%
|
||||||
@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
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue