emqx_ctl.cmd 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. :: The batch file for emqx_ctl command
  2. @set args=%*
  3. :: Set variables that describe the release
  4. @set rel_name=emqx
  5. @set rel_vsn={{ release_version }}
  6. @set erts_vsn={{ erts_vsn }}
  7. @set erl_opts={{ erl_opts }}
  8. :: Discover the release root directory from the directory
  9. :: of this script
  10. @set script_dir=%~dp0
  11. @for %%A in ("%script_dir%\..") do @(
  12. set rel_root_dir=%%~fA
  13. )
  14. @set rel_dir=%rel_root_dir%\releases\%rel_vsn%
  15. @set emqx_conf=%rel_root_dir%\etc\emqx.conf
  16. @call :find_erts_dir
  17. @set bindir=%erts_dir%\bin
  18. @set progname=erl.exe
  19. @set escript="%bindir%\escript.exe"
  20. @set nodetool="%rel_root_dir%\bin\nodetool"
  21. @set node_type="-name"
  22. :: Extract node name from emqx.conf
  23. @for /f "usebackq delims=\= tokens=2" %%I in (`findstr /b node\.name "%emqx_conf%"`) do @(
  24. @call :set_trim node_name %%I
  25. )
  26. :: Extract node cookie from emqx.conf
  27. @for /f "usebackq delims=\= tokens=2" %%I in (`findstr /b node\.cookie "%emqx_conf%"`) do @(
  28. @call :set_trim node_cookie= %%I
  29. )
  30. :: Write the erl.ini file to set up paths relative to this script
  31. @call :write_ini
  32. :: If a start.boot file is not present, copy one from the named .boot file
  33. @if not exist "%rel_dir%\start.boot" (
  34. copy "%rel_dir%\%rel_name%.boot" "%rel_dir%\start.boot" >nul
  35. )
  36. @%escript% %nodetool% %node_type% "%node_name%" -setcookie "%node_cookie%" rpc emqx_ctl run_command %args%
  37. :: Find the ERTS dir
  38. :find_erts_dir
  39. @set possible_erts_dir=%rel_root_dir%\erts-%erts_vsn%
  40. @if exist "%possible_erts_dir%" (
  41. call :set_erts_dir_from_default
  42. ) else (
  43. call :set_erts_dir_from_erl
  44. )
  45. @goto :eof
  46. :: Set the ERTS dir from the passed in erts_vsn
  47. :set_erts_dir_from_default
  48. @set erts_dir=%possible_erts_dir%
  49. @set rootdir=%rel_root_dir%
  50. @goto :eof
  51. :: Set the ERTS dir from erl
  52. :set_erts_dir_from_erl
  53. @for /f "delims=" %%i in ('where erl') do @(
  54. set erl=%%i
  55. )
  56. @set dir_cmd="%erl%" -noshell -eval "io:format(\"~s\", [filename:nativename(code:root_dir())])." -s init stop
  57. @for /f %%i in ('%%dir_cmd%%') do @(
  58. set erl_root=%%i
  59. )
  60. @set erts_dir=%erl_root%\erts-%erts_vsn%
  61. @set rootdir=%erl_root%
  62. @goto :eof
  63. :: Write the erl.ini file
  64. :write_ini
  65. @set erl_ini=%erts_dir%\bin\erl.ini
  66. @set converted_bindir=%bindir:\=\\%
  67. @set converted_rootdir=%rootdir:\=\\%
  68. @echo [erlang] > "%erl_ini%"
  69. @echo Bindir=%converted_bindir% >> "%erl_ini%"
  70. @echo Progname=%progname% >> "%erl_ini%"
  71. @echo Rootdir=%converted_rootdir% >> "%erl_ini%"
  72. @goto :eof
  73. :: Trim variable
  74. :set_trim
  75. @set %1=%2
  76. @goto :eof