startup.cmd 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. @echo off
  2. rem Copyright 1999-2018 Alibaba Group Holding Ltd.
  3. rem Licensed under the Apache License, Version 2.0 (the "License");
  4. rem you may not use this file except in compliance with the License.
  5. rem You may obtain a copy of the License at
  6. rem
  7. rem http://www.apache.org/licenses/LICENSE-2.0
  8. rem
  9. rem Unless required by applicable law or agreed to in writing, software
  10. rem distributed under the License is distributed on an "AS IS" BASIS,
  11. rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. rem See the License for the specific language governing permissions and
  13. rem limitations under the License.
  14. if not exist "%JAVA_HOME%\bin\java.exe" echo Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better! & EXIT /B 1
  15. set "JAVA=%JAVA_HOME%\bin\java.exe"
  16. setlocal enabledelayedexpansion
  17. set BASE_DIR=%~dp0
  18. rem added double quotation marks to avoid the issue caused by the folder names containing spaces.
  19. rem removed the last 5 chars(which means \bin\) to get the base DIR.
  20. set BASE_DIR="%BASE_DIR:~0,-5%"
  21. set CUSTOM_SEARCH_LOCATIONS=file:%BASE_DIR%/conf/
  22. set MODE="standalone"
  23. set FUNCTION_MODE="all"
  24. set SERVER=nacos-server
  25. set MODE_INDEX=-1
  26. set FUNCTION_MODE_INDEX=-1
  27. set SERVER_INDEX=-1
  28. set EMBEDDED_STORAGE_INDEX=-1
  29. set EMBEDDED_STORAGE=""
  30. set i=0
  31. for %%a in (%*) do (
  32. if "%%a" == "-m" ( set /a MODE_INDEX=!i!+1 )
  33. if "%%a" == "-f" ( set /a FUNCTION_MODE_INDEX=!i!+1 )
  34. if "%%a" == "-s" ( set /a SERVER_INDEX=!i!+1 )
  35. if "%%a" == "-p" ( set /a EMBEDDED_STORAGE_INDEX=!i!+1 )
  36. set /a i+=1
  37. )
  38. set i=0
  39. for %%a in (%*) do (
  40. if %MODE_INDEX% == !i! ( set MODE="%%a" )
  41. if %FUNCTION_MODE_INDEX% == !i! ( set FUNCTION_MODE="%%a" )
  42. if %SERVER_INDEX% == !i! (set SERVER="%%a")
  43. if %EMBEDDED_STORAGE_INDEX% == !i! (set EMBEDDED_STORAGE="%%a")
  44. set /a i+=1
  45. )
  46. rem if nacos startup mode is standalone
  47. if %MODE% == "standalone" (
  48. echo "nacos is starting with standalone"
  49. set "NACOS_OPTS=-Dnacos.standalone=true"
  50. set "NACOS_JVM_OPTS=-Xms512m -Xmx512m -Xmn256m"
  51. )
  52. rem if nacos startup mode is cluster
  53. if %MODE% == "cluster" (
  54. echo "nacos is starting with cluster"
  55. if %EMBEDDED_STORAGE% == "embedded" (
  56. set "NACOS_OPTS=-DembeddedStorage=true"
  57. )
  58. set "NACOS_JVM_OPTS=-server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=%BASE_DIR%\logs\java_heapdump.hprof -XX:-UseLargePages"
  59. )
  60. rem set nacos's functionMode
  61. if %FUNCTION_MODE% == "config" (
  62. set "NACOS_OPTS=%NACOS_OPTS% -Dnacos.functionMode=config"
  63. )
  64. if %FUNCTION_MODE% == "naming" (
  65. set "NACOS_OPTS=%NACOS_OPTS% -Dnacos.functionMode=naming"
  66. )
  67. rem set nacos options
  68. set "NACOS_OPTS=%NACOS_OPTS% -Dloader.path=%BASE_DIR%/plugins,%BASE_DIR%/plugins/health,%BASE_DIR%/plugins/cmdb,%BASE_DIR%/plugins/selector"
  69. set "NACOS_OPTS=%NACOS_OPTS% -Dnacos.home=%BASE_DIR%"
  70. set "NACOS_OPTS=%NACOS_OPTS% -jar %BASE_DIR%\target\%SERVER%.jar"
  71. rem set nacos spring config location
  72. set "NACOS_CONFIG_OPTS=--spring.config.additional-location=%CUSTOM_SEARCH_LOCATIONS%"
  73. rem set nacos log4j file location
  74. set "NACOS_LOG4J_OPTS=--logging.config=%BASE_DIR%/conf/nacos-logback.xml"
  75. set COMMAND="%JAVA%" %NACOS_JVM_OPTS% %NACOS_OPTS% %NACOS_CONFIG_OPTS% %NACOS_LOG4J_OPTS% nacos.nacos %*
  76. rem start nacos command
  77. %COMMAND%