docker-entrypoint.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #!/bin/bash
  2. if [[ "${SKIP_SOLR}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
  3. echo "SKIP_SOLR=y, skipping Solr..."
  4. sleep 365d
  5. exit 0
  6. fi
  7. MEM_TOTAL=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
  8. if [[ "${1}" != "--bootstrap" ]]; then
  9. if [ ${MEM_TOTAL} -lt "2097152" ]; then
  10. echo "System memory less than 2 GB, skipping Solr..."
  11. sleep 365d
  12. exit 0
  13. fi
  14. fi
  15. set -e
  16. # allow easier debugging with `docker run -e VERBOSE=yes`
  17. if [[ "$VERBOSE" = "yes" ]]; then
  18. set -x
  19. fi
  20. # run the optional initdb
  21. . /opt/docker-solr/scripts/run-initdb
  22. function solr_config() {
  23. curl -XPOST http://localhost:8983/solr/dovecot/schema -H 'Content-type:application/json' -d '{
  24. "add-field-type":{
  25. "name":"long",
  26. "class":"solr.TrieLongField"
  27. },
  28. "add-field-type":{
  29. "name":"text",
  30. "class":"solr.TextField",
  31. "positionIncrementGap":100,
  32. "indexAnalyser":{
  33. "tokenizer":{
  34. "class":"solr.StandardTokenizerFactory"
  35. },
  36. "filter":{
  37. "class":"solr.WordDelimiterFilterFactory",
  38. "generateWordParts":1,
  39. "generateNumberParts":1,
  40. "catenateWorks":1,
  41. "catenateNumbers":1,
  42. "catenateAll":0
  43. },
  44. "filter":{
  45. "class":"solr.LowerCaseFilterFactory"
  46. },
  47. "filter":{
  48. "class":"solr.KeywordMarkerFilterFactory",
  49. "protected":"protwords.txt"
  50. }
  51. },
  52. "queryAnalyzer":{
  53. "tokenizer":{
  54. "class":"solr.StandardTokenizerFactory"
  55. },
  56. "filter":{
  57. "synonyms":"synonyms.txt",
  58. "ignoreCase":true,
  59. "expand":true
  60. },
  61. "filter":{
  62. "class":"solr.LowerCaseFilterFactory"
  63. },
  64. "filter":{
  65. "class":"solr.WordDelimiterFilterFactory",
  66. "generateWordParts":1,
  67. "generateNumberParts":1,
  68. "catenateWords":0,
  69. "catenateNumbers":0,
  70. "catenateAll":0,
  71. "splitOnCaseChange":1
  72. }
  73. }
  74. },
  75. "add-field":{
  76. "name":"uid",
  77. "type":"long",
  78. "indexed":true,
  79. "stored":true,
  80. "required":true
  81. },
  82. "add-field":{
  83. "name":"box",
  84. "type":"string",
  85. "indexed":true,
  86. "stored":true,
  87. "required":true
  88. },
  89. "add-field":{
  90. "name":"user",
  91. "type":"string",
  92. "indexed":true,
  93. "stored":true,
  94. "required":true
  95. },
  96. "add-field":{
  97. "name":"hdr",
  98. "type":"text",
  99. "indexed":true,
  100. "stored":false
  101. },
  102. "add-field":{
  103. "name":"body",
  104. "type":"text",
  105. "indexed":true,
  106. "stored":false
  107. },
  108. "add-field":{
  109. "name":"from",
  110. "type":"text",
  111. "indexed":true,
  112. "stored":false
  113. },
  114. "add-field":{
  115. "name":"to",
  116. "type":"text",
  117. "indexed":true,
  118. "stored":false
  119. },
  120. "add-field":{
  121. "name":"cc",
  122. "type":"text",
  123. "indexed":true,
  124. "stored":false
  125. },
  126. "add-field":{
  127. "name":"bcc",
  128. "type":"text",
  129. "indexed":true,
  130. "stored":false
  131. },
  132. "add-field":{
  133. "name":"subject",
  134. "type":"text",
  135. "indexed":true,
  136. "stored":false
  137. }
  138. }'
  139. curl -XPOST http://localhost:8983/solr/dovecot/config -H 'Content-type:application/json' -d '{
  140. "update-requesthandler":{
  141. "name":"/select",
  142. "class":"solr.SearchHandler",
  143. "defaults":{
  144. "wt":"xml"
  145. }
  146. }
  147. }'
  148. curl -XPOST http://localhost:8983/solr/dovecot/config/updateHandler -d '{
  149. "set-property": {
  150. "updateHandler.autoSoftCommit.maxDocs":500,
  151. "updateHandler.autoSoftCommit.maxTime":120000,
  152. "updateHandler.autoCommit.maxDocs":200,
  153. "updateHandler.autoCommit.maxTime":1800000,
  154. "updateHandler.autoCommit.openSearcher":false
  155. }
  156. }'
  157. }
  158. # fixing volume permission
  159. [[ -d /opt/solr/server/solr/dovecot/data ]] && chown -R solr:solr /opt/solr/server/solr/dovecot/data
  160. if [[ "${1}" != "--bootstrap" ]]; then
  161. sed -i '/SOLR_HEAP=/c\SOLR_HEAP="'${SOLR_HEAP:-1024}'m"' /opt/solr/bin/solr.in.sh
  162. else
  163. sed -i '/SOLR_HEAP=/c\SOLR_HEAP="256m"' /opt/solr/bin/solr.in.sh
  164. fi
  165. # start a Solr so we can use the Schema API, but only on localhost,
  166. # so that clients don't see Solr until we have configured it.
  167. echo "Starting local Solr instance to setup configuration"
  168. su-exec solr start-local-solr
  169. # keep a sentinel file so we don't try to create the core a second time
  170. # for example when we restart a container.
  171. SENTINEL=/opt/docker-solr/core_created
  172. if [[ -f ${SENTINEL} ]]; then
  173. echo "skipping core creation"
  174. else
  175. echo "Creating core \"dovecot\""
  176. su-exec solr /opt/solr/bin/solr create -c "dovecot"
  177. # See https://github.com/docker-solr/docker-solr/issues/27
  178. echo "Checking core"
  179. while ! wget -O - 'http://localhost:8983/solr/admin/cores?action=STATUS' | grep -q instanceDir; do
  180. echo "Could not find any cores, waiting..."
  181. sleep 5
  182. done
  183. echo "Created core \"dovecot\""
  184. touch ${SENTINEL}
  185. fi
  186. echo "Starting configuration"
  187. solr_config
  188. echo "Stopping local Solr"
  189. su-exec solr stop-local-solr
  190. if [[ "${1}" == "--bootstrap" ]]; then
  191. exit 0
  192. else
  193. exec su-exec solr solr-foreground
  194. fi