Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | if [[ "${SKIP_SOLR}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then |
| 4 | echo "SKIP_SOLR=y, skipping Solr..." |
| 5 | sleep 365d |
| 6 | exit 0 |
| 7 | fi |
| 8 | |
| 9 | MEM_TOTAL=$(awk '/MemTotal/ {print $2}' /proc/meminfo) |
| 10 | |
| 11 | if [[ "${1}" != "--bootstrap" ]]; then |
| 12 | if [ ${MEM_TOTAL} -lt "2097152" ]; then |
| 13 | echo "System memory less than 2 GB, skipping Solr..." |
| 14 | sleep 365d |
| 15 | exit 0 |
| 16 | fi |
| 17 | fi |
| 18 | |
| 19 | set -e |
| 20 | |
| 21 | # run the optional initdb |
| 22 | . /opt/docker-solr/scripts/run-initdb |
| 23 | |
| 24 | # fixing volume permission |
| 25 | [[ -d /opt/solr/server/solr/dovecot-fts/data ]] && chown -R solr:solr /opt/solr/server/solr/dovecot-fts/data |
| 26 | if [[ "${1}" != "--bootstrap" ]]; then |
| 27 | sed -i '/SOLR_HEAP=/c\SOLR_HEAP="'${SOLR_HEAP:-1024}'m"' /opt/solr/bin/solr.in.sh |
| 28 | else |
| 29 | sed -i '/SOLR_HEAP=/c\SOLR_HEAP="256m"' /opt/solr/bin/solr.in.sh |
| 30 | fi |
| 31 | |
| 32 | if [[ "${1}" == "--bootstrap" ]]; then |
| 33 | echo "Creating initial configuration" |
| 34 | echo "Modifying default config set" |
| 35 | cp /solr-config-7.7.0.xml /opt/solr/server/solr/configsets/_default/conf/solrconfig.xml |
| 36 | cp /solr-schema-7.7.0.xml /opt/solr/server/solr/configsets/_default/conf/schema.xml |
| 37 | rm /opt/solr/server/solr/configsets/_default/conf/managed-schema |
| 38 | |
| 39 | echo "Starting local Solr instance to setup configuration" |
| 40 | gosu solr start-local-solr |
| 41 | |
| 42 | echo "Creating core \"dovecot-fts\"" |
| 43 | gosu solr /opt/solr/bin/solr create -c "dovecot-fts" |
| 44 | |
| 45 | # See https://github.com/docker-solr/docker-solr/issues/27 |
| 46 | echo "Checking core" |
| 47 | while ! wget -O - 'http://localhost:8983/solr/admin/cores?action=STATUS' | grep -q instanceDir; do |
| 48 | echo "Could not find any cores, waiting..." |
| 49 | sleep 3 |
| 50 | done |
| 51 | |
| 52 | echo "Created core \"dovecot-fts\"" |
| 53 | |
| 54 | echo "Stopping local Solr" |
| 55 | gosu solr stop-local-solr |
| 56 | |
| 57 | exit 0 |
| 58 | fi |
| 59 | |
| 60 | exec gosu solr solr-foreground |
| 61 | |