jira automated ReIndex script for version 5 and later


I have the reindex script configured to fire the reindex process on Jira 4.4 and it works nice.

It is based on something similar to this one: https://answers.atlassian.com/questions/92800/activating-jira-indexing-via-script

# This script detects if Jira is suggesting a re-index is necessary
# and triggers it if this is the case.
# This script is designed to be run from cron

THISPROC=`basename $0` # Set our name to the called command name
echo "[$THISPROC - Version 1.02 - 28-Mar-2012]" | tee ${MAILFILE}
echo " " | tee ${MAILFILE}

if [[ ${1} == "" ]]; then
        echo "Need to specify Jira hostname"  | tee -a ${MAILFILE}
        rm $MAILFILE


COOKIE="/tmp/jiracoookie-$(date +%s)"
PASSWORD=$(grep ${JIRA_URL} ~/.netrc | cut -f6 -d" ")

echo "$(hostname): Starting Jira reindex $(date)" >> ${MAILFILE}
echo " "  >> ${MAILFILE}

RESULT=$(curl -s -n --cookie-jar ${COOKIE} ${PROJECT_PAGE_URL} | grep "It is recommended that you perform a re-index")

if [[ ${RESULT} != "" ]]; then
   echo "                  *  Re-index required - starting that now  *" >> ${MAILFILE}
   # Set the web sudo token
   curl -s -n --cookie ${COOKIE} -d "webSudoPassword=${PASSWORD}" $WEBSUDO_PAGE_URL
   # Kick off the re-index
   curl -s -n --cookie ${COOKIE} --header "X-Atlassian-Token: no-check" -d "indexPathOption=DEFAULT" -d "Re-Index=Re-Index" -d "indexPath=" --output /dev/null ${INDEX_PAGE_URL}
   echo "                     No need to re-index this time" >> ${MAILFILE}

cat ${MAILFILE} | mail -s "Jira re-index script - ${JIRA_URL}" ${MAIL_USERS}

This scripts perfectly detects if it necessary to Reindex instance for both Jira 4.4 and Jira 5.2.8 versions but it is failing to start ReIndex process on Jira 5.2.8.

I even tried to add the " -d "indexingStrategy=1" " option for Backround Index in Jira 5 but it does not help at all.

curl -s -n --cookie ${COOKIE} --header "X-Atlassian-Token: no-check" -d "indexPathOption=DEFAULT" -d "Re-Index=Re-Index" -d "indexPath=" --output /dev/null ${INDEX_PAGE_URL}

Does anyone done this and got working script?



3 answers

1 accepted

This widget could not be displayed.

Hi Timothy

Here is the part of curl output where it says about reindexing:

<p>Jira made configuration changes in section 'Plugins' at 20/May/13 9:46 AM. It is recommended that you perform a re-index. For more information, please click the Help icon.<p>To perform the re-index now, please go to the '<a href='/secure/admin/jira/IndexAdmin.jspa'>Indexing</a>' section.<p>Note: So that you only have to re-index once, you may wish to complete any other configuration changes before performing the re-index.</div>

The problem is that Reindexing is changed in Jira 5 and it supports background option.

The script is normally detects that reindexing required but can't kick off the reindex ....



This widget could not be displayed.
Timothy Chin Community Champion May 18, 2013

Why don't you print out the result of the curl for the page. Does it really print out the "It is recommended that you perform a re-index" text?

This widget could not be displayed.

From JIRA 6.1 onwards there is a much simpler way to trigger a re-index - by using the REST API:


Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

50 views 0 1
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you