reindexdovecot script

From elyograg, 1 Year ago, written in Bash, viewed 128 times. This paste will slip away in 1 Second.
URL https://paste.elyograg.org/view/74accd23 Embed
Download Paste or View Raw
  1. #!/bin/sh
  2.  
  3. SOLR_HOST=solr.elyograg.org
  4. SOLR_PORT=443
  5. SOLR_SCHEME=https
  6. INDEX_NAME="dovecot"
  7. #SOLR_COLLECTION="dovecot_2023_03"
  8.  
  9. ##########################
  10. # DO NOT MODIFY BELOW
  11. # WITHOUT GOOD REASON
  12. #
  13. SOLR_URL_BASE="${SOLR_SCHEME}://${SOLR_HOST}:${SOLR_PORT}/solr"
  14. DOVECOT_SOLR_UPDATE_URL="${SOLR_URL_BASE}/${INDEX_NAME}"
  15. ZK_SOLR_URL="${SOLR_URL_BASE}/admin/zookeeper"
  16. CORE_ADMIN_SOLR_URL="${SOLR_URL_BASE}/admin/cores"
  17. COLLECTIONS_ADMIN_SOLR_URL="${SOLR_URL_BASE}/admin/collections"
  18. DEL_ALL_QUERY_XML="<delete><query>*:*</query></delete>"
  19. CLOUD=""
  20.  
  21. echo "=== Stopping dovecot"
  22. sudo service dovecot stop
  23.  
  24. echo -n "=== TESTING FOR CLOUD..."
  25. for i in 1 2 3 4
  26. do
  27.   curl -m 2 -s -f "${ZK_SOLR_URL}" > /dev/null
  28.   RET="$?"
  29.   if [ "$RET" -eq 0 ]; then
  30.     CLOUD="true"
  31.     echo -n " Cloud detected"
  32.     RESPONSE="$(curl -s "${COLLECTIONS_ADMIN_SOLR_URL}?action=CLUSTERSTATUS&wt=json")"
  33.     SOLR_COLLECTION="$(echo "$RESPONSE" | jq -r ".cluster.aliases.\"${INDEX_NAME}\"")"
  34.     if [ -z "${SOLR_COLLECTION}" ]; then
  35.       SOLR_COLLECTION="${INDEX_NAME}"
  36.     fi
  37.     break
  38.   else
  39.     sleep 5
  40.   fi
  41. done
  42. echo
  43.  
  44. RET="1"
  45. for i in 1 2 3 4
  46. do
  47.   echo "=== Attempt ${i} of index wipe"
  48.   curl -m 2 -f -s \
  49.     "${DOVECOT_SOLR_UPDATE_URL}/update?commit=true&optimize=true&wt=json" \
  50.       -H "Content-Type: text/xml" \
  51.       --data-binary "${DEL_ALL_QUERY_XML}"
  52.   RET="$?"
  53.   if [ "${RET}" -eq 0 ]; then
  54.     break
  55.   fi
  56.   sleep 5
  57. done
  58. echo
  59.  
  60. ABORT_REBUILD=""
  61. if [ "${RET}" -ne 0 ]; then
  62.   echo "===== Wipe failed!  Aborting."
  63.   ABORT_REBUILD="true"
  64. fi
  65.  
  66. if [ -z "${ABORT_REBUILD}" ]; then
  67.   RET="1"
  68.   for i in 1 2 3 4
  69.   do
  70.     echo "=== Attempt ${i} of index reload"
  71.     if [ -z "${CLOUD}" ]; then
  72.       curl -m 2 -f -s \
  73.         "${CORE_ADMIN_SOLR_URL}?action=RELOAD&core=${INDEX_NAME}&wt=json"
  74.       RET="$?"
  75.     else
  76.       curl -m 2 -f -s \
  77.         "${COLLECTIONS_ADMIN_SOLR_URL}?action=RELOAD&name=${SOLR_COLLECTION}&wt=json"
  78.       RET="$?"
  79.     fi
  80.     if [ "${RET}" -eq 0 ]; then
  81.       break
  82.     fi
  83.     sleep 1
  84.   done
  85.   echo
  86.  
  87.   if [ "${RET}" -ne 0 ]; then
  88.     echo "----- Reload failed! Continuing anyway."
  89.   fi
  90. fi
  91.  
  92. echo "=== Starting dovecot"
  93. sudo service dovecot start
  94.  
  95. if [ -z "${ABORT_REBUILD}" ]; then
  96.   echo "--- force-resync"
  97.   sudo doveadm force-resync -A '*'
  98.   echo "--- fts rescan"
  99.   sudo doveadm fts rescan -A
  100.   echo "--- fts index"
  101.   sudo doveadm index -A -q '*'
  102.   echo "=== Now reindexing"
  103. fi
  104.  

Reply to "reindexdovecot script"

Here you can reply to the paste above