solr.cmd 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021
  1. @REM
  2. @REM Licensed to the Apache Software Foundation (ASF) under one or more
  3. @REM contributor license agreements. See the NOTICE file distributed with
  4. @REM this work for additional information regarding copyright ownership.
  5. @REM The ASF licenses this file to You under the Apache License, Version 2.0
  6. @REM (the "License"); you may not use this file except in compliance with
  7. @REM the License. You may obtain a copy of the License at
  8. @REM
  9. @REM http://www.apache.org/licenses/LICENSE-2.0
  10. @REM
  11. @REM Unless required by applicable law or agreed to in writing, software
  12. @REM distributed under the License is distributed on an "AS IS" BASIS,
  13. @REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. @REM See the License for the specific language governing permissions and
  15. @REM limitations under the License.
  16. @echo off
  17. IF "%OS%"=="Windows_NT" setlocal enabledelayedexpansion enableextensions
  18. set "PASS_TO_RUN_EXAMPLE="
  19. REM Determine top-level Solr directory
  20. set SDIR=%~dp0
  21. IF "%SDIR:~-1%"=="\" set SDIR=%SDIR:~0,-1%
  22. set SOLR_TIP=%SDIR%\..
  23. pushd %SOLR_TIP%
  24. set SOLR_TIP=%CD%
  25. popd
  26. REM Used to report errors before exiting the script
  27. set SCRIPT_ERROR=
  28. set NO_USER_PROMPT=0
  29. REM Allow user to import vars from an include file
  30. REM vars set in the include file can be overridden with
  31. REM command line args
  32. IF "%SOLR_INCLUDE%"=="" set "SOLR_INCLUDE=%SOLR_TIP%\bin\solr.in.cmd"
  33. IF EXIST "%SOLR_INCLUDE%" CALL "%SOLR_INCLUDE%"
  34. set "DEFAULT_SERVER_DIR=%SOLR_TIP%\server"
  35. REM Select HTTP OR HTTPS related configurations
  36. set SOLR_URL_SCHEME=http
  37. set "SOLR_JETTY_CONFIG=--module=http"
  38. set "SOLR_SSL_OPTS= "
  39. IF DEFINED SOLR_HADOOP_CREDENTIAL_PROVIDER_PATH (
  40. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Dhadoop.security.credential.provider.path=%SOLR_HADOOP_CREDENTIAL_PROVIDER_PATH%"
  41. )
  42. IF NOT DEFINED SOLR_SSL_ENABLED (
  43. IF DEFINED SOLR_SSL_KEY_STORE (
  44. set "SOLR_SSL_ENABLED=true"
  45. ) ELSE (
  46. set "SOLR_SSL_ENABLED=false"
  47. )
  48. )
  49. IF "%SOLR_SSL_ENABLED%"=="true" (
  50. set "SOLR_JETTY_CONFIG=--lib="%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*" --module=https"
  51. set SOLR_URL_SCHEME=https
  52. IF DEFINED SOLR_SSL_KEY_STORE (
  53. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Dsolr.jetty.keystore=%SOLR_SSL_KEY_STORE%"
  54. )
  55. IF DEFINED SOLR_SSL_KEY_STORE_TYPE (
  56. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Dsolr.jetty.keystore.type=%SOLR_SSL_KEY_STORE_TYPE%"
  57. )
  58. IF DEFINED SOLR_SSL_TRUST_STORE (
  59. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Dsolr.jetty.truststore=%SOLR_SSL_TRUST_STORE%"
  60. )
  61. IF DEFINED SOLR_SSL_TRUST_STORE_TYPE (
  62. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Dsolr.jetty.truststore.type=%SOLR_SSL_TRUST_STORE_TYPE%"
  63. )
  64. IF DEFINED SOLR_SSL_NEED_CLIENT_AUTH (
  65. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Dsolr.jetty.ssl.needClientAuth=%SOLR_SSL_NEED_CLIENT_AUTH%"
  66. )
  67. IF DEFINED SOLR_SSL_WANT_CLIENT_AUTH (
  68. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Dsolr.jetty.ssl.wantClientAuth=%SOLR_SSL_WANT_CLIENT_AUTH%"
  69. )
  70. IF DEFINED SOLR_SSL_CLIENT_KEY_STORE (
  71. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Djavax.net.ssl.keyStore=%SOLR_SSL_CLIENT_KEY_STORE%"
  72. IF DEFINED SOLR_SSL_CLIENT_KEY_STORE_TYPE (
  73. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Djavax.net.ssl.keyStoreType=%SOLR_SSL_CLIENT_KEY_STORE_TYPE%"
  74. )
  75. ) ELSE (
  76. IF DEFINED SOLR_SSL_KEY_STORE (
  77. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Djavax.net.ssl.keyStore=%SOLR_SSL_KEY_STORE%"
  78. )
  79. IF DEFINED SOLR_SSL_KEY_STORE_TYPE (
  80. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Djavax.net.ssl.keyStoreType=%SOLR_SSL_KEY_STORE_TYPE%"
  81. )
  82. )
  83. IF DEFINED SOLR_SSL_CLIENT_TRUST_STORE (
  84. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Djavax.net.ssl.trustStore=%SOLR_SSL_CLIENT_TRUST_STORE%"
  85. IF DEFINED SOLR_SSL_CLIENT_TRUST_STORE_TYPE (
  86. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Djavax.net.ssl.trustStoreType=%SOLR_SSL_CLIENT_TRUST_STORE_TYPE%"
  87. )
  88. ) ELSE (
  89. IF DEFINED SOLR_SSL_TRUST_STORE (
  90. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Djavax.net.ssl.trustStore=%SOLR_SSL_TRUST_STORE%"
  91. )
  92. IF DEFINED SOLR_SSL_TRUST_STORE_TYPE (
  93. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Djavax.net.ssl.trustStoreType=%SOLR_SSL_TRUST_STORE_TYPE%"
  94. )
  95. )
  96. IF DEFINED SOLR_SSL_CHECK_PEER_NAME (
  97. set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Dsolr.ssl.checkPeerName=%SOLR_SSL_CHECK_PEER_NAME%"
  98. )
  99. ) ELSE (
  100. set SOLR_SSL_OPTS=
  101. )
  102. REM Authentication options
  103. IF NOT DEFINED SOLR_AUTH_TYPE (
  104. IF DEFINED SOLR_AUTHENTICATION_OPTS (
  105. echo WARNING: SOLR_AUTHENTICATION_OPTS variable configured without associated SOLR_AUTH_TYPE variable
  106. echo Please configure SOLR_AUTH_TYPE variable with the authentication type to be used.
  107. echo Currently supported authentication types are [kerberos, basic]
  108. )
  109. )
  110. IF DEFINED SOLR_AUTH_TYPE (
  111. IF DEFINED SOLR_AUTHENTICATION_CLIENT_BUILDER (
  112. echo WARNING: SOLR_AUTHENTICATION_CLIENT_BUILDER and SOLR_AUTH_TYPE variables are configured together
  113. echo Use SOLR_AUTH_TYPE variable to configure authentication type to be used
  114. echo Currently supported authentication types are [kerberos, basic]
  115. echo The value of SOLR_AUTHENTICATION_CLIENT_BUILDER configuration variable will be ignored
  116. )
  117. )
  118. IF DEFINED SOLR_AUTH_TYPE (
  119. IF /I "%SOLR_AUTH_TYPE%" == "basic" (
  120. set SOLR_AUTHENTICATION_CLIENT_BUILDER="org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory"
  121. ) ELSE (
  122. IF /I "%SOLR_AUTH_TYPE%" == "kerberos" (
  123. set SOLR_AUTHENTICATION_CLIENT_BUILDER="org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory"
  124. ) ELSE (
  125. echo ERROR: Value specified for SOLR_AUTH_TYPE configuration variable is invalid.
  126. goto err
  127. )
  128. )
  129. )
  130. IF DEFINED SOLR_AUTHENTICATION_CLIENT_CONFIGURER (
  131. echo WARNING: Found unsupported configuration variable SOLR_AUTHENTICATION_CLIENT_CONFIGURER
  132. echo Please start using SOLR_AUTH_TYPE instead
  133. )
  134. IF DEFINED SOLR_AUTHENTICATION_CLIENT_BUILDER (
  135. set AUTHC_CLIENT_BUILDER_ARG="-Dsolr.httpclient.builder.factory=%SOLR_AUTHENTICATION_CLIENT_BUILDER%"
  136. )
  137. set "AUTHC_OPTS=%AUTHC_CLIENT_BUILDER_ARG% %SOLR_AUTHENTICATION_OPTS%"
  138. REM Set the SOLR_TOOL_HOST variable for use when connecting to a running Solr instance
  139. IF NOT "%SOLR_HOST%"=="" (
  140. set "SOLR_TOOL_HOST=%SOLR_HOST%"
  141. ) ELSE (
  142. set "SOLR_TOOL_HOST=localhost"
  143. )
  144. IF "%SOLR_JETTY_HOST%"=="" (
  145. set SOLR_JETTY_HOST=0.0.0.0
  146. )
  147. REM Verify Java is available
  148. IF DEFINED SOLR_JAVA_HOME set "JAVA_HOME=%SOLR_JAVA_HOME%"
  149. REM Try to detect JAVA_HOME from the registry
  150. IF NOT DEFINED JAVA_HOME (
  151. FOR /F "skip=2 tokens=2*" %%A IN ('REG QUERY "HKLM\Software\JavaSoft\Java Runtime Environment" /v CurrentVersion') DO set CurVer=%%B
  152. FOR /F "skip=2 tokens=2*" %%A IN ('REG QUERY "HKLM\Software\JavaSoft\Java Runtime Environment\!CurVer!" /v JavaHome') DO (
  153. set "JAVA_HOME=%%B"
  154. )
  155. )
  156. IF NOT DEFINED JAVA_HOME goto need_java_home
  157. set JAVA_HOME=%JAVA_HOME:"=%
  158. IF %JAVA_HOME:~-1%==\ SET JAVA_HOME=%JAVA_HOME:~0,-1%
  159. IF NOT EXIST "%JAVA_HOME%\bin\java.exe" (
  160. set "SCRIPT_ERROR=java.exe not found in %JAVA_HOME%\bin. Please set JAVA_HOME to a valid JRE / JDK directory."
  161. goto err
  162. )
  163. set "JAVA=%JAVA_HOME%\bin\java"
  164. CALL :resolve_java_info
  165. IF !JAVA_MAJOR_VERSION! LSS 8 (
  166. set "SCRIPT_ERROR=Java 1.8 or later is required to run Solr. Current Java version is: !JAVA_VERSION_INFO! (detected major: !JAVA_MAJOR_VERSION!)"
  167. goto err
  168. )
  169. set FIRST_ARG=%1
  170. IF [%1]==[] goto usage
  171. IF "%1"=="-help" goto usage
  172. IF "%1"=="-usage" goto usage
  173. IF "%1"=="-h" goto usage
  174. IF "%1"=="--help" goto usage
  175. IF "%1"=="/?" goto usage
  176. IF "%1"=="-i" goto get_info
  177. IF "%1"=="-info" goto get_info
  178. IF "%1"=="status" goto get_info
  179. IF "%1"=="version" goto get_version
  180. IF "%1"=="-v" goto get_version
  181. IF "%1"=="-version" goto get_version
  182. IF "%1"=="assert" goto run_assert
  183. REM Only allow the command to be the first argument, assume start if not supplied
  184. IF "%1"=="start" goto set_script_cmd
  185. IF "%1"=="stop" goto set_script_cmd
  186. IF "%1"=="restart" goto set_script_cmd
  187. IF "%1"=="healthcheck" (
  188. REM healthcheck uses different arg parsing strategy
  189. set SCRIPT_CMD=healthcheck
  190. SHIFT
  191. goto parse_healthcheck_args
  192. )
  193. IF "%1"=="create" (
  194. set SCRIPT_CMD=create
  195. SHIFT
  196. goto parse_create_args
  197. )
  198. IF "%1"=="create_core" (
  199. set SCRIPT_CMD=create_core
  200. SHIFT
  201. goto parse_create_args
  202. )
  203. IF "%1"=="create_collection" (
  204. set SCRIPT_CMD=create_collection
  205. SHIFT
  206. goto parse_create_args
  207. )
  208. IF "%1"=="delete" (
  209. set SCRIPT_CMD=delete
  210. SHIFT
  211. goto parse_delete_args
  212. )
  213. IF "%1"=="zk" (
  214. set SCRIPT_CMD=zk
  215. SHIFT
  216. set ZK_RECURSE=false
  217. goto parse_zk_args
  218. )
  219. IF "%1"=="auth" (
  220. set SCRIPT_CMD=auth
  221. SHIFT
  222. goto run_auth
  223. )
  224. IF "%1"=="config" (
  225. REM config uses different arg parsing strategy
  226. set SCRIPT_CMD=config
  227. SHIFT
  228. set CONFIG_ARGS=
  229. goto parse_config_args
  230. )
  231. goto parse_args
  232. :usage
  233. IF NOT "%SCRIPT_ERROR%"=="" ECHO %SCRIPT_ERROR%
  234. IF [%FIRST_ARG%]==[] goto script_usage
  235. IF "%FIRST_ARG%"=="-help" goto script_usage
  236. IF "%FIRST_ARG%"=="-usage" goto script_usage
  237. IF "%FIRST_ARG%"=="-h" goto script_usage
  238. IF "%FIRST_ARG%"=="--help" goto script_usage
  239. IF "%FIRST_ARG%"=="/?" goto script_usage
  240. IF "%SCRIPT_CMD%"=="start" goto start_usage
  241. IF "%SCRIPT_CMD%"=="restart" goto start_usage
  242. IF "%SCRIPT_CMD%"=="stop" goto stop_usage
  243. IF "%SCRIPT_CMD%"=="healthcheck" goto healthcheck_usage
  244. IF "%SCRIPT_CMD%"=="create" goto create_usage
  245. IF "%SCRIPT_CMD%"=="create_core" goto create_core_usage
  246. IF "%SCRIPT_CMD%"=="create_collection" goto create_collection_usage
  247. IF "%SCRIPT_CMD%"=="delete" goto delete_usage
  248. IF "%SCRIPT_CMD%"=="zk" goto zk_usage
  249. IF "%SCRIPT_CMD%"=="auth" goto auth_usage
  250. IF "%SCRIPT_CMD%"=="status" goto status_usage
  251. goto done
  252. :script_usage
  253. @echo.
  254. @echo Usage: solr COMMAND OPTIONS
  255. @echo where COMMAND is one of: start, stop, restart, healthcheck, create, create_core, create_collection, delete, version, zk, auth, assert, config
  256. @echo.
  257. @echo Standalone server example (start Solr running in the background on port 8984):
  258. @echo.
  259. @echo solr start -p 8984
  260. @echo.
  261. @echo SolrCloud example (start Solr running in SolrCloud mode using localhost:2181 to connect to Zookeeper, with 1g max heap size and remote Java debug options enabled):
  262. @echo.
  263. @echo solr start -c -m 1g -z localhost:2181 -a "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044"
  264. @echo.
  265. @echo Omit '-z localhost:2181' from the above command if you have defined ZK_HOST in solr.in.cmd.
  266. @echo.
  267. @echo Pass -help after any COMMAND to see command-specific usage information,
  268. @echo such as: solr start -help or solr stop -help
  269. @echo.
  270. goto done
  271. :start_usage
  272. @echo.
  273. @echo Usage: solr %SCRIPT_CMD% [-f] [-c] [-h hostname] [-p port] [-d directory] [-z zkHost] [-m memory] [-e example] [-s solr.solr.home] [-t solr.data.home] [-a "additional-options"] [-V]
  274. @echo.
  275. @echo -f Start Solr in foreground; default starts Solr in the background
  276. @echo and sends stdout / stderr to solr-PORT-console.log
  277. @echo.
  278. @echo -c or -cloud Start Solr in SolrCloud mode; if -z not supplied and ZK_HOST not defined in
  279. @echo solr.in.cmd, an embedded ZooKeeper instance is started on Solr port+1000,
  280. @echo such as 9983 if Solr is bound to 8983
  281. @echo.
  282. @echo -h host Specify the hostname for this Solr instance
  283. @echo.
  284. @echo -p port Specify the port to start the Solr HTTP listener on; default is 8983
  285. @echo " The specified port (SOLR_PORT) will also be used to determine the stop port"
  286. @echo " STOP_PORT=(\$SOLR_PORT-1000) and JMX RMI listen port RMI_PORT=(\$SOLR_PORT+10000). "
  287. @echo " For instance, if you set -p 8985, then the STOP_PORT=7985 and RMI_PORT=18985"
  288. @echo.
  289. @echo -d dir Specify the Solr server directory; defaults to server
  290. @echo.
  291. @echo -z zkHost Zookeeper connection string; only used when running in SolrCloud mode using -c
  292. @echo If neither ZK_HOST is defined in solr.in.cmd nor the -z parameter is specified,
  293. @echo an embedded ZooKeeper instance will be launched.
  294. @echo.
  295. @echo -m memory Sets the min (-Xms) and max (-Xmx) heap size for the JVM, such as: -m 4g
  296. @echo results in: -Xms4g -Xmx4g; by default, this script sets the heap size to 512m
  297. @echo.
  298. @echo -s dir Sets the solr.solr.home system property; Solr will create core directories under
  299. @echo this directory. This allows you to run multiple Solr instances on the same host
  300. @echo while reusing the same server directory set using the -d parameter. If set, the
  301. @echo specified directory should contain a solr.xml file, unless solr.xml exists in Zookeeper.
  302. @echo This parameter is ignored when running examples (-e), as the solr.solr.home depends
  303. @echo on which example is run. The default value is server/solr. If passed a relative dir
  304. @echo validation with the current dir will be done before trying the default server/^<dir^>
  305. @echo.
  306. @echo -t dir Sets the solr.data.home system property, where Solr will store index data in ^<instance_dir^>/data subdirectories.
  307. @echo If not set, Solr uses solr.solr.home for both config and data.
  308. @echo.
  309. @echo -e example Name of the example to run; available examples:
  310. @echo cloud: SolrCloud example
  311. @echo techproducts: Comprehensive example illustrating many of Solr's core capabilities
  312. @echo dih: Data Import Handler
  313. @echo schemaless: Schema-less example
  314. @echo.
  315. @echo -a opts Additional parameters to pass to the JVM when starting Solr, such as to setup
  316. @echo Java debug options. For example, to enable a Java debugger to attach to the Solr JVM
  317. @echo you could pass: -a "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=18983"
  318. @echo In most cases, you should wrap the additional parameters in double quotes.
  319. @echo.
  320. @echo -j opts Additional parameters to pass to Jetty when starting Solr.
  321. @echo For example, to add configuration folder that jetty should read
  322. @echo you could pass: -j "--include-jetty-dir=/etc/jetty/custom/server/"
  323. @echo In most cases, you should wrap the additional parameters in double quotes.
  324. @echo.
  325. @echo -noprompt Don't prompt for input; accept all defaults when running examples that accept user input
  326. @echo.
  327. @echo -v and -q Verbose (-v) or quiet (-q) logging. Sets default log level to DEBUG or WARN instead of INFO
  328. @echo.
  329. @echo -V/-verbose Verbose messages from this script
  330. @echo.
  331. goto done
  332. :status_usage
  333. @echo.
  334. @echo Usage: solr status
  335. @echo.
  336. @echo NOTE: This command will show the status of all running Solr servers
  337. @echo.
  338. goto done
  339. :stop_usage
  340. @echo.
  341. @echo Usage: solr stop [-k key] [-p port] [-V]
  342. @echo.
  343. @echo -k key Stop key; default is solrrocks
  344. @echo.
  345. @echo -p port Specify the port the Solr HTTP listener is bound to
  346. @echo.
  347. @echo -all Find and stop all running Solr servers on this host
  348. @echo.
  349. @echo -V/-verbose Verbose messages from this script
  350. @echo.
  351. @echo NOTE: To see if any Solr servers are running, do: solr status
  352. @echo.
  353. goto done
  354. :healthcheck_usage
  355. @echo.
  356. @echo Usage: solr healthcheck [-c collection] [-z zkHost] [-V]
  357. @echo.
  358. @echo Can be run from remote (non-Solr^) hosts, as long as a proper ZooKeeper connection is provided
  359. @echo.
  360. @echo -c collection Collection to run healthcheck against.
  361. @echo.
  362. @echo -z zkHost Zookeeper connection string; unnecessary if ZK_HOST is defined in solr.in.cmd;
  363. @echo otherwise, default is localhost:9983
  364. @echo.
  365. @echo -V Enable more verbose output
  366. @echo.
  367. goto done
  368. :create_usage
  369. echo.
  370. echo Usage: solr create [-c name] [-d confdir] [-n confname] [-shards #] [-replicationFactor #] [-p port] [-V]
  371. echo.
  372. echo Create a core or collection depending on whether Solr is running in standalone (core) or SolrCloud
  373. echo mode (collection). In other words, this action detects which mode Solr is running in, and then takes
  374. echo the appropriate action (either create_core or create_collection). For detailed usage instructions, do:
  375. echo.
  376. echo bin\solr create_core -help
  377. echo.
  378. echo or
  379. echo.
  380. echo bin\solr create_collection -help
  381. echo.
  382. goto done
  383. :delete_usage
  384. echo.
  385. echo Usage: solr delete [-c name] [-deleteConfig true^|false] [-p port] [-V]
  386. echo.
  387. echo Deletes a core or collection depending on whether Solr is running in standalone (core) or SolrCloud
  388. echo mode (collection). If you're deleting a collection in SolrCloud mode, the default behavior is to also
  389. echo delete the configuration directory from Zookeeper so long as it is not being used by another collection.
  390. echo You can override this behavior by passing -deleteConfig false when running this command.
  391. echo.
  392. echo Can be run on remote (non-Solr^) hosts, as long as a valid SOLR_HOST is provided in solr.in.cmd
  393. echo.
  394. echo -c name Name of core to delete
  395. echo.
  396. echo -deleteConfig boolean Delete the configuration directory from Zookeeper; default is true
  397. echo.
  398. echo -p port Port of a local Solr instance where you want to delete the core/collection
  399. echo If not specified, the script will search the local system for a running
  400. echo Solr instance and will use the port of the first server it finds.
  401. echo.
  402. echo -V Enables more verbose output.
  403. echo.
  404. goto done
  405. :create_core_usage
  406. echo.
  407. echo Usage: solr create_core [-c ^<core^>] [-d confdir] [-p port] [-V]
  408. echo.
  409. echo When a configSet is used, this can be run from any host. If pointing at a non-configSet directory, this
  410. echo must be run from the host that you wish to create the core on.
  411. echo.
  412. echo -c ^<core^> Name of core to create
  413. echo.
  414. echo -d confdir Configuration directory to copy when creating the new core, built-in options are:
  415. echo.
  416. echo _default: Minimal configuration, which supports enabling/disabling field-guessing support
  417. echo sample_techproducts_configs: Example configuration with many optional features enabled to
  418. echo demonstrate the full power of Solr
  419. echo.
  420. echo If not specified, default is: _default
  421. echo.
  422. echo Alternatively, you can pass the path to your own configuration directory instead of using
  423. echo one of the built-in configurations, such as: bin\solr create_core -c mycore -d c:/tmp/myconfig
  424. echo.
  425. echo -p port Port of a local Solr instance where you want to create the new core
  426. echo If not specified, the script will search the local system for a running
  427. echo Solr instance and will use the port of the first server it finds.
  428. echo.
  429. echo -V Enable more verbose output.
  430. echo.
  431. goto done
  432. :create_collection_usage
  433. echo.
  434. echo Usage: solr create_collection [-c collection] [-d confdir] [-n confname] [-shards #] [-replicationFactor #] [-p port] [-V]
  435. echo.
  436. echo Can be run from remote (non-Solr^) hosts, as long as a valid SOLR_HOST is provided in solr.in.cmd.
  437. echo.
  438. echo -c ^<collection^> Name of collection to create
  439. echo.
  440. echo -d ^<confdir^> Configuration directory to copy when creating the new collection, built-in options are:
  441. echo.
  442. echo _default: Minimal configuration, which supports enabling/disabling field-guessing support
  443. echo sample_techproducts_configs: Example configuration with many optional features enabled to
  444. echo demonstrate the full power of Solr
  445. echo.
  446. echo If not specified, default is: _default
  447. echo.
  448. echo Alternatively, you can pass the path to your own configuration directory instead of using
  449. echo one of the built-in configurations, such as: bin\solr create_collection -c mycoll -d c:/tmp/myconfig
  450. echo.
  451. echo By default the script will upload the specified confdir directory into Zookeeper using the same
  452. echo name as the collection (-c) option. Alternatively, if you want to reuse an existing directory
  453. echo or create a confdir in Zookeeper that can be shared by multiple collections, use the -n option
  454. echo.
  455. echo -n configName Name the configuration directory in Zookeeper; by default, the configuration
  456. echo will be uploaded to Zookeeper using the collection name (-c), but if you want
  457. echo to use an existing directory or override the name of the configuration in
  458. echo Zookeeper, then use the -c option.
  459. echo.
  460. echo -shards # Number of shards to split the collection into; default is 1
  461. echo.
  462. echo -replicationFactor # Number of copies of each document in the collection, default is 1 (no replication)
  463. echo.
  464. echo -p port Port of a local Solr instance where you want to create the new collection
  465. echo If not specified, the script will search the local system for a running
  466. echo Solr instance and will use the port of the first server it finds.
  467. echo.
  468. echo -V Enable more verbose output.
  469. echo.
  470. goto done
  471. :zk_usage
  472. set ZK_FULL=true
  473. goto zk_short_usage
  474. :zk_full_usage
  475. echo Can be run on remote (non-Solr^) hosts, as long as valid ZK_HOST information is provided.
  476. echo Be sure to check the Solr logs in case of errors.
  477. echo.
  478. echo -z zkHost Optional Zookeeper connection string for all commands. If specified it
  479. echo overrides the 'ZK_HOST=...'' defined in solr.in.cmd.
  480. echo.
  481. echo -V Enable more verbose output.
  482. echo.
  483. echo upconfig uploads a configset from the local machine to Zookeeper. (Backcompat: -upconfig)
  484. echo.
  485. echo downconfig downloads a configset from Zookeeper to the local machine. (Backcompat: -downconfig)
  486. echo.
  487. echo -n configName Name of the configset in Zookeeper that will be the destination of
  488. echo 'upconfig' and the source for 'downconfig'.
  489. echo.
  490. echo -d confdir The local directory the configuration will be uploaded from for
  491. echo 'upconfig' or downloaded to for 'downconfig'. If 'confdir' is a child of
  492. echo ...solr/server/solr/configsets' then the configs will be copied from/to
  493. echo that directory. Otherwise it is interpreted as a simple local path.
  494. echo.
  495. echo cp copies files or folders to/from Zookeeper or Zokeeper -^> Zookeeper
  496. echo -r Recursively copy ^<src^> to ^<dst^>. Command will fail if ^<src^> has children and
  497. echo -r is not specified. Optional
  498. echo.
  499. echo. ^<src^>, ^<dest^> : [file:][/]path/to/local/file or zk:/path/to/zk/node
  500. echo NOTE: ^<src^> and ^<dest^> may both be Zookeeper resources prefixed by 'zk:'
  501. echo When ^<src^> is a zk resource, ^<dest^> may be '.'
  502. echo If ^<dest^> ends with '/', then ^<dest^> will be a local folder or parent znode and the last
  503. echo element of the ^<src^> path will be appended unless ^<src^> also ends in a slash.
  504. echo ^<dest^> may be zk:, which may be useful when using the cp -r form to backup/restore
  505. echo the entire zk state.
  506. echo You must enclose local paths that end in a wildcard in quotes or just
  507. echo end the local path in a slash. That is,
  508. echo 'bin/solr zk cp -r /some/dir/ zk:/ -z localhost:2181' is equivalent to
  509. echo 'bin/solr zk cp -r ^"/some/dir/*^" zk:/ -z localhost:2181'
  510. echo but 'bin/solr zk cp -r /some/dir/* zk:/ -z localhost:2181' will throw an error.
  511. echo.
  512. echo Here's an example of backup/restore for a ZK configuration:
  513. echo to copy to local: 'bin/solr zk cp -r zk:/ /some/dir -z localhost:2181'
  514. echo to restore to ZK: 'bin/solr zk cp -r /some/dir/ zk:/ -z localhost:2181'
  515. echo.
  516. echo The 'file:' prefix is stripped, thus 'file:/wherever' specifies an absolute local path and
  517. echo 'file:somewhere' specifies a relative local path. All paths on Zookeeper are absolute.
  518. echo.
  519. echo Zookeeper nodes CAN have data, so moving a single file to a parent znode
  520. echo will overlay the data on the parent Znode so specifying the trailing slash
  521. echo can be important.
  522. echo.
  523. echo Wildcards are supported when copying from local, trailing only and must be quoted.
  524. echo.
  525. echo rm deletes files or folders on Zookeeper
  526. echo -r Recursively delete if ^<path^> is a directory. Command will fail if ^<path^>
  527. echo has children and -r is not specified. Optional
  528. echo ^<path^> : [zk:]/path/to/zk/node. ^<path^> may not be the root ('/')
  529. echo.
  530. echo mv moves (renames) znodes on Zookeeper
  531. echo ^<src^>, ^<dest^> : Zookeeper nodes, the 'zk:' prefix is optional.
  532. echo If ^<dest^> ends with '/', then ^<dest^> will be a parent znode
  533. echo and the last element of the ^<src^> path will be appended.
  534. echo Zookeeper nodes CAN have data, so moving a single file to a parent znode
  535. echo will overlay the data on the parent Znode so specifying the trailing slash
  536. echo is important.
  537. echo.
  538. echo ls lists the znodes on Zookeeper
  539. echo -r recursively descends the path listing all znodes. Optional
  540. echo ^<path^>: The Zookeeper path to use as the root.
  541. echo.
  542. echo Only the node names are listed, not data
  543. echo.
  544. echo mkroot makes a znode in Zookeeper with no data. Can be used to make a path of arbitrary
  545. echo depth but primarily intended to create a 'chroot'.
  546. echo.
  547. echo ^<path^>: The Zookeeper path to create. Leading slash is assumed if not present.
  548. echo Intermediate nodes are created as needed if not present.
  549. echo.
  550. goto done
  551. :zk_short_usage
  552. IF NOT "!ERROR_MSG!"=="" (
  553. echo ERROR: !ERROR_MSG!
  554. echo.
  555. )
  556. echo Usage: solr zk upconfig^|downconfig -d ^<confdir^> -n ^<configName^> [-z zkHost]
  557. echo solr zk cp [-r] ^<src^> ^<dest^> [-z zkHost]
  558. echo solr zk rm [-r] ^<path^> [-z zkHost]
  559. echo solr zk mv ^<src^> ^<dest^> [-z zkHost]
  560. echo solr zk ls [-r] ^<path^> [-z zkHost]
  561. echo solr zk mkroot ^<path^> [-z zkHost]
  562. echo.
  563. IF "%ZK_FULL%"=="true" (
  564. goto zk_full_usage
  565. ) ELSE (
  566. echo Type bin/solr zk -help for full usage help
  567. )
  568. goto done
  569. :auth_usage
  570. echo Usage: solr auth enable [-type basicAuth] -credentials user:pass [-blockUnknown ^<true^|false^>] [-updateIncludeFileOnly ^<true^|false^>] [-V]
  571. echo solr auth enable [-type basicAuth] -prompt ^<true^|false^> [-blockUnknown ^<true^|false^>] [-updateIncludeFileOnly ^<true^|false^>] [-V]
  572. echo solr auth disable [-updateIncludeFileOnly ^<true^|false^>] [-V]
  573. echo.
  574. echo Updates or enables/disables authentication. Must be run on the machine hosting Solr.
  575. echo.
  576. echo -type ^<type^> The authentication mechanism to enable. Defaults to 'basicAuth'.
  577. echo.
  578. echo -credentials ^<user:pass^> The username and password of the initial user
  579. echo Note: only one of -prompt or -credentials must be provided
  580. echo.
  581. echo -prompt ^<true^|false^> Prompts the user to provide the credentials
  582. echo Note: only one of -prompt or -credentials must be provided
  583. echo.
  584. echo -blockUnknown ^<true^|false^> When true, this blocks out access to unauthenticated users. When not provided,
  585. echo this defaults to false (i.e. unauthenticated users can access all endpoints, except the
  586. echo operations like collection-edit, security-edit, core-admin-edit etc.^). Check the reference
  587. echo guide for Basic Authentication for more details.
  588. echo.
  589. echo -updateIncludeFileOnly ^<true^|false^> Only update the solr.in.sh or solr.in.cmd file, and skip actual enabling/disabling"
  590. echo authentication (i.e. don't update security.json^)"
  591. echo.
  592. echo -z zkHost Zookeeper connection string. Unnecessary if ZK_HOST is defined in solr.in.cmd.
  593. echo.
  594. echo -d ^<dir^> Specify the Solr server directory"
  595. echo.
  596. echo -s ^<dir^> Specify the Solr home directory. This is where any credentials or authentication"
  597. echo configuration files (e.g. basicAuth.conf^) would be placed."
  598. echo.
  599. echo -V Enable more verbose output
  600. echo.
  601. goto done
  602. REM Really basic command-line arg parsing
  603. :parse_args
  604. set "arg=%~1"
  605. set "firstTwo=%arg:~0,2%"
  606. IF "%SCRIPT_CMD%"=="" set SCRIPT_CMD=start
  607. IF [%1]==[] goto process_script_cmd
  608. IF "%1"=="-help" goto usage
  609. IF "%1"=="-usage" goto usage
  610. IF "%1"=="/?" goto usage
  611. IF "%1"=="-f" goto set_foreground_mode
  612. IF "%1"=="-foreground" goto set_foreground_mode
  613. IF "%1"=="-V" goto set_verbose
  614. IF "%1"=="-verbose" goto set_verbose
  615. IF "%1"=="-v" goto set_debug
  616. IF "%1"=="-q" goto set_warn
  617. IF "%1"=="-c" goto set_cloud_mode
  618. IF "%1"=="-cloud" goto set_cloud_mode
  619. IF "%1"=="-d" goto set_server_dir
  620. IF "%1"=="-dir" goto set_server_dir
  621. IF "%1"=="-s" goto set_solr_home_dir
  622. IF "%1"=="-t" goto set_solr_data_dir
  623. IF "%1"=="-solr.home" goto set_solr_home_dir
  624. IF "%1"=="-e" goto set_example
  625. IF "%1"=="-example" goto set_example
  626. IF "%1"=="-h" goto set_host
  627. IF "%1"=="-host" goto set_host
  628. IF "%1"=="-m" goto set_memory
  629. IF "%1"=="-memory" goto set_memory
  630. IF "%1"=="-p" goto set_port
  631. IF "%1"=="-port" goto set_port
  632. IF "%1"=="-z" goto set_zookeeper
  633. IF "%1"=="-zkhost" goto set_zookeeper
  634. IF "%1"=="-zkHost" goto set_zookeeper
  635. IF "%1"=="-a" goto set_addl_opts
  636. IF "%1"=="-addlopts" goto set_addl_opts
  637. IF "%1"=="-j" goto set_addl_jetty_config
  638. IF "%1"=="-jettyconfig" goto set_addl_jetty_config
  639. IF "%1"=="-noprompt" goto set_noprompt
  640. IF "%1"=="-k" goto set_stop_key
  641. IF "%1"=="-key" goto set_stop_key
  642. IF "%1"=="-all" goto set_stop_all
  643. IF "%firstTwo%"=="-D" goto set_passthru
  644. IF NOT "%1"=="" goto invalid_cmd_line
  645. goto invalid_cmd_line
  646. :set_script_cmd
  647. set SCRIPT_CMD=%1
  648. SHIFT
  649. goto parse_args
  650. :set_foreground_mode
  651. set FG=1
  652. SHIFT
  653. goto parse_args
  654. :set_verbose
  655. set verbose=1
  656. set "PASS_TO_RUN_EXAMPLE=--verbose !PASS_TO_RUN_EXAMPLE!"
  657. SHIFT
  658. goto parse_args
  659. :set_debug
  660. set SOLR_LOG_LEVEL=DEBUG
  661. SHIFT
  662. goto parse_args
  663. :set_warn
  664. set SOLR_LOG_LEVEL=WARN
  665. SHIFT
  666. goto parse_args
  667. :set_cloud_mode
  668. set SOLR_MODE=solrcloud
  669. SHIFT
  670. goto parse_args
  671. :set_server_dir
  672. set "arg=%~2"
  673. IF "%arg%"=="" (
  674. set SCRIPT_ERROR=Directory name is required!
  675. goto invalid_cmd_line
  676. )
  677. set firstChar=%arg:~0,1%
  678. IF "%firstChar%"=="-" (
  679. set SCRIPT_ERROR=Expected directory but found %2 instead!
  680. goto invalid_cmd_line
  681. )
  682. REM See if they are using a short-hand name relative from the Solr tip directory
  683. IF EXIST "%SOLR_TIP%\%~2" (
  684. set "SOLR_SERVER_DIR=%SOLR_TIP%\%~2"
  685. ) ELSE (
  686. set "SOLR_SERVER_DIR=%~2"
  687. )
  688. SHIFT
  689. SHIFT
  690. goto parse_args
  691. :set_solr_home_dir
  692. set "arg=%~2"
  693. IF "%arg%"=="" (
  694. set SCRIPT_ERROR=Directory name is required!
  695. goto invalid_cmd_line
  696. )
  697. set firstChar=%arg:~0,1%
  698. IF "%firstChar%"=="-" (
  699. set SCRIPT_ERROR=Expected directory but found %2 instead!
  700. goto invalid_cmd_line
  701. )
  702. set "SOLR_HOME=%~2"
  703. SHIFT
  704. SHIFT
  705. goto parse_args
  706. :set_solr_data_dir
  707. set "arg=%~2"
  708. IF "%arg%"=="" (
  709. set SCRIPT_ERROR=Directory name is required!
  710. goto invalid_cmd_line
  711. )
  712. set firstChar=%arg:~0,1%
  713. IF "%firstChar%"=="-" (
  714. set SCRIPT_ERROR=Expected directory but found %2 instead!
  715. goto invalid_cmd_line
  716. )
  717. set "SOLR_DATA_HOME=%~2"
  718. SHIFT
  719. SHIFT
  720. goto parse_args
  721. :set_example
  722. set "arg=%~2"
  723. IF "%arg%"=="" (
  724. set SCRIPT_ERROR=Example name is required!
  725. goto invalid_cmd_line
  726. )
  727. set firstChar=%arg:~0,1%
  728. IF "%firstChar%"=="-" (
  729. set SCRIPT_ERROR=Expected example name but found %2 instead!
  730. goto invalid_cmd_line
  731. )
  732. set EXAMPLE=%~2
  733. SHIFT
  734. SHIFT
  735. goto parse_args
  736. :set_memory
  737. set "arg=%~2"
  738. IF "%arg%"=="" (
  739. set SCRIPT_ERROR=Memory setting is required!
  740. goto invalid_cmd_line
  741. )
  742. set firstChar=%arg:~0,1%
  743. IF "%firstChar%"=="-" (
  744. set SCRIPT_ERROR=Expected memory setting but found %2 instead!
  745. goto invalid_cmd_line
  746. )
  747. set SOLR_HEAP=%~2
  748. set "PASS_TO_RUN_EXAMPLE=-m %~2 !PASS_TO_RUN_EXAMPLE!"
  749. SHIFT
  750. SHIFT
  751. goto parse_args
  752. :set_host
  753. set "arg=%~2"
  754. IF "%arg%"=="" (
  755. set SCRIPT_ERROR=Hostname is required!
  756. goto invalid_cmd_line
  757. )
  758. set firstChar=%arg:~0,1%
  759. IF "%firstChar%"=="-" (
  760. set SCRIPT_ERROR=Expected hostname but found %2 instead!
  761. goto invalid_cmd_line
  762. )
  763. set SOLR_HOST=%~2
  764. set "PASS_TO_RUN_EXAMPLE=-h %~2 !PASS_TO_RUN_EXAMPLE!"
  765. SHIFT
  766. SHIFT
  767. goto parse_args
  768. :set_port
  769. set "arg=%~2"
  770. IF "%arg%"=="" (
  771. set SCRIPT_ERROR=Port is required!
  772. goto invalid_cmd_line
  773. )
  774. set firstChar=%arg:~0,1%
  775. IF "%firstChar%"=="-" (
  776. set SCRIPT_ERROR=Expected port but found %2 instead!
  777. goto invalid_cmd_line
  778. )
  779. set SOLR_PORT=%~2
  780. set "PASS_TO_RUN_EXAMPLE=-p %~2 !PASS_TO_RUN_EXAMPLE!"
  781. SHIFT
  782. SHIFT
  783. goto parse_args
  784. :set_stop_key
  785. set "arg=%~2"
  786. IF "%arg%"=="" (
  787. set SCRIPT_ERROR=Stop key is required!
  788. goto invalid_cmd_line
  789. )
  790. set firstChar=%arg:~0,1%
  791. IF "%firstChar%"=="-" (
  792. set SCRIPT_ERROR=Expected stop key but found %2 instead!
  793. goto invalid_cmd_line
  794. )
  795. set STOP_KEY=%~2
  796. SHIFT
  797. SHIFT
  798. goto parse_args
  799. :set_stop_all
  800. set STOP_ALL=1
  801. SHIFT
  802. goto parse_args
  803. :set_zookeeper
  804. set "arg=%~2"
  805. IF "%arg%"=="" (
  806. set SCRIPT_ERROR=Zookeeper connection string is required!
  807. goto invalid_cmd_line
  808. )
  809. set firstChar=%arg:~0,1%
  810. IF "%firstChar%"=="-" (
  811. set SCRIPT_ERROR=Expected Zookeeper connection string but found %2 instead!
  812. goto invalid_cmd_line
  813. )
  814. set "ZK_HOST=%~2"
  815. set "PASS_TO_RUN_EXAMPLE=-z %~2 !PASS_TO_RUN_EXAMPLE!"
  816. SHIFT
  817. SHIFT
  818. goto parse_args
  819. :set_addl_opts
  820. set "arg=%~2"
  821. set "SOLR_ADDL_ARGS=%~2"
  822. SHIFT
  823. SHIFT
  824. goto parse_args
  825. :set_addl_jetty_config
  826. set "arg=%~2"
  827. set "SOLR_JETTY_ADDL_CONFIG=%~2"
  828. SHIFT
  829. SHIFT
  830. goto parse_args
  831. :set_passthru
  832. set "PASSTHRU=%~1=%~2"
  833. IF NOT "%SOLR_OPTS%"=="" (
  834. set "SOLR_OPTS=%SOLR_OPTS% %PASSTHRU%"
  835. ) ELSE (
  836. set "SOLR_OPTS=%PASSTHRU%"
  837. )
  838. set "PASS_TO_RUN_EXAMPLE=%PASSTHRU% !PASS_TO_RUN_EXAMPLE!"
  839. SHIFT
  840. SHIFT
  841. goto parse_args
  842. :set_noprompt
  843. set NO_USER_PROMPT=1
  844. set "PASS_TO_RUN_EXAMPLE=-noprompt !PASS_TO_RUN_EXAMPLE!"
  845. SHIFT
  846. goto parse_args
  847. REM Perform the requested command after processing args
  848. :process_script_cmd
  849. IF "%verbose%"=="1" (
  850. CALL :safe_echo "Using Solr root directory: %SOLR_TIP%"
  851. CALL :safe_echo "Using Java: %JAVA%"
  852. "%JAVA%" -version
  853. @echo.
  854. )
  855. IF NOT "%SOLR_HOST%"=="" (
  856. set SOLR_HOST_ARG=-Dhost=%SOLR_HOST%
  857. ) ELSE (
  858. set SOLR_HOST_ARG=
  859. )
  860. IF "%SOLR_SERVER_DIR%"=="" set "SOLR_SERVER_DIR=%DEFAULT_SERVER_DIR%"
  861. IF NOT EXIST "%SOLR_SERVER_DIR%" (
  862. set "SCRIPT_ERROR=Solr server directory %SOLR_SERVER_DIR% not found!"
  863. goto err
  864. )
  865. IF NOT "%EXAMPLE%"=="" goto run_example
  866. :start_solr
  867. IF "%SOLR_HOME%"=="" set "SOLR_HOME=%SOLR_SERVER_DIR%\solr"
  868. IF EXIST "%cd%\%SOLR_HOME%" set "SOLR_HOME=%cd%\%SOLR_HOME%"
  869. IF NOT EXIST "%SOLR_HOME%\" (
  870. IF EXIST "%SOLR_SERVER_DIR%\%SOLR_HOME%" (
  871. set "SOLR_HOME=%SOLR_SERVER_DIR%\%SOLR_HOME%"
  872. ) ELSE (
  873. set "SCRIPT_ERROR=Solr home directory %SOLR_HOME% not found!"
  874. goto err
  875. )
  876. )
  877. IF "%STOP_KEY%"=="" set STOP_KEY=solrrocks
  878. @REM This is quite hacky, but examples rely on a different log4j2.xml
  879. @REM so that we can write logs for examples to %SOLR_HOME%\..\logs
  880. IF [%SOLR_LOGS_DIR%] == [] (
  881. set "SOLR_LOGS_DIR=%SOLR_SERVER_DIR%\logs"
  882. ) ELSE (
  883. set SOLR_LOGS_DIR=%SOLR_LOGS_DIR:"=%
  884. )
  885. set "EXAMPLE_DIR=%SOLR_TIP%\example"
  886. set TMP_SOLR_HOME=!SOLR_HOME:%EXAMPLE_DIR%=!
  887. IF NOT "%TMP_SOLR_HOME%"=="%SOLR_HOME%" (
  888. set "SOLR_LOGS_DIR=%SOLR_HOME%\..\logs"
  889. set "LOG4J_CONFIG=file:///%SOLR_SERVER_DIR%\resources\log4j2.xml"
  890. )
  891. set IS_RESTART=0
  892. IF "%SCRIPT_CMD%"=="restart" (
  893. IF "%SOLR_PORT%"=="" (
  894. set "SCRIPT_ERROR=Must specify the port when trying to restart Solr."
  895. goto err
  896. )
  897. set SCRIPT_CMD=stop
  898. set IS_RESTART=1
  899. )
  900. @REM stop logic here
  901. IF "%SCRIPT_CMD%"=="stop" (
  902. IF "%SOLR_PORT%"=="" (
  903. IF "%STOP_ALL%"=="1" (
  904. set found_it=0
  905. for /f "usebackq" %%i in (`dir /b "%SOLR_TIP%\bin" ^| findstr /i "^solr-.*\.port$"`) do (
  906. set SOME_SOLR_PORT=
  907. For /F "delims=" %%J In ('type "%SOLR_TIP%\bin\%%i"') do set SOME_SOLR_PORT=%%~J
  908. if NOT "!SOME_SOLR_PORT!"=="" (
  909. for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":0 " ^| find ":!SOME_SOLR_PORT! "') do (
  910. @REM j is the ip:port and k is the pid
  911. IF NOT "%%k"=="0" (
  912. IF "%%j"=="%SOLR_JETTY_HOST%:!SOME_SOLR_PORT!" (
  913. set found_it=1
  914. @echo Stopping Solr process %%k running on port !SOME_SOLR_PORT!
  915. IF "%STOP_PORT%"=="" set /A STOP_PORT=!SOME_SOLR_PORT! - 1000
  916. "%JAVA%" %SOLR_SSL_OPTS% -Djetty.home="%SOLR_SERVER_DIR%" -jar "%SOLR_SERVER_DIR%\start.jar" STOP.PORT=!STOP_PORT! STOP.KEY=%STOP_KEY% --stop
  917. del "%SOLR_TIP%"\bin\solr-!SOME_SOLR_PORT!.port
  918. timeout /T 5
  919. REM Kill it if it is still running after the graceful shutdown
  920. For /f "tokens=2,5" %%M in ('netstat -nao ^| find "TCP " ^| find ":0 " ^| find ":!SOME_SOLR_PORT! "') do (
  921. IF "%%N"=="%%k" (
  922. IF "%%M"=="%SOLR_JETTY_HOST%:!SOME_SOLR_PORT!" (
  923. @echo Forcefully killing process %%N
  924. taskkill /f /PID %%N
  925. )
  926. )
  927. )
  928. )
  929. )
  930. )
  931. )
  932. )
  933. if "!found_it!"=="0" echo No Solr nodes found to stop.
  934. ) ELSE (
  935. set "SCRIPT_ERROR=Must specify the port when trying to stop Solr, or use -all to stop all running nodes on this host."
  936. goto err
  937. )
  938. ) ELSE (
  939. set found_it=0
  940. For /f "tokens=2,5" %%M in ('netstat -nao ^| find "TCP " ^| find ":0 " ^| find ":%SOLR_PORT% "') do (
  941. IF NOT "%%N"=="0" (
  942. IF "%%M"=="%SOLR_JETTY_HOST%:%SOLR_PORT%" (
  943. set found_it=1
  944. @echo Stopping Solr process %%N running on port %SOLR_PORT%
  945. IF "%STOP_PORT%"=="" set /A STOP_PORT=%SOLR_PORT% - 1000
  946. "%JAVA%" %SOLR_SSL_OPTS% -Djetty.home="%SOLR_SERVER_DIR%" -jar "%SOLR_SERVER_DIR%\start.jar" %SOLR_JETTY_CONFIG% STOP.PORT=!STOP_PORT! STOP.KEY=%STOP_KEY% --stop
  947. del "%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port
  948. timeout /T 5
  949. REM Kill it if it is still running after the graceful shutdown
  950. For /f "tokens=2,5" %%j in ('netstat -nao ^| find "TCP " ^| find ":0 " ^| find ":%SOLR_PORT% "') do (
  951. IF "%%N"=="%%k" (
  952. IF "%%j"=="%SOLR_JETTY_HOST%:%SOLR_PORT%" (
  953. @echo Forcefully killing process %%N
  954. taskkill /f /PID %%N
  955. )
  956. )
  957. )
  958. )
  959. )
  960. )
  961. if "!found_it!"=="0" echo No Solr found running on port %SOLR_PORT%
  962. )
  963. IF "!IS_RESTART!"=="0" goto done
  964. )
  965. IF "!IS_RESTART!"=="1" set SCRIPT_CMD=start
  966. IF "%SOLR_PORT%"=="" set SOLR_PORT=8983
  967. IF "%STOP_PORT%"=="" set /A STOP_PORT=%SOLR_PORT% - 1000
  968. IF "%SCRIPT_CMD%"=="start" (
  969. REM see if Solr is already running using netstat
  970. For /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":0 " ^| find ":%SOLR_PORT% "') do (
  971. IF NOT "%%k"=="0" (
  972. IF "%%j"=="%SOLR_JETTY_HOST%:%SOLR_PORT%" (
  973. set "SCRIPT_ERROR=Process %%k is already listening on port %SOLR_PORT%. If this is Solr, please stop it first before starting (or use restart). If this is not Solr, then please choose a different port using -p PORT"
  974. goto err
  975. )
  976. )
  977. )
  978. )
  979. @REM determine if -server flag is supported by current JVM
  980. "%JAVA%" -server -version > nul 2>&1
  981. IF ERRORLEVEL 1 (
  982. set IS_JDK=false
  983. set "SERVEROPT="
  984. @echo WARNING: You are using a JRE without support for -server option. Please upgrade to latest JDK for best performance
  985. @echo.
  986. ) ELSE (
  987. set IS_JDK=true
  988. set "SERVEROPT=-server"
  989. )
  990. if !JAVA_MAJOR_VERSION! LSS 9 (
  991. "%JAVA%" -d64 -version > nul 2>&1
  992. IF ERRORLEVEL 1 (
  993. set "IS_64BIT=false"
  994. @echo WARNING: 32-bit Java detected. Not recommended for production. Point your JAVA_HOME to a 64-bit JDK
  995. @echo.
  996. ) ELSE (
  997. set IS_64bit=true
  998. )
  999. ) ELSE (
  1000. set IS_64bit=true
  1001. )
  1002. REM Clean up and rotate logs. Default to false since 7.4 as log4j2 handles startup rotation
  1003. IF [%SOLR_LOG_PRESTART_ROTATION%] == [] (
  1004. set SOLR_LOG_PRESTART_ROTATION=false
  1005. )
  1006. IF [%SOLR_LOG_PRESTART_ROTATION%] == [true] (
  1007. REM Enable any of these if you require old remove/archive behavior
  1008. REM call :run_utils "-remove_old_solr_logs 7" || echo "Failed removing old solr logs"
  1009. REM call :run_utils "-archive_gc_logs" || echo "Failed archiving old GC logs"
  1010. REM call :run_utils "-archive_console_logs" || echo "Failed archiving old console logs"
  1011. call :run_utils "-rotate_solr_logs 9" || echo "Failed rotating old solr logs"
  1012. )
  1013. IF NOT "%ZK_HOST%"=="" set SOLR_MODE=solrcloud
  1014. IF "%SOLR_MODE%"=="solrcloud" (
  1015. IF "%ZK_CLIENT_TIMEOUT%"=="" set "ZK_CLIENT_TIMEOUT=15000"
  1016. set "CLOUD_MODE_OPTS=-DzkClientTimeout=!ZK_CLIENT_TIMEOUT!"
  1017. IF NOT "%ZK_HOST%"=="" (
  1018. set "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -DzkHost=%ZK_HOST%"
  1019. ) ELSE (
  1020. IF "%verbose%"=="1" echo Configuring SolrCloud to launch an embedded Zookeeper using -DzkRun
  1021. set "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -DzkRun"
  1022. )
  1023. IF EXIST "%SOLR_HOME%\collection1\core.properties" set "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -Dbootstrap_confdir=./solr/collection1/conf -Dcollection.configName=myconf -DnumShards=1"
  1024. ) ELSE (
  1025. set CLOUD_MODE_OPTS=
  1026. IF NOT EXIST "%SOLR_HOME%\solr.xml" (
  1027. set "SCRIPT_ERROR=Solr home directory %SOLR_HOME% must contain solr.xml!"
  1028. goto err
  1029. )
  1030. )
  1031. REM These are useful for attaching remove profilers like VisualVM/JConsole
  1032. IF "%ENABLE_REMOTE_JMX_OPTS%"=="true" (
  1033. IF "!RMI_PORT!"=="" set RMI_PORT=1%SOLR_PORT%
  1034. set REMOTE_JMX_OPTS=-Dcom.sun.management.jmxremote ^
  1035. -Dcom.sun.management.jmxremote.local.only=false ^
  1036. -Dcom.sun.management.jmxremote.ssl=false ^
  1037. -Dcom.sun.management.jmxremote.authenticate=false ^
  1038. -Dcom.sun.management.jmxremote.port=!RMI_PORT! ^
  1039. -Dcom.sun.management.jmxremote.rmi.port=!RMI_PORT!
  1040. IF NOT "%SOLR_HOST%"=="" set REMOTE_JMX_OPTS=%REMOTE_JMX_OPTS% -Djava.rmi.server.hostname=%SOLR_HOST%
  1041. ) ELSE (
  1042. set REMOTE_JMX_OPTS=
  1043. )
  1044. IF NOT "%SOLR_HEAP%"=="" set SOLR_JAVA_MEM=-Xms%SOLR_HEAP% -Xmx%SOLR_HEAP%
  1045. IF "%SOLR_JAVA_MEM%"=="" set SOLR_JAVA_MEM=-Xms512m -Xmx512m
  1046. IF "%SOLR_JAVA_STACK_SIZE%"=="" set SOLR_JAVA_STACK_SIZE=-Xss256k
  1047. set SOLR_OPTS=%SOLR_JAVA_STACK_SIZE% %SOLR_OPTS%
  1048. IF "%SOLR_TIMEZONE%"=="" set SOLR_TIMEZONE=UTC
  1049. IF "%GC_TUNE%"=="" (
  1050. set GC_TUNE=-XX:NewRatio=3 ^
  1051. -XX:SurvivorRatio=4 ^
  1052. -XX:TargetSurvivorRatio=90 ^
  1053. -XX:MaxTenuringThreshold=8 ^
  1054. -XX:+UseConcMarkSweepGC ^
  1055. -XX:ConcGCThreads=4 -XX:ParallelGCThreads=4 ^
  1056. -XX:+CMSScavengeBeforeRemark ^
  1057. -XX:PretenureSizeThreshold=64m ^
  1058. -XX:+UseCMSInitiatingOccupancyOnly ^
  1059. -XX:CMSInitiatingOccupancyFraction=50 ^
  1060. -XX:CMSMaxAbortablePrecleanTime=6000 ^
  1061. -XX:+CMSParallelRemarkEnabled ^
  1062. -XX:+ParallelRefProcEnabled ^
  1063. -XX:-OmitStackTraceInFastThrow
  1064. )
  1065. if !JAVA_MAJOR_VERSION! GEQ 9 (
  1066. IF NOT "%GC_LOG_OPTS%"=="" (
  1067. echo ERROR: On Java 9 you cannot set GC_LOG_OPTS, only default GC logging is available. Exiting
  1068. GOTO :eof
  1069. )
  1070. set GC_LOG_OPTS="-Xlog:gc*:file=\"!SOLR_LOGS_DIR!\solr_gc.log\":time,uptime:filecount=9,filesize=20M"
  1071. ) else (
  1072. IF "%GC_LOG_OPTS%"=="" (
  1073. rem Set defaults for Java 8
  1074. set GC_LOG_OPTS=-verbose:gc ^
  1075. -XX:+PrintHeapAtGC ^
  1076. -XX:+PrintGCDetails ^
  1077. -XX:+PrintGCDateStamps ^
  1078. -XX:+PrintGCTimeStamps ^
  1079. -XX:+PrintTenuringDistribution ^
  1080. -XX:+PrintGCApplicationStoppedTime
  1081. )
  1082. if "%JAVA_VENDOR%" == "IBM J9" (
  1083. set GC_LOG_OPTS=!GC_LOG_OPTS! "-Xverbosegclog:!SOLR_LOGS_DIR!\solr_gc.log" -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=9 -XX:GCLogFileSize=20M
  1084. ) else (
  1085. set GC_LOG_OPTS=!GC_LOG_OPTS! "-Xloggc:!SOLR_LOGS_DIR!\solr_gc.log" -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=9 -XX:GCLogFileSize=20M
  1086. )
  1087. )
  1088. IF "%verbose%"=="1" (
  1089. @echo Starting Solr using the following settings:
  1090. CALL :safe_echo " JAVA = %JAVA%"
  1091. CALL :safe_echo " SOLR_SERVER_DIR = %SOLR_SERVER_DIR%"
  1092. CALL :safe_echo " SOLR_HOME = %SOLR_HOME%"
  1093. @echo SOLR_HOST = %SOLR_HOST%
  1094. @echo SOLR_PORT = %SOLR_PORT%
  1095. @echo STOP_PORT = %STOP_PORT%
  1096. @echo SOLR_JAVA_MEM = %SOLR_JAVA_MEM%
  1097. @echo GC_TUNE = !GC_TUNE!
  1098. @echo GC_LOG_OPTS = %GC_LOG_OPTS%
  1099. @echo SOLR_TIMEZONE = %SOLR_TIMEZONE%
  1100. IF "%SOLR_MODE%"=="solrcloud" (
  1101. @echo CLOUD_MODE_OPTS = %CLOUD_MODE_OPTS%
  1102. )
  1103. IF NOT "%SOLR_OPTS%"=="" (
  1104. @echo SOLR_OPTS = %SOLR_OPTS%
  1105. )
  1106. IF NOT "%SOLR_ADDL_ARGS%"=="" (
  1107. CALL :safe_echo " SOLR_ADDL_ARGS = %SOLR_ADDL_ARGS%"
  1108. )
  1109. IF NOT "%SOLR_JETTY_ADDL_CONFIG%"=="" (
  1110. CALL :safe_echo " SOLR_JETTY_ADDL_CONFIG = %SOLR_JETTY_ADDL_CONFIG%"
  1111. )
  1112. IF "%ENABLE_REMOTE_JMX_OPTS%"=="true" (
  1113. @echo RMI_PORT = !RMI_PORT!
  1114. @echo REMOTE_JMX_OPTS = %REMOTE_JMX_OPTS%
  1115. )
  1116. IF NOT "%SOLR_LOG_LEVEL%"=="" (
  1117. @echo SOLR_LOG_LEVEL = !SOLR_LOG_LEVEL!
  1118. )
  1119. IF NOT "%SOLR_DATA_HOME%"=="" (
  1120. @echo SOLR_DATA_HOME = !SOLR_DATA_HOME!
  1121. )
  1122. @echo.
  1123. )
  1124. set START_OPTS=-Duser.timezone=%SOLR_TIMEZONE%
  1125. set START_OPTS=%START_OPTS% !GC_TUNE! %GC_LOG_OPTS%
  1126. IF NOT "!CLOUD_MODE_OPTS!"=="" set "START_OPTS=%START_OPTS% !CLOUD_MODE_OPTS!"
  1127. IF NOT "%REMOTE_JMX_OPTS%"=="" set "START_OPTS=%START_OPTS% %REMOTE_JMX_OPTS%"
  1128. IF NOT "%SOLR_ADDL_ARGS%"=="" set "START_OPTS=%START_OPTS% %SOLR_ADDL_ARGS%"
  1129. IF NOT "%SOLR_HOST_ARG%"=="" set "START_OPTS=%START_OPTS% %SOLR_HOST_ARG%"
  1130. IF NOT "%SOLR_OPTS%"=="" set "START_OPTS=%START_OPTS% %SOLR_OPTS%"
  1131. IF "%SOLR_SSL_ENABLED%"=="true" (
  1132. set "SSL_PORT_PROP=-Dsolr.jetty.https.port=%SOLR_PORT%"
  1133. set "START_OPTS=%START_OPTS% %SOLR_SSL_OPTS% !SSL_PORT_PROP!"
  1134. )
  1135. IF NOT "%SOLR_LOG_LEVEL%"=="" set "START_OPTS=%START_OPTS% -Dsolr.log.level=%SOLR_LOG_LEVEL%"
  1136. set SOLR_LOGS_DIR_QUOTED="%SOLR_LOGS_DIR%"
  1137. set SOLR_DATA_HOME_QUOTED="%SOLR_DATA_HOME%"
  1138. set "START_OPTS=%START_OPTS% -Dsolr.log.dir=%SOLR_LOGS_DIR_QUOTED%"
  1139. IF NOT "%SOLR_DATA_HOME%"=="" set "START_OPTS=%START_OPTS% -Dsolr.data.home=%SOLR_DATA_HOME_QUOTED%"
  1140. IF NOT DEFINED LOG4J_CONFIG set "LOG4J_CONFIG=file:///%SOLR_SERVER_DIR%\resources\log4j2.xml"
  1141. cd /d "%SOLR_SERVER_DIR%"
  1142. IF NOT EXIST "%SOLR_LOGS_DIR%" (
  1143. mkdir "%SOLR_LOGS_DIR%"
  1144. )
  1145. copy /Y NUL "%SOLR_LOGS_DIR%\.writable" > NUL 2>&1 && set WRITEOK=1
  1146. IF DEFINED WRITEOK (
  1147. del "%SOLR_LOGS_DIR%\.writable"
  1148. ) else (
  1149. echo "ERROR: Logs directory %SOLR_LOGS_DIR% is not writable or could not be created. Exiting"
  1150. GOTO :eof
  1151. )
  1152. echo " contexts etc lib modules resources scripts solr solr-webapp " > "%TEMP%\solr-pattern.txt"
  1153. findstr /i /C:" %SOLR_LOGS_DIR% " "%TEMP%\solr-pattern.txt" 1>nul
  1154. if %ERRORLEVEL% == 0 (
  1155. echo "ERROR: Logs directory %SOLR_LOGS_DIR% is invalid. Reserved for the system. Exiting"
  1156. GOTO :eof
  1157. )
  1158. IF NOT EXIST "%SOLR_SERVER_DIR%\tmp" (
  1159. mkdir "%SOLR_SERVER_DIR%\tmp"
  1160. )
  1161. IF "%DEFAULT_CONFDIR%"=="" set "DEFAULT_CONFDIR=%SOLR_SERVER_DIR%\solr\configsets\_default\conf"
  1162. IF "%FG%"=="1" (
  1163. REM run solr in the foreground
  1164. title "Solr-%SOLR_PORT%"
  1165. echo %SOLR_PORT%>"%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port
  1166. "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% ^
  1167. -Dlog4j.configurationFile="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^
  1168. -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" -Dsolr.default.confdir="%DEFAULT_CONFDIR%" ^
  1169. -Djetty.host=%SOLR_JETTY_HOST% -Djetty.port=%SOLR_PORT% -Djetty.home="%SOLR_SERVER_DIR%" ^
  1170. -Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar %SOLR_JETTY_CONFIG% "%SOLR_JETTY_ADDL_CONFIG%"
  1171. ) ELSE (
  1172. START /B "Solr-%SOLR_PORT%" /D "%SOLR_SERVER_DIR%" ^
  1173. "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% ^
  1174. -Dlog4j.configurationFile="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^
  1175. -Dsolr.log.muteconsole ^
  1176. -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" -Dsolr.default.confdir="%DEFAULT_CONFDIR%" ^
  1177. -Djetty.host=%SOLR_JETTY_HOST% -Djetty.port=%SOLR_PORT% -Djetty.home="%SOLR_SERVER_DIR%" ^
  1178. -Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar %SOLR_JETTY_CONFIG% "%SOLR_JETTY_ADDL_CONFIG%" > "!SOLR_LOGS_DIR!\solr-%SOLR_PORT%-console.log"
  1179. echo %SOLR_PORT%>"%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port
  1180. REM now wait to see Solr come online ...
  1181. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" -Dsolr.default.confdir="%DEFAULT_CONFDIR%"^
  1182. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1183. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1184. org.apache.solr.util.SolrCLI status -maxWaitSecs 30 -solr !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:%SOLR_PORT%/solr
  1185. )
  1186. goto done
  1187. :run_example
  1188. REM Run the requested example
  1189. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1190. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1191. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1192. org.apache.solr.util.SolrCLI run_example -script "%SDIR%\solr.cmd" -e %EXAMPLE% -d "%SOLR_SERVER_DIR%" ^
  1193. -urlScheme !SOLR_URL_SCHEME! !PASS_TO_RUN_EXAMPLE!
  1194. REM End of run_example
  1195. goto done
  1196. :get_info
  1197. REM Find all Java processes, correlate with those listening on a port
  1198. REM and then try to contact via that port using the status tool
  1199. for /f "usebackq" %%i in (`dir /b "%SOLR_TIP%\bin" ^| findstr /i "^solr-.*\.port$"`) do (
  1200. set SOME_SOLR_PORT=
  1201. For /F "Delims=" %%J In ('type "%SOLR_TIP%\bin\%%i"') do set SOME_SOLR_PORT=%%~J
  1202. if NOT "!SOME_SOLR_PORT!"=="" (
  1203. for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":0 " ^| find ":!SOME_SOLR_PORT! "') do (
  1204. IF NOT "%%k"=="0" (
  1205. if "%%j"=="%SOLR_JETTY_HOST%:!SOME_SOLR_PORT!" (
  1206. @echo.
  1207. set has_info=1
  1208. echo Found Solr process %%k running on port !SOME_SOLR_PORT!
  1209. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1210. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1211. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1212. org.apache.solr.util.SolrCLI status -solr !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:!SOME_SOLR_PORT!/solr
  1213. @echo.
  1214. )
  1215. )
  1216. )
  1217. )
  1218. )
  1219. if NOT "!has_info!"=="1" echo No running Solr nodes found.
  1220. set has_info=
  1221. goto done
  1222. :parse_healthcheck_args
  1223. IF [%1]==[] goto run_healthcheck
  1224. IF "%1"=="-V" goto set_healthcheck_verbose
  1225. IF "%1"=="-c" goto set_healthcheck_collection
  1226. IF "%1"=="-collection" goto set_healthcheck_collection
  1227. IF "%1"=="-z" goto set_healthcheck_zk
  1228. IF "%1"=="-zkhost" goto set_healthcheck_zk
  1229. IF "%1"=="-zkHost" goto set_healthcheck_zk
  1230. IF "%1"=="-help" goto usage
  1231. IF "%1"=="-usage" goto usage
  1232. IF "%1"=="/?" goto usage
  1233. goto run_healthcheck
  1234. :set_healthcheck_verbose
  1235. set HEALTHCHECK_VERBOSE="-verbose"
  1236. SHIFT
  1237. goto parse_healthcheck_args
  1238. :set_healthcheck_collection
  1239. set HEALTHCHECK_COLLECTION=%~2
  1240. SHIFT
  1241. SHIFT
  1242. goto parse_healthcheck_args
  1243. :set_healthcheck_zk
  1244. set ZK_HOST=%~2
  1245. SHIFT
  1246. SHIFT
  1247. goto parse_healthcheck_args
  1248. :run_healthcheck
  1249. IF NOT DEFINED HEALTHCHECK_COLLECTION goto healthcheck_usage
  1250. IF NOT DEFINED HEALTHCHECK_VERBOSE set "HEALTHCHECK_VERBOSE="
  1251. IF NOT DEFINED HEALTHCHECK_ZK_HOST set "HEALTHCHECK_ZK_HOST=localhost:9983"
  1252. echo ZK_HOST: !ZK_HOST!
  1253. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1254. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1255. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1256. org.apache.solr.util.SolrCLI healthcheck -collection !HEALTHCHECK_COLLECTION! -zkHost !ZK_HOST! %HEALTHCHECK_VERBOSE%
  1257. goto done
  1258. :run_assert
  1259. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1260. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1261. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1262. org.apache.solr.util.SolrCLI %*
  1263. if errorlevel 1 (
  1264. exit /b 1
  1265. )
  1266. goto done
  1267. :parse_config_args
  1268. IF [%1]==[] goto run_config
  1269. IF "%1"=="-z" goto set_config_zk
  1270. IF "%1"=="-zkhost" goto set_config_zk
  1271. IF "%1"=="-zkHost" goto set_config_zk
  1272. IF "%1"=="-s" goto set_config_url_scheme
  1273. IF "%1"=="-scheme" goto set_config_url_scheme
  1274. set "CONFIG_ARGS=!CONFIG_ARGS! %1"
  1275. SHIFT
  1276. goto parse_config_args
  1277. :set_config_zk
  1278. set ZK_HOST=%~2
  1279. SHIFT
  1280. SHIFT
  1281. goto parse_config_args
  1282. :set_config_url_scheme
  1283. set SOLR_URL_SCHEME=%~2
  1284. SHIFT
  1285. SHIFT
  1286. goto parse_config_args
  1287. :run_config
  1288. IF NOT "!ZK_HOST!"=="" SET "CONFIG_ARGS=!CONFIG_ARGS! -z !ZK_HOST!"
  1289. IF NOT "!SOLR_URL_SCHEME!"=="" SET "CONFIG_ARGS=!CONFIG_ARGS! -scheme !SOLR_URL_SCHEME!"
  1290. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1291. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1292. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1293. org.apache.solr.util.SolrCLI config !CONFIG_ARGS!
  1294. if errorlevel 1 (
  1295. exit /b 1
  1296. )
  1297. goto done
  1298. :get_version
  1299. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1300. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1301. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1302. org.apache.solr.util.SolrCLI version
  1303. goto done
  1304. :run_utils
  1305. set "TOOL_CMD=%~1"
  1306. set q="-q"
  1307. IF "%verbose%"=="1" set q=""
  1308. "%JAVA%" %SOLR_SSL_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1309. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1310. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1311. org.apache.solr.util.SolrCLI utils -s "%DEFAULT_SERVER_DIR%" -l "%SOLR_LOGS_DIR%" %q:"=% %TOOL_CMD%
  1312. if errorlevel 1 (
  1313. exit /b 1
  1314. )
  1315. goto done
  1316. :parse_create_args
  1317. IF [%1]==[] goto run_create
  1318. IF "%1"=="-V" goto set_create_verbose
  1319. IF "%1"=="-c" goto set_create_name
  1320. IF "%1"=="-core" goto set_create_name
  1321. IF "%1"=="-collection" goto set_create_name
  1322. IF "%1"=="-d" goto set_create_confdir
  1323. IF "%1"=="-confdir" goto set_create_confdir
  1324. IF "%1"=="-n" goto set_create_confname
  1325. IF "%1"=="-confname" goto set_create_confname
  1326. IF "%1"=="-s" goto set_create_shards
  1327. IF "%1"=="-shards" goto set_create_shards
  1328. IF "%1"=="-rf" goto set_create_rf
  1329. IF "%1"=="-replicationFactor" goto set_create_rf
  1330. IF "%1"=="-p" goto set_create_port
  1331. IF "%1"=="-port" goto set_create_port
  1332. IF "%1"=="-help" goto usage
  1333. IF "%1"=="-usage" goto usage
  1334. IF "%1"=="/?" goto usage
  1335. goto run_create
  1336. :set_create_verbose
  1337. set CREATE_VERBOSE="-verbose"
  1338. SHIFT
  1339. goto parse_create_args
  1340. :set_create_name
  1341. set CREATE_NAME=%~2
  1342. SHIFT
  1343. SHIFT
  1344. goto parse_create_args
  1345. :set_create_confdir
  1346. set CREATE_CONFDIR=%~2
  1347. SHIFT
  1348. SHIFT
  1349. goto parse_create_args
  1350. :set_create_confname
  1351. set CREATE_CONFNAME=%~2
  1352. SHIFT
  1353. SHIFT
  1354. goto parse_create_args
  1355. :set_create_port
  1356. set CREATE_PORT=%~2
  1357. SHIFT
  1358. SHIFT
  1359. goto parse_create_args
  1360. :set_create_shards
  1361. set CREATE_NUM_SHARDS=%~2
  1362. SHIFT
  1363. SHIFT
  1364. goto parse_create_args
  1365. :set_create_rf
  1366. set CREATE_REPFACT=%~2
  1367. SHIFT
  1368. SHIFT
  1369. goto parse_create_args
  1370. :run_create
  1371. IF "!CREATE_NAME!"=="" (
  1372. set "SCRIPT_ERROR=Name (-c) is a required parameter for %SCRIPT_CMD%"
  1373. goto invalid_cmd_line
  1374. )
  1375. IF NOT DEFINED CREATE_VERBOSE set "CREATE_VERBOSE="
  1376. IF "!CREATE_CONFDIR!"=="" set CREATE_CONFDIR=_default
  1377. IF "!CREATE_NUM_SHARDS!"=="" set CREATE_NUM_SHARDS=1
  1378. IF "!CREATE_REPFACT!"=="" set CREATE_REPFACT=1
  1379. IF "!CREATE_CONFNAME!"=="" set CREATE_CONFNAME=!CREATE_NAME!
  1380. REM Find a port that Solr is running on
  1381. if "!CREATE_PORT!"=="" (
  1382. for /f "usebackq" %%i in (`dir /b "%SOLR_TIP%\bin" ^| findstr /i "^solr-.*\.port$"`) do (
  1383. set SOME_SOLR_PORT=
  1384. For /F "Delims=" %%J In ('type "%SOLR_TIP%\bin\%%i"') do set SOME_SOLR_PORT=%%~J
  1385. if NOT "!SOME_SOLR_PORT!"=="" (
  1386. for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":0 " ^| find ":!SOME_SOLR_PORT! "') do (
  1387. IF NOT "%%k"=="0" set CREATE_PORT=!SOME_SOLR_PORT!
  1388. )
  1389. )
  1390. )
  1391. )
  1392. if "!CREATE_PORT!"=="" (
  1393. set "SCRIPT_ERROR=Could not find a running Solr instance on this host! Please use the -p option to specify the port."
  1394. goto err
  1395. )
  1396. if "!CREATE_CONFDIR!"=="_default" (
  1397. echo WARNING: Using _default configset with data driven schema functionality. NOT RECOMMENDED for production use.
  1398. echo To turn off: bin\solr config -c !CREATE_NAME! -p !CREATE_PORT! -action set-user-property -property update.autoCreateFields -value false
  1399. )
  1400. if "%SCRIPT_CMD%"=="create_core" (
  1401. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1402. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1403. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1404. org.apache.solr.util.SolrCLI create_core -name !CREATE_NAME! -solrUrl !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:!CREATE_PORT!/solr ^
  1405. -confdir !CREATE_CONFDIR! -configsetsDir "%SOLR_TIP%\server\solr\configsets" %CREATE_VERBOSE%
  1406. ) else (
  1407. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" -Dsolr.default.confdir="%DEFAULT_CONFDIR%"^
  1408. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1409. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1410. org.apache.solr.util.SolrCLI create -name !CREATE_NAME! -shards !CREATE_NUM_SHARDS! -replicationFactor !CREATE_REPFACT! ^
  1411. -confname !CREATE_CONFNAME! -confdir !CREATE_CONFDIR! -configsetsDir "%SOLR_TIP%\server\solr\configsets" ^
  1412. -solrUrl !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:!CREATE_PORT!/solr %CREATE_VERBOSE%
  1413. )
  1414. goto done
  1415. :parse_delete_args
  1416. IF [%1]==[] goto run_delete
  1417. IF "%1"=="-V" goto set_delete_verbose
  1418. IF "%1"=="-c" goto set_delete_name
  1419. IF "%1"=="-core" goto set_delete_name
  1420. IF "%1"=="-collection" goto set_delete_name
  1421. IF "%1"=="-p" goto set_delete_port
  1422. IF "%1"=="-port" goto set_delete_port
  1423. IF "%1"=="-deleteConfig" goto set_delete_config
  1424. IF "%1"=="-help" goto usage
  1425. IF "%1"=="-usage" goto usage
  1426. IF "%1"=="/?" goto usage
  1427. goto run_delete
  1428. :set_delete_verbose
  1429. set DELETE_VERBOSE="-verbose"
  1430. SHIFT
  1431. goto parse_delete_args
  1432. :set_delete_name
  1433. set DELETE_NAME=%~2
  1434. SHIFT
  1435. SHIFT
  1436. goto parse_delete_args
  1437. :set_delete_port
  1438. set DELETE_PORT=%~2
  1439. SHIFT
  1440. SHIFT
  1441. goto parse_delete_args
  1442. :set_delete_config
  1443. set DELETE_CONFIG=%~2
  1444. SHIFT
  1445. SHIFT
  1446. goto parse_delete_args
  1447. :run_delete
  1448. IF NOT DEFINED DELETE_VERBOSE set "DELETE_VERBOSE="
  1449. IF "!DELETE_NAME!"=="" (
  1450. set "SCRIPT_ERROR=Name (-c) is a required parameter for %SCRIPT_CMD%"
  1451. goto invalid_cmd_line
  1452. )
  1453. REM Find a port that Solr is running on
  1454. if "!DELETE_PORT!"=="" (
  1455. for /f "usebackq" %%i in (`dir /b "%SOLR_TIP%\bin" ^| findstr /i "^solr-.*\.port$"`) do (
  1456. set SOME_SOLR_PORT=
  1457. For /F "Delims=" %%J In ('type "%SOLR_TIP%\bin\%%i"') do set SOME_SOLR_PORT=%%~J
  1458. if NOT "!SOME_SOLR_PORT!"=="" (
  1459. for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":0 " ^| find ":!SOME_SOLR_PORT! "') do (
  1460. IF NOT "%%k"=="0" set DELETE_PORT=!SOME_SOLR_PORT!
  1461. )
  1462. )
  1463. )
  1464. )
  1465. if "!DELETE_PORT!"=="" (
  1466. set "SCRIPT_ERROR=Could not find a running Solr instance on this host! Please use the -p option to specify the port."
  1467. goto err
  1468. )
  1469. if "!DELETE_CONFIG!"=="" (
  1470. set DELETE_CONFIG=true
  1471. )
  1472. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1473. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1474. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1475. org.apache.solr.util.SolrCLI delete -name !DELETE_NAME! -deleteConfig !DELETE_CONFIG! ^
  1476. -solrUrl !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:!DELETE_PORT!/solr %DELETE_VERBOSE%
  1477. goto done
  1478. REM Clumsy to do the state machine thing for -d and -n, but that's required for back-compat
  1479. :parse_zk_args
  1480. IF "%1"=="-upconfig" (
  1481. goto set_zk_op
  1482. ) ELSE IF "%1"=="-V" (
  1483. goto set_zk_verbose
  1484. ) ELSE IF "%1"=="upconfig" (
  1485. goto set_zk_op
  1486. ) ELSE IF "%1"=="-downconfig" (
  1487. goto set_zk_op
  1488. ) ELSE IF "%1"=="downconfig" (
  1489. goto set_zk_op
  1490. ) ELSE IF "%1"=="cp" (
  1491. goto set_zk_op
  1492. ) ELSE IF "%1"=="mv" (
  1493. goto set_zk_op
  1494. ) ELSE IF "%1"=="rm" (
  1495. goto set_zk_op
  1496. ) ELSE IF "%1"=="ls" (
  1497. goto set_zk_op
  1498. ) ELSE IF "%1"=="mkroot" (
  1499. goto set_zk_op
  1500. ) ELSE IF "%1"=="-n" (
  1501. goto set_config_name
  1502. ) ELSE IF "%1"=="-r" (
  1503. goto set_zk_recurse
  1504. ) ELSE IF "%1"=="-configname" (
  1505. goto set_config_name
  1506. ) ELSE IF "%1"=="-d" (
  1507. goto set_configdir
  1508. ) ELSE IF "%1"=="-confdir" (
  1509. goto set_configdir
  1510. ) ELSE IF "%1"=="-z" (
  1511. goto set_config_zk
  1512. ) ELSE IF "%1"=="/?" (
  1513. goto zk_usage
  1514. ) ELSE IF "%1"=="-h" (
  1515. goto zk_usage
  1516. ) ELSE IF "%1"=="-help" (
  1517. goto zk_usage
  1518. ) ELSE IF "!ZK_SRC!"=="" (
  1519. if not "%~1"=="" (
  1520. goto set_zk_src
  1521. )
  1522. ) ELSE IF "!ZK_DST!"=="" (
  1523. IF "%ZK_OP%"=="cp" (
  1524. goto set_zk_dst
  1525. )
  1526. IF "%ZK_OP%"=="mv" (
  1527. goto set_zk_dst
  1528. )
  1529. set ZK_DST="_"
  1530. ) ELSE IF NOT "%1"=="" (
  1531. set ERROR_MSG="Unrecognized or misplaced zk argument %1%"
  1532. goto zk_short_usage
  1533. )
  1534. goto run_zk
  1535. :set_zk_op
  1536. set ZK_OP=%~1
  1537. SHIFT
  1538. goto parse_zk_args
  1539. :set_zk_verbose
  1540. set ZK_VERBOSE="-verbose"
  1541. SHIFT
  1542. goto parse_zk_args
  1543. :set_config_name
  1544. set CONFIGSET_NAME=%~2
  1545. SHIFT
  1546. SHIFT
  1547. goto parse_zk_args
  1548. :set_configdir
  1549. set CONFIGSET_DIR=%~2
  1550. SHIFT
  1551. SHIFT
  1552. goto parse_zk_args
  1553. :set_config_zk
  1554. set ZK_HOST=%~2
  1555. SHIFT
  1556. SHIFT
  1557. goto parse_zk_args
  1558. :set_zk_src
  1559. set ZK_SRC=%~1
  1560. SHIFT
  1561. goto parse_zk_args
  1562. :set_zk_dst
  1563. set ZK_DST=%~1
  1564. SHIFT
  1565. goto parse_zk_args
  1566. :set_zk_recurse
  1567. set ZK_RECURSE="true"
  1568. SHIFT
  1569. goto parse_zk_args
  1570. :run_zk
  1571. IF "!ZK_OP!"=="" (
  1572. set "ERROR_MSG=Invalid command specified for zk sub-command"
  1573. goto zk_short_usage
  1574. )
  1575. IF "!ZK_HOST!"=="" (
  1576. set "ERROR_MSG=Must specify -z zkHost"
  1577. goto zk_short_usage
  1578. )
  1579. IF "!ZK_OP!"=="-upconfig" (
  1580. set ZK_OP="upconfig"
  1581. )
  1582. IF "!ZK_OP!"=="-downconfig" (
  1583. set ZK_OP="downconfig"
  1584. )
  1585. IF "!ZK_OP!"=="upconfig" (
  1586. IF "!CONFIGSET_NAME!"=="" (
  1587. set ERROR_MSG="-n option must be set for upconfig"
  1588. goto zk_short_usage
  1589. )
  1590. IF "!CONFIGSET_DIR!"=="" (
  1591. set ERROR_MSG="The -d option must be set for upconfig."
  1592. goto zk_short_usage
  1593. )
  1594. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1595. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1596. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1597. org.apache.solr.util.SolrCLI !ZK_OP! -confname !CONFIGSET_NAME! -confdir !CONFIGSET_DIR! -zkHost !ZK_HOST! %ZK_VERBOSE%^
  1598. -configsetsDir "%SOLR_TIP%/server/solr/configsets"
  1599. ) ELSE IF "!ZK_OP!"=="downconfig" (
  1600. IF "!CONFIGSET_NAME!"=="" (
  1601. set ERROR_MSG="-n option must be set for downconfig"
  1602. goto zk_short_usage
  1603. )
  1604. IF "!CONFIGSET_DIR!"=="" (
  1605. set ERROR_MSG="The -d option must be set for downconfig."
  1606. goto zk_short_usage
  1607. )
  1608. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1609. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1610. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1611. org.apache.solr.util.SolrCLI !ZK_OP! -confname !CONFIGSET_NAME! -confdir !CONFIGSET_DIR! -zkHost !ZK_HOST! %ZK_VERBOSE%
  1612. ) ELSE IF "!ZK_OP!"=="cp" (
  1613. IF "%ZK_SRC%"=="" (
  1614. set ERROR_MSG="<src> must be specified for 'cp' command"
  1615. goto zk_short_usage
  1616. )
  1617. IF "%ZK_DST%"=="" (
  1618. set ERROR_MSG=<dest> must be specified for 'cp' command"
  1619. goto zk_short_usage
  1620. )
  1621. IF NOT "!ZK_SRC:~0,3!"=="zk:" (
  1622. IF NOT "!%ZK_DST:~0,3!"=="zk:" (
  1623. set ERROR_MSG="At least one of src or dst must be prefixed by 'zk:'"
  1624. goto zk_short_usage
  1625. )
  1626. )
  1627. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1628. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1629. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1630. org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -src !ZK_SRC! -dst !ZK_DST! -recurse !ZK_RECURSE! %ZK_VERBOSE%
  1631. ) ELSE IF "!ZK_OP!"=="mv" (
  1632. IF "%ZK_SRC%"=="" (
  1633. set ERROR_MSG="<src> must be specified for 'mv' command"
  1634. goto zk_short_usage
  1635. )
  1636. IF "%ZK_DST%"=="" (
  1637. set ERROR_MSG="<dest> must be specified for 'mv' command"
  1638. goto zk_short_usage
  1639. )
  1640. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1641. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1642. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1643. org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -src !ZK_SRC! -dst !ZK_DST! %ZK_VERBOSE%
  1644. ) ELSE IF "!ZK_OP!"=="rm" (
  1645. IF "%ZK_SRC"=="" (
  1646. set ERROR_MSG="Zookeeper path to remove must be specified when using the 'rm' command"
  1647. goto zk_short_usage
  1648. )
  1649. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1650. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1651. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1652. org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -path !ZK_SRC! -recurse !ZK_RECURSE! %ZK_VERBOSE%
  1653. ) ELSE IF "!ZK_OP!"=="ls" (
  1654. IF "%ZK_SRC"=="" (
  1655. set ERROR_MSG="Zookeeper path to remove must be specified when using the 'ls' command"
  1656. goto zk_short_usage
  1657. )
  1658. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1659. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1660. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1661. org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -path !ZK_SRC! -recurse !ZK_RECURSE! %ZK_VERBOSE%
  1662. ) ELSE IF "!ZK_OP!"=="mkroot" (
  1663. IF "%ZK_SRC"=="" (
  1664. set ERROR_MSG="Zookeeper path to create must be specified when using the 'mkroot' command"
  1665. goto zk_short_usage
  1666. )
  1667. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1668. -Dlog4j.configurationFile="file:///%SOLR_SERVER_DIR%\resources\log4j2-console.xml" ^
  1669. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1670. org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -path !ZK_SRC! %ZK_VERBOSE%
  1671. ) ELSE (
  1672. set ERROR_MSG="Unknown zk option !ZK_OP!"
  1673. goto zk_short_usage
  1674. )
  1675. goto done
  1676. :run_auth
  1677. IF "%1"=="-help" goto usage
  1678. IF "%1"=="-usage" goto usage
  1679. REM Options parsing.
  1680. REM Note: With the following technique of parsing, it is not possible
  1681. REM to have an option without a value.
  1682. set "AUTH_PARAMS=%1"
  1683. set "option="
  1684. for %%a in (%*) do (
  1685. if not defined option (
  1686. set arg=%%a
  1687. if "!arg:~0,1!" equ "-" set "option=!arg!"
  1688. ) else (
  1689. set "option!option!=%%a"
  1690. if "!option!" equ "-d" set "SOLR_SERVER_DIR=%%a"
  1691. if "!option!" equ "-s" set "SOLR_HOME=%%a"
  1692. if not "!option!" equ "-s" if not "!option!" equ "-d" (
  1693. set "AUTH_PARAMS=!AUTH_PARAMS! !option! %%a"
  1694. )
  1695. set "option="
  1696. )
  1697. )
  1698. IF "%SOLR_SERVER_DIR%"=="" set "SOLR_SERVER_DIR=%DEFAULT_SERVER_DIR%"
  1699. IF NOT EXIST "%SOLR_SERVER_DIR%" (
  1700. set "SCRIPT_ERROR=Solr server directory %SOLR_SERVER_DIR% not found!"
  1701. goto err
  1702. )
  1703. IF "%SOLR_HOME%"=="" set "SOLR_HOME=%SOLR_SERVER_DIR%\solr"
  1704. IF EXIST "%cd%\%SOLR_HOME%" set "SOLR_HOME=%cd%\%SOLR_HOME%"
  1705. IF NOT EXIST "%SOLR_HOME%\" (
  1706. IF EXIST "%SOLR_SERVER_DIR%\%SOLR_HOME%" (
  1707. set "SOLR_HOME=%SOLR_SERVER_DIR%\%SOLR_HOME%"
  1708. ) ELSE (
  1709. set "SCRIPT_ERROR=Solr home directory %SOLR_HOME% not found!"
  1710. goto err
  1711. )
  1712. )
  1713. if "!AUTH_PORT!"=="" (
  1714. for /f "usebackq" %%i in (`dir /b "%SOLR_TIP%\bin" ^| findstr /i "^solr-.*\.port$"`) do (
  1715. set SOME_SOLR_PORT=
  1716. For /F "Delims=" %%J In ('type "%SOLR_TIP%\bin\%%i"') do set SOME_SOLR_PORT=%%~J
  1717. if NOT "!SOME_SOLR_PORT!"=="" (
  1718. for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":0 " ^| find ":!SOME_SOLR_PORT! "') do (
  1719. IF NOT "%%k"=="0" set AUTH_PORT=!SOME_SOLR_PORT!
  1720. )
  1721. )
  1722. )
  1723. )
  1724. "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
  1725. -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
  1726. -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
  1727. org.apache.solr.util.SolrCLI auth %AUTH_PARAMS% -solrIncludeFile "%SOLR_INCLUDE%" -authConfDir "%SOLR_HOME%" ^
  1728. -solrUrl !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:!AUTH_PORT!/solr
  1729. goto done
  1730. :invalid_cmd_line
  1731. @echo.
  1732. IF "!SCRIPT_ERROR!"=="" (
  1733. @echo Invalid command-line option: %1
  1734. ) ELSE (
  1735. @echo ERROR: !SCRIPT_ERROR!
  1736. )
  1737. @echo.
  1738. IF "%FIRST_ARG%"=="start" (
  1739. goto start_usage
  1740. ) ELSE IF "%FIRST_ARG:~0,1%" == "-" (
  1741. goto start_usage
  1742. ) ELSE IF "%FIRST_ARG%"=="restart" (
  1743. goto start_usage
  1744. ) ELSE IF "%FIRST_ARG%"=="stop" (
  1745. goto stop_usage
  1746. ) ELSE IF "%FIRST_ARG%"=="healthcheck" (
  1747. goto healthcheck_usage
  1748. ) ELSE IF "%FIRST_ARG%"=="create" (
  1749. goto create_usage
  1750. ) ELSE IF "%FIRST_ARG%"=="create_core" (
  1751. goto create_core_usage
  1752. ) ELSE IF "%FIRST_ARG%"=="create_collection" (
  1753. goto create_collection_usage
  1754. ) ELSE IF "%FIRST_ARG%"=="zk" (
  1755. goto zk_short_usage
  1756. ) ELSE IF "%FIRST_ARG%"=="auth" (
  1757. goto auth_usage
  1758. ) ELSE IF "%FIRST_ARG%"=="status" (
  1759. goto status_usage
  1760. ) ELSE (
  1761. goto script_usage
  1762. )
  1763. :need_java_home
  1764. @echo Please set the JAVA_HOME environment variable to the path where you installed Java 1.8+
  1765. goto done
  1766. :need_java_vers
  1767. @echo Java 1.8 or later is required to run Solr.
  1768. goto done
  1769. :err
  1770. @echo.
  1771. @echo ERROR: !SCRIPT_ERROR!
  1772. @echo.
  1773. exit /b 1
  1774. :done
  1775. ENDLOCAL
  1776. exit /b 0
  1777. REM Tests what Java we have and sets some global variables
  1778. :resolve_java_info
  1779. CALL :resolve_java_vendor
  1780. set JAVA_MAJOR_VERSION=0
  1781. set JAVA_VERSION_INFO=
  1782. set JAVA_BUILD=0
  1783. FOR /f "usebackq tokens=3" %%a IN (`^""%JAVA%" -version 2^>^&1 ^| findstr "version"^"`) do (
  1784. set JAVA_VERSION_INFO=%%a
  1785. REM Remove surrounding quotes
  1786. set JAVA_VERSION_INFO=!JAVA_VERSION_INFO:"=!
  1787. REM Extract the major Java version, e.g. 7, 8, 9, 10 ...
  1788. for /f "tokens=1,2 delims=._-" %%a in ("!JAVA_VERSION_INFO!") do (
  1789. if %%a GEQ 9 (
  1790. set JAVA_MAJOR_VERSION=%%a
  1791. ) else (
  1792. set JAVA_MAJOR_VERSION=%%b
  1793. )
  1794. )
  1795. REM Don't look for "_{build}" if we're on IBM J9.
  1796. if NOT "%JAVA_VENDOR%" == "IBM J9" (
  1797. for /f "delims=_ tokens=2" %%a in ("!JAVA_VERSION_INFO!") do (
  1798. set /a JAVA_BUILD=%%a
  1799. )
  1800. )
  1801. )
  1802. GOTO :eof
  1803. REM Set which JVM vendor we have
  1804. :resolve_java_vendor
  1805. "%JAVA%" -version 2>&1 | findstr /i "IBM J9" > nul
  1806. if %ERRORLEVEL% == 1 ( set "JAVA_VENDOR=Oracle" ) else ( set "JAVA_VENDOR=IBM J9" )
  1807. set JAVA_VENDOR_OUT=
  1808. GOTO :eof
  1809. REM Safe echo which does not mess with () in strings
  1810. :safe_echo
  1811. set "eout=%1"
  1812. set eout=%eout:"=%
  1813. echo !eout!
  1814. GOTO :eof