|
|
@@ -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
|
|
|
|
|
|
@@ -22,7 +24,9 @@
|
|
|
|
|
|
@set script=%~n0
|
|
|
|
|
|
+:: for remote_console
|
|
|
@set EPMD_ARG=-start_epmd false -epmd_module ekka_epmd -proto_dist ekka
|
|
|
+:: for erl command
|
|
|
@set ERL_FLAGS=%EPMD_ARG%
|
|
|
|
|
|
:: Discover the release root directory from the directory
|
|
|
@@ -32,43 +36,54 @@
|
|
|
set rel_root_dir=%%~fA
|
|
|
)
|
|
|
|
|
|
-@set rel_dir=%rel_root_dir%\releases\%rel_vsn%
|
|
|
-@set RUNNER_ROOT_DIR=%rel_root_dir%
|
|
|
-@set RUNNER_ETC_DIR=%rel_root_dir%\etc
|
|
|
-
|
|
|
-@set etc_dir=%rel_root_dir%\etc
|
|
|
-@set lib_dir=%rel_root_dir%\lib
|
|
|
-@set data_dir=%rel_root_dir%\data
|
|
|
-@set emqx_conf=%etc_dir%\emqx.conf
|
|
|
+:: If release dir has space, change dir
|
|
|
+@if not "%rel_root_dir%"=="%rel_root_dir: =%" (
|
|
|
+ @chdir /d "%rel_root_dir%"
|
|
|
+ @set rel_root_dir=.
|
|
|
+)
|
|
|
|
|
|
-@call :find_erts_dir
|
|
|
-@call :find_vm_args
|
|
|
-@call :find_sys_config
|
|
|
-@call :set_boot_script_var
|
|
|
+@set "erts_dir=%rel_root_dir%\erts-%erts_vsn%"
|
|
|
+@set "rootdir=%rel_root_dir%"
|
|
|
+@set "rel_dir=%rel_root_dir%\releases\%rel_vsn%"
|
|
|
+@set "RUNNER_ROOT_DIR=%rel_root_dir%"
|
|
|
+:: hard code etc dir
|
|
|
+@set "RUNNER_ETC_DIR=%rel_root_dir%\etc"
|
|
|
+@set "etc_dir=%rel_root_dir%\etc"
|
|
|
+@set "lib_dir=%rel_root_dir%\lib"
|
|
|
+:: allow setting data dir
|
|
|
+@if "%RUNNER_DATA_DIR%"=="" (
|
|
|
+ @set "data_dir=%rel_root_dir%\data"
|
|
|
+) else (
|
|
|
+ @set "data_dir=%RUNNER_DATA_DIR%"
|
|
|
+)
|
|
|
+@set "emqx_conf=%etc_dir%\emqx.conf"
|
|
|
|
|
|
-@set service_name=%rel_name%_%rel_vsn%
|
|
|
-@set bindir=%erts_dir%\bin
|
|
|
+@set "boot_file_name=%rel_dir%\start"
|
|
|
+@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 erlsrv="%bindir%\erlsrv.exe"
|
|
|
-@set escript="%bindir%\escript.exe"
|
|
|
-@set werl="%bindir%\werl.exe"
|
|
|
-@set erl_exe="%bindir%\erl.exe"
|
|
|
-@set nodetool="%rel_root_dir%\bin\nodetool"
|
|
|
-@set cuttlefish="%rel_root_dir%\bin\cuttlefish"
|
|
|
-@set node_type="-name"
|
|
|
-@set schema_mod="emqx_conf_schema"
|
|
|
+@set "clean_boot_file_name=%rel_dir%\start_clean"
|
|
|
+@set "erlsrv=%bindir%\erlsrv.exe"
|
|
|
+@set "escript=%bindir%\escript.exe"
|
|
|
+@set "werl=%bindir%\werl.exe"
|
|
|
+@set "erl_exe=%bindir%\erl.exe"
|
|
|
+@set "nodetool=%rel_root_dir%\bin\nodetool"
|
|
|
+@set "cuttlefish=%rel_root_dir%\bin\cuttlefish"
|
|
|
+@set node_type=-name
|
|
|
+@set schema_mod=emqx_conf_schema
|
|
|
|
|
|
@set conf_path="%etc_dir%\emqx.conf"
|
|
|
:: Extract node name from emqx.conf
|
|
|
@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
|
|
|
)
|
|
|
+@set node_name=%node_name:"=%
|
|
|
|
|
|
:: 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 @(
|
|
|
@call :set_trim node_cookie %%I
|
|
|
)
|
|
|
+@set node_cookie=%node_cookie:"=%
|
|
|
|
|
|
:: Write the erl.ini file to set up paths relative to this script
|
|
|
@call :write_ini
|
|
|
@@ -83,67 +98,22 @@
|
|
|
@if "%1"=="start" @goto start
|
|
|
@if "%1"=="stop" @goto stop
|
|
|
@if "%1"=="restart" @call :stop && @goto start
|
|
|
-::@if "%1"=="upgrade" @goto relup
|
|
|
-::@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"
|
|
|
|
|
|
@goto :eof
|
|
|
|
|
|
-:: 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
|
|
|
-
|
|
|
-:find_vm_args
|
|
|
-@set possible_vm=%etc_dir%\vm.args
|
|
|
-@if exist "%possible_vm%" (
|
|
|
- set args_file=-args_file "%possible_vm%"
|
|
|
-)
|
|
|
-@goto :eof
|
|
|
-
|
|
|
-:: Find the sys.config file
|
|
|
-:find_sys_config
|
|
|
-@set possible_sys=%etc_dir%\sys.config
|
|
|
-@if exist "%possible_sys%" (
|
|
|
- set sys_config=-config "%possible_sys%"
|
|
|
-)
|
|
|
-@goto :eof
|
|
|
-
|
|
|
:create_mnesia_dir
|
|
|
@set create_dir_cmd=%escript% %nodetool% mnesia_dir "%data_dir%\mnesia" %node_name%
|
|
|
@for /f "delims=" %%Z in ('%%create_dir_cmd%%') do @(
|
|
|
set mnesia_dir=%%Z
|
|
|
)
|
|
|
-@set mnesia_dir="%mnesia_dir%"
|
|
|
@goto :eof
|
|
|
|
|
|
:: get the current time with hocon
|
|
|
@@ -155,7 +125,7 @@
|
|
|
|
|
|
:generate_app_config
|
|
|
@call :get_cur_time
|
|
|
-%escript% %nodetool% hocon -v -t %now_time% -s %schema_mod% -c "%etc_dir%\emqx.conf" -d "%data_dir%\configs" generate
|
|
|
+@%escript% %nodetool% hocon -v -t %now_time% -s %schema_mod% -c "%etc_dir%\emqx.conf" -d "%data_dir%\configs" generate
|
|
|
@set generated_config_args=-config "%data_dir%\configs\app.%now_time%.config" -args_file "%data_dir%\configs\vm.%now_time%.args"
|
|
|
:: create one new line
|
|
|
@echo.>>"%data_dir%\configs\vm.%now_time%.args"
|
|
|
@@ -163,18 +133,9 @@
|
|
|
@echo %node_type% %node_name%>>"%data_dir%\configs\vm.%now_time%.args"
|
|
|
@goto :eof
|
|
|
|
|
|
-:: set boot_script variable
|
|
|
-:set_boot_script_var
|
|
|
-@if exist "%rel_dir%\%rel_name%.boot" (
|
|
|
- set boot_script=%rel_dir%\%rel_name%
|
|
|
-) else (
|
|
|
- set boot_script=%rel_dir%\start
|
|
|
-)
|
|
|
-@goto :eof
|
|
|
-
|
|
|
:: Write the erl.ini file
|
|
|
:write_ini
|
|
|
-@set erl_ini=%erts_dir%\bin\erl.ini
|
|
|
+@set "erl_ini=%erts_dir%\bin\erl.ini"
|
|
|
@set converted_bindir=%bindir:\=\\%
|
|
|
@set converted_rootdir=%rootdir:\=\\%
|
|
|
@echo [erlang] > "%erl_ini%"
|
|
|
@@ -185,7 +146,7 @@
|
|
|
|
|
|
:: Display usage information
|
|
|
: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^|remote_console^|attach^)
|
|
|
@goto :eof
|
|
|
|
|
|
:: Install the release as a Windows service
|
|
|
@@ -194,16 +155,13 @@
|
|
|
@call :create_mnesia_dir
|
|
|
@call :generate_app_config
|
|
|
:: Install the service
|
|
|
-@set args="-boot %boot_script% %sys_config% %generated_config_args% -mnesia dir '%mnesia_dir%'"
|
|
|
+@set args="-boot %boot_file_name% %generated_config_args% -mnesia dir '%mnesia_dir%'"
|
|
|
@set description=EMQX node %node_name% in %rootdir%
|
|
|
@if "" == "%2" (
|
|
|
%erlsrv% add %service_name% %node_type% "%node_name%" -on restart -c "%description%" ^
|
|
|
-i "emqx" -w "%rootdir%" -m %erl_exe% -args %args% ^
|
|
|
-st "init:stop()."
|
|
|
sc config emqx start=delayed-auto
|
|
|
-) else (
|
|
|
- :: relup and reldown
|
|
|
- goto relup
|
|
|
)
|
|
|
@goto :eof
|
|
|
|
|
|
@@ -218,11 +176,11 @@
|
|
|
:: @%erlsrv% start %service_name%
|
|
|
@call :create_mnesia_dir
|
|
|
@call :generate_app_config
|
|
|
-@set args=-detached %sys_config% %generated_config_args% -mnesia dir '%mnesia_dir%'
|
|
|
+@set args=-detached %generated_config_args% -mnesia dir '%mnesia_dir%'
|
|
|
@echo off
|
|
|
cd /d "%rel_root_dir%"
|
|
|
@echo on
|
|
|
-@start "%rel_name%" %werl% -boot "%boot_script%" -mode embedded %args%
|
|
|
+@start "%rel_name%" %werl% -mode embedded -boot "%boot_file_name%" %args%
|
|
|
@goto :eof
|
|
|
|
|
|
:: Stop the Windows service
|
|
|
@@ -232,27 +190,15 @@ cd /d "%rel_root_dir%"
|
|
|
@%escript% %nodetool% %node_type% %node_name% -setcookie %node_cookie% stop
|
|
|
@goto :eof
|
|
|
|
|
|
-:: Relup and reldown
|
|
|
-:relup
|
|
|
-@if "" == "%2" (
|
|
|
- echo Missing package argument
|
|
|
- echo Usage: %rel_name% %1 {package base name}
|
|
|
- echo NOTE {package base name} MUST NOT include the .tar.gz suffix
|
|
|
- set ERRORLEVEL=1
|
|
|
- exit /b %ERRORLEVEL%
|
|
|
-)
|
|
|
-@%escript% "%rootdir%/bin/install_upgrade.escript" "%rel_name%" "%node_name%" "%node_cookie%" "%2"
|
|
|
-@goto :eof
|
|
|
-
|
|
|
:: Start a console
|
|
|
:console
|
|
|
@call :create_mnesia_dir
|
|
|
@call :generate_app_config
|
|
|
-@set args=%sys_config% %generated_config_args% -mnesia dir '%mnesia_dir%'
|
|
|
+@set args=%generated_config_args% -mnesia dir '%mnesia_dir%'
|
|
|
@echo off
|
|
|
cd /d %rel_root_dir%
|
|
|
@echo on
|
|
|
-@start "bin\%rel_name% console" %werl% -boot "%boot_script%" -mode embedded %args%
|
|
|
+@start "%rel_name% console" %werl% -mode embedded -boot "%boot_file_name%" %args%
|
|
|
@echo emqx is started!
|
|
|
@goto :eof
|
|
|
|
|
|
@@ -261,6 +207,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%
|
|
|
@@ -268,9 +220,7 @@ 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 "remsh_%nodename%" %werl% -hidden -remsh "%node_name%" -boot "%clean_boot_file_name%" "%node_type%" "remsh_%node_name%" -setcookie "%node_cookie%"
|
|
|
@goto :eof
|
|
|
|
|
|
:: Trim variable
|