docker-entrypoint.sh 4.7 KB

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