Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Activating JIRA Indexing via Script

David Hoffman October 3, 2012

I need to know if there is any way to trigger indexing on Jira 3.13.4 via Curl / WGET.

I preface this with saying I have not even tried, but I am under a timeline and wanted to at least get the question out there before I start researching in case there is a known solution.

Thanks in advance.

18 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

6 votes
Jason Hensler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 6, 2012

Updates:

  • 07/23/2015 - Moved Files to github Repo for easier management. https://github.com/jasonhensler/Atlassian-Scripts/ 
    reindex.sh was rewritten to include changes from @Chris Solgat and other cleanup/features.
  • 1/22/2015 - Added shell script for JIRA 6.1+, no dependencies runs an a new RHEL6 vm.
  • 11/6/2013 - Added checking every 10secs for progress of re-index, script exits at 100%. Tested with Jira 5.2.4 and 6.0.7 For @Sean Edwards
LucasA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 3, 2013

Good shot, Jason. :)

Pauline Cheung December 13, 2013

Thank you! Works great!

AlfrescoG April 7, 2014

We implemented this script on RHEL6 as well, working against Jira 6.1.7 .

Nice job, thanks!

Christopher Pence May 27, 2015

Can confirm that the reindex.sh script is still working on RHEL 7 and Jira 6.4.x

Jason Hensler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 27, 2015

Yes and No. I cannot attest to RHEL 7 support as we are still on RHEL6 but, the shell script was written with bash as shell and curl as the only dependence so, I would expect it to run from any distro or proably even cygwin. Version 6.4.x changed the rest-api to return a taskid and progress url. The script will work with 6.4 to start an index but, cannot monitor progress as of now. Additionally, as pointed out by @Chris Solgat they added an acknowledge url return as well to clear the notice in Jira gui that an index has completed. I have made code changes and am testing now. I will update later today with a new shell script.

Christopher Pence May 27, 2015

I ran the script earlier after tailoring it to our system and it is still getting the status and reporting it to the console every 5 seconds as the script was designed to do. So far even with the updates to rest and whatnot this script is still fully functional on our current RHEL 7/Jira 6.4.x instance that we have setup. Updating the script will be nice to take advantage of new functionality but for anyone reading this thread that needs to get something up and running quickly can still use this script. Good work on it and have a great day!

Omprakash Thamsetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 25, 2016

Jason Hensler  have you modified the perl script to do the acknowledge the re-index in PERL script. I saw Chris Solgat has that code shell script but looking same in perl in your script. Can you help me on that piece of code?

Kevin Dalton March 28, 2018

Have you updated this for JDC 7+?

Can it push the index to the other nodes in the cluster?

Chris Solgat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 3, 2018

We have updated our script for JIRA Software 7.1, JIRA Software 7.3.1, and JIRA Software 7.6.1.  The code itself didn't really change, but the parsing of the http responses did.  They added a couple extra fields to the http response, so the cutting/parsing of the response does need to be updated.

Yasith Tharindu December 2, 2018

Chris, would you mind posting the changed portions of the script here? It will save some time for JIRA later versions.

3 votes
Chris Solgat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 28, 2015

@Jason Hensler

I have taken your bash script and made a few modifications to it. Hopefully it will help someone else. I have tested this on JIRA 6.3.15 and it seems to work very well.
I'm not sure when they made the change that each re-index would get a unique task id, but this helps with that as well. I've been running into an issue in my environment where it seems as though a connection is not closing. I think it's been coming from the re-indexing being run by a script. When you run it through the UI, after it completes, there is an Acknowledge button that appears. I've asked around a little, and was told that this is essentially an insignificant piece. In JIRA 6.3.15, if you know what the re-indexing task id was, you can go back and view the re-indexing complete page, long after it has completed. You can even run other re-index tasks and still go back to a page 5 re-indexes ago, if the task was never acknowledged. After it has been acknowledged, you will get a "Task not found" error if you try to access the page again. This leads me to believe that it's holding onto something more than nothing. Anyways, I have a support ticket open looking into this specifically. In the mean time, I have modified the script to handle the Acknowledgement, as well as provide a little bit of logging information.

 

#!/bin/sh
LOG_FILE="{path to your log directory}/log/reindex.log"
exec 3>&1 1>>${LOG_FILE} 2>&1
 
username="username"
password="pass"
server="https://jira:port/jira"
background=false
monitor=true
debug=0
echo 
echo "$(date +%Y-%m-%d_%T) Kicking off re-index..."
if [[ "$background" == "true" ]]; then
        output=`curl -D- -s -S -k -u $username:$password -X POST -H "Content-Type: application/json" "${server}/rest/api/2/reindex"`
        if [[ $? != 0 ]]; then
                echo Looks like curl failed with exit code $?: $!
                exit 1
        fi
        
        echo "$(date +%Y-%m-%d_%T) Logged in and started a Background re-index..."
else
        output=`curl -D- -s -S -k -u $username:$password -X POST -H "Content-Type: application/json" "${server}/rest/api/2/reindex?type=FOREGROUND"`
        if [[ $? != 0 ]]; then
                echo Looks like curl failed with exit code $?: $!
                exit 1
        fi
        
        echo "$(date +%Y-%m-%d_%T) Logged in and started a Foreground re-index..."
fi
if [[ $debug == 1 ]]; then
        echo ------------------- Http raw response ---------------------------
        echo $output
        echo ------------------- ---------------------------
fi
until [[ $progress -eq 100 || "$monitor" != "true" ]]
do
        sleep 5
        output=`curl -s -S -k -u $username:$password -X GET -H "Content-Type: application/json" "${server}/rest/api/2/reindex" `
        if [[ $debug == 1 ]]; then
                echo ------------------- Http raw response ---------------------------
                echo $output
                echo ------------------- ---------------------------
        fi
        progress=`echo $output | cut -d "," -f 2 | cut -d ":" -f 2`
        if [ "$oldprog" != "$progress" ]; then
            taskid=`echo $output | cut -d "," -f 1 | cut -d ":" -f 2 | cut -d "=" -f 2 | awk '{ print substr( $0, 0, 5) }'`
            success=`echo $output | cut -d "," -f 7 | cut -d ":" -f 2 | cut -d "}" -f 1`
            acknowledge="${server}/secure/admin/jira/AcknowledgeTask.jspa?taskId=${taskid}&destinationURL=%2Fsecure%2Fadmin%2Fjira%2FIndexAdmin.jspa%3FreindexTime%3D246&Acknowledge=Acknowledge&atl_token=${atl_token}"
            echo "$(date +%Y-%m-%d_%T) Index is at ${progress}%..."
        fi
        oldprog=$progress
done
echo "$(date +%Y-%m-%d_%T) Task ID is ${taskid}"
echo "$(date +%Y-%m-%d_%T) Success of re-index is ${success}"
if [[ $success = "true" && $progress -eq 100 ]]; then
    echo "$(date +%Y-%m-%d_%T) Re-index completed Successfully, sending Acknowledgement."
    #echo "Acknowledge URL is ${acknowledge}"
    output=`curl -s -S -k -u $username:$password -X GET -H "X-Atlassian-Token: no-check" -H "Content-Type:  text/html" "${acknowledge}"`
    if [[ $? != 0 ]]; then
                echo Looks like curl failed with exit code $?: $!
                exit 1
    fi
    echo "$(date +%Y-%m-%d_%T) Successfully Acknowledged."
    if [[ $debug == 1 ]]; then
            echo ------------------- Http raw response ---------------------------
            echo $output
            echo ------------------- ---------------------------
    fi
fi
exit 0
Jeanne Howe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2015

@Chris Solgat Chris, I am trying to configure your script to run in my environment. I am running into an error on how the date is parsed (I think). Here is what I am seeing: 2015-07-22_13:39:12 Index is at \"PM\"]%... ./reindex.sh: line 35: [[: \"PM\"]: syntax error: operand expected (error token is "\"PM\"]") I am not very familiar with parsing. Can you give me any help?

Chris Solgat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2015

@Jeanne Howe Did you try running Jason's script. If Jason's does not work for you, it could be the shell that you're using. If you're failing on line 35, it looks like its actually failing on the "progress" variable, not the time. Try Jason's and let me know.

Jason Hensler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2015

Could you change "debug=0" to "debug=1" and post the output. It looks like the script is picking up the timestamp for the progress variable and the shell is bailing out.

Jeanne Howe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2015

Jason, Chris It is bailing on the progress variable. Here is what the debug out put looks like {code} 2015-07-22_15:58:16 Kicking off re-index... 2015-07-22_15:58:16 Logged in and started a Background re-index... ------------------- Http raw response --------------------------- <html> <head> <title>Unauthorized (401)</title> <!--[if IE]><![endif]--> <script type="text/javascript">var contextPath = '';</script> <script> window.WRM=window.WRM||{};window.WRM._unparsedData=window.WRM._unparsedData||{}; WRM._unparsedData["com.atlassian.plugins.atlassian-plugins-webresource-plugin:context-path.context-path"]="\"\""; WRM._unparsedData["jira.webresources:dateFormatProvider.dateFormat"]="{\"meridiem\":[\"AM\",\"PM\"],\"eras\":[\"BC\",\"AD\"],\"months\":[\"January\",\"February\",\"March\",\"April\",\"May\",\"June\",\"July\",\"August\",\"September\",\"October\",\"November\",\"December\"],\"monthsShort\":[\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\",\"Jul\",\"Aug\",\"Sep\",\"Oct\",\"Nov\",\"Dec\"],\"weekdaysShort\":[\"Sun\",\"Mon\",\"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\"],\"weekdays\":[\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"]}"; WRM._unparsedData["com.atlassian.jira.ext.calendar:tipDataProvider.tip"]="{\"suppressTip\":false}"; WRM._unparsedData["com.atlassian.jira.jira-header-plugin:dismissedFlags.flags"]="{\"dismissed\":[]}"; WRM._unparsedData["com.atlassian.jira.jira-header-plugin:newsletter-signup-tip.newsletterSignup"]="{\"formUrl\":\"https://www.atlassian.com/apis/exact-target/{0}/subscribe?mailingListId=1239131\",\"showNewsletterTip\":false}"; WRM._unparsedData["com.atlassian.jira.plugins.greenhopper-marketing-plugin:gh-advertising-resources.urls"]="{\"hamlet\":\"https://hamlet.atlassian.com/\",\"lasso\":\"https://id.atlassian.com/\",\"mac\":\"https://my.atlassian.com\"}"; WRM._unparsedData["com.atlassian.jira.plugins.jira-admin-helper-plugin:notification-event-provider.notification-event-data"]="[{\"id\":1,\"name\":\"Issue Created\",\"isDefault\":true},{\"id\":2,\"name\":\"Issue Updated\"},{\"id\":3,\"name\":\"Issue Assigned\"},{\"id\":4,\"name\":\"Issue Resolved\"},{\"id\":5,\"name\":\"Issue Closed\"},{\"id\":6,\"name\":\"Issue Commented\"},{\"id\":14,\"name\":\"Issue Comment Edited\"},{\"id\":17,\"name\":\"Issue Comment Deleted\"},{\"id\":7,\"name\":\"Issue Reopened\"},{\"id\":8,\"name\":\"Issue Deleted\"},{\"id\":9,\"name\":\"Issue Moved\"},{\"id\":10,\"name\":\"Work Logged On Issue\"},{\"id\":11,\"name\":\"Work Started On Issue\"},{\"id\":12,\"name\":\"Work Stopped On Issue\"},{\"id\":15,\"name\":\"Issue Worklog Updated\"},{\"id\":16,\"name\":\"Issue Worklog Deleted\"},{\"id\":13,\"name\":\"Generic Event\"},{\"id\":10001,\"name\":\"event.type.jemhpost-creationevent.name\"}]"; WRM._unparsedData["com.atlassian.jira.plugins.jira-admin-helper-plugin:permissions-provider.permissions-data"]="[{\"permissions\":[{\"name\":\"Administer Projects\",\"id\":\"23\"},{\"name\":\"Browse Projects\",\"id\":\"10\"},{\"name\":\"View Development Tools\",\"id\":\"29\"},{\"name\":\"View Read-Only Workflow\",\"id\":\"45\"}],\"name\":\"Project Permissions\"},{\"permissions\":[{\"name\":\"Create Issues\",\"id\":\"11\"},{\"name\":\"Edit Issues\",\"id\":\"12\"},{\"name\":\"Transition Issues\",\"id\":\"46\"},{\"name\":\"Schedule Issues\",\"id\":\"28\"},{\"name\":\"Move Issues\",\"id\":\"25\"},{\"name\":\"Assign Issues\",\"id\":\"13\"},{\"name\":\"Assignable User\",\"id\":\"17\"},{\"name\":\"Resolve Issues\",\"id\":\"14\"},{\"name\":\"Close Issues\",\"id\":\"18\"},{\"name\":\"Modify Reporter\",\"id\":\"30\"},{\"name\":\"Delete Issues\",\"id\":\"16\"},{\"name\":\"Link Issues\",\"id\":\"21\"},{\"name\":\"Set Issue Security\",\"id\":\"26\"}],\"name\":\"Issue Permissions\"},{\"permissions\":[{\"name\":\"View Voters and Watchers\",\"id\":\"31\"},{\"name\":\"Manage Watchers\",\"id\":\"32\"}],\"name\":\"Voters & Watchers Permissions\"},{\"permissions\":[{\"name\":\"Add Comments\",\"id\":\"15\"},{\"name\":\"Edit All Comments\",\"id\":\"34\"},{\"name\":\"Edit Own Comments\",\"id\":\"35\"},{\"name\":\"Delete All Comments\",\"id\":\"36\"},{\"name\":\"Delete Own Comments\",\"id\":\"37\"}],\"name\":\"Comments Permissions\"},{\"permissions\":[{\"name\":\"Create Attachments\",\"id\":\"19\"},{\"name\":\"Delete All Attachments\",\"id\":\"38\"},{\"name\":\"Delete Own Attachments\",\"id\":\"39\"}],\"name\":\"Attachments Permissions\"},{\"permissions\":[{\"name\":\"Work On Issues\",\"id\":\"20\"},{\"name\":\"Edit Own Worklogs\",\"id\":\"40\"},{\"name\":\"Edit All Worklogs\",\"id\":\"41\"},{\"name\":\"Delete Own Worklogs\",\"id\":\"42\"},{\"name\":\"Delete All Worklogs\",\"id\":\"43\"}],\"name\":\"Time Tracking Permissions\"}]"; WRM._unparsedData["com.atlassian.jira.plugins.jira-dnd-attachment-plugin:drag-and-drop-attachment-javascript.upload-limit"]="\"304857600\""; WRM._unparsedData["com.atlassian.plugins.browser.metrics.browser-metrics-plugin:browser-metrics.feature-data-provider-legacy"]="true"; WRM._unparsedData["com.atlassian.plugins.helptips.jira-help-tips:common.JiraHelpTipData"]="{\"anonymous\":true}"; WRM._unparsedData["com.atlassian.plugins.jira-html5-attach-images:jira-html5-attach-images-resources.resource-uris"]="{\"deployJava.html\":\"/s/en_US9gafw3/64020/104/1.5.27/_/download/resources/com.atlassian.plugins.jira-html5-attach-images:jira-html5-attach-images-resources/deployJava.html\",\"clipboard.jar\":\"/s/en_US9gafw3/64020/104/1.5.27/_/download/resources/com.atlassian.plugins.jira-html5-attach-images:jira-html5-attach-images-resources/clipboard.jar\",\"clipboard-legacy.jar\":\"/s/en_US9gafw3/64020/104/1.5.27/_/download/resources/com.atlassian.plugins.jira-html5-attach-images:jira-html5-attach-images-resources/clipboard-legacy.jar\"}"; WRM._unparsedData["com.atlassian.pocketknife.featureflags-plugin:pocketknife-feature-flags.feature-flag-data"]="{\"enabled-feature-keys\":[\"com.atlassian.jira.projects.issuenavigator\",\"com.atlassian.jira.projects.ProjectCentricNavigation.Switch\",\"jira.plugin.devstatus.phasetwo.enabled\",\"com.atlassian.jira.config.PDL\",\"jira.frother.reporter.field\",\"jira.plugin.devstatus.phasetwo\",\"com.atlassian.jira.darkfeature.CommonHeader\",\"app-switcher.new\",\"frother.assignee.field\",\"jira.issue.status.lozenge\"],\"feature-flag-states\":{\"sd.confluence.kb.od.oneclick\":true,\"sd.test.feature.flag.x\":true,\"sd.test.feature.flag.y\":false,\"sd.shared.portals.kb.search\":true,\"sd.skate.upgrade\":true,\"sd.reporter.internal.comments.async.upgrade\":true,\"sd.experimental.customer.satisfaction\":false,\"sd.advance.portal.branding.portal.content\":false,\"sd.request.type.search.advance\":false,\"sd.experimental.itil.sd.configuration\":false,\"sd.agent.invite.customers\":true,\"sd.better.logo.uploader\":true,\"sd.global.portal.rt.search\":false,\"sd.shared.portals.kb.like\":true,\"sd.shared.portals.redo\":true,\"sd.advance.portal.branding\":true,\"sd.channel.issue.properties.async.upgrade\":true,\"sd.agent.queue.update\":true,\"sd.req.participants.portal\":true,\"sd.agent.signature\":false,\"sd.sla.threshold.events\":true,\"sd.request.participants\":true,\"sd.req.participants.email\":true,\"sd.email.notification.quoted.reply.stripping\":false,\"sd.email.notification.plain.text\":true,\"sd.portal.logo.default\":true,\"sd.agent.queue.dynamic.update\":true,\"sd.automation.settings.page\":true,\"sd.request.participants.upgrade\":true,\"sd.jira.automation.event\":false,\"sd.remove.logo.roundness\":true,\"sd.admin.permission.migration.complete\":false,\"sd.global.portal.search.atlassian.only.tracking\":false,\"sd.email.platform.integration\":true,\"com.atlassian.jira.config.CoreFeatures.LICENSE_ROLES_ENABLED\":false}}"; WRM._unparsedData["com.atlassian.servicedesk:sd-help-links.help-links"]="{\"help\":{\"legacy.transition.deprecated\":\"http://docs.atlassian.com/servicedesk/docs-025/Legacy+comment+transition\",\"troubleshoot.requesttype\":\"http://docs.atlassian.com/servicedesk/docs-025/Troubleshooting+issues+with+request+types\",\"public.signup\":\"http://docs.atlassian.com/servicedesk/docs-025/Configuring+public+signup\",\"troubleshooting.user.management.issues\":\"http://docs.atlassian.com/servicedesk/docs-025/Troubleshooting+issues+with+user+management\",\"admin.notifications.config\":\"http://docs.atlassian.com/servicedesk/docs-025/Configuring+JIRA+Service+Desk+notifications\",\"resolve.permission.scheme.errors\":\"http://docs.atlassian.com/servicedesk/docs-025/Resolving+permission+scheme+errors\",\"default\":\"http://docs.atlassian.com/servicedesk/docs-025/\",\"request.type.error.learn.more\":\"http://docs.atlassian.com/servicedesk/docs-025/Troubleshooting+issues+with+request+types\",\"email.setup\":\"http://docs.atlassian.com/servicedesk/docs-025/Setting+up+the+email+channel\"},\"kb\":{\"default\":\"https://confluence.atlassian.com/display/SDKB/\",\"legacytransition\":\"https://confluence.atlassian.com/display/SDKB/Replacing+legacy+automatic+transitions+with+automation+rules\"}}"; WRM._unparsedData["com.atlassian.servicedesk:sd-license-warning-resource.exceeded-data"]="{\"isOndemand\":false}"; </script> <link type="text/css" rel="stylesheet" href="/s/e1d516f0a4fe012a178b1199b806ca59-CDN/en_US9gafw3/64020/104/104/_/download/superbatch/css/batch.css" media="all"> <!--[if lte IE 9]> <link type="text/css" rel="stylesheet" href="/s/ede1f147ca45bb7ab88c769eeb329330-CDN/en_US9gafw3/64020/104/104/_/download/superbatch/css/batch.css?conditionalComment=lte+IE+9" media="all"> <![endif]--> <link type="text/css" rel="stylesheet" href="/s/57d33162ceeb4737d979b281ad082ad8-CDN/en_US9gafw3/64020/104/f4e82ce632c501799dd2979ab8d96fb3/_/download/contextbatch/css/atl.general,jira.global,jira.general/batch.css?jag_disabled_marketing=true" media="all"> <link type="text/css" rel="stylesheet" href="/s/1de7d13d6350075759f5dbb50e596fe1-CDN/en_US9gafw3/64020/104/5.7.27/_/download/batch/com.atlassian.auiplugin:dialog2/com.atlassian.auiplugin:dialog2.css" media="all"> <link type="text/css" rel="stylesheet" href="/s/d41d8cd98f00b204e9800998ecf8427e-T/en_US9gafw3/64020/104/6.2.1.2/_/download/batch/com.metainf.jira.plugin.emailissue:emailissue-web-resource6/com.metainf.jira.plugin.emailissue:emailissue-web-resource6.css" media="all"> <script type="text/javascript" src="/s/a552c0308a3fa15a8ec02787e026318b-CDN/en_US9gafw3/64020/104/104/_/download/superbatch/js/batch.js?locale=en-US" ></script> <script type="text/javascript" src="/s/34b930dabb0049fd35bf17e729badf38-CDN/en_US9gafw3/64020/104/f4e82ce632c501799dd2979ab8d96fb3/_/download/contextbatch/js/atl.general,jira.global,jira.general/batch.js?locale=en-US&amp;jag_disabled_marketing=true" ></script> <script type="text/javascript" src="/s/d41d8cd98f00b204e9800998ecf8427e-CDN/en_US9gafw3/64020/104/5.7.27/_/download/batch/com.atlassian.auiplugin:internal-aui-browser/com.atlassian.auiplugin:internal-aui-browser.js" ></script> <script type="text/javascript" src="/s/d41d8cd98f00b204e9800998ecf8427e-CDN/en_US9gafw3/64020/104/5.7.27/_/download/batch/com.atlassian.auiplugin:dialog2/com.atlassian.auiplugin:dialog2.js" ></script> <script type="text/javascript" src="/s/970538c65b124f864b514ddb8fb92adf-T/en_US9gafw3/64020/104/6.2.1.2/_/download/batch/com.metainf.jira.plugin.emailissue:emailissue-web-resource6/com.metainf.jira.plugin.emailissue:emailissue-web-resource6.js?content-type=text%2Fjavascript&amp;locale=en-US" ></script> <script type="text/javascript" src="/rest/api/1.0/shortcuts/64020/f7b342512c8ef641f85e4c6693f33eef/shortcuts.js"></script> <meta name="application-name" content="JIRA" data-name="jira" data-version="6.4.5"> </head> <body id="jira" class="aui-layout aui-style-default page-type-message" data-version="6.4.5" > <div class="aui-page-panel"><div class="aui-page-panel-inner"> <section class="aui-page-panel-content"> <header class="aui-page-header"><div class="aui-page-header-inner"> <div class="aui-page-header-main"> <h1>Unauthorized (401)</h1> </div><!-- .aui-page-header-main --> </div><!-- .aui-page-header-inner --></header><!-- .aui-page-header --> <div class="aui-message aui-message-warning warning"> <p>Encountered a <code>&quot;401 - Unauthorized&quot;</code> error while loading this page.</p> <p><a href="/secure/MyJiraHome.jspa">Go to JIRA home</a></p> </div> </section><!-- .aui-page-panel-content --> </div><!-- .aui-page-panel-inner --></div><!-- .aui-page-panel --> </body> </html> {code}

Chris Solgat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2015

First thing that jumps out to me, you are getting a 401 - Unauthorized error. Did you make sure that the user ID has access to run a re-index, and make sure that the password is spelled correctly?

Chris Solgat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2015

One other thing I forgot to ask, which version of Jira are you using this for? I have only tested this with Jira 6.3.15.

Jeanne Howe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2015

The user ID and password are correct. We are on v6.4.5. I think the issue may be in this line: output=`curl -s -S -k -u $username:$password -X GET -H "Content-Type: application/json" "https://jira01ap:8080/jira/rest/api/2/reindex"; ` I modified the line to point to my dev environment. When I run Jason's script I get: curl: (6) Couldn't resolve host 'jiradev'

Chris Solgat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2015

I was just going to add a comment to this. Since you are using https and a port number you need to make sure that you have the correct port number. Usually 8080 is only for http, not https. If your Jira is using https, there should be a redirect port number that is being used. If you're not using https, just use http in your URL.

Chris Solgat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2015

This is what a proper response should look like -- 2015-07-22_16:02:12 Kicking off re-index... 2015-07-22_16:02:12 Logged in and started a Background re-index... ------------------- Http raw response --------------------------- {"progressUrl":"/secure/admin/jira/IndexProgress.jspa?taskId=10401","currentProgress":0,"type":"BACKGROUND","submittedTime":"2015-07-22T16:02:12.864-0500","success":false} ------------------- ---------------------------

Jeanne Howe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2015

Chris, I have gotten Jason's script to run! thank you for all the help. The issue was in my URL format.

Adam White May 31, 2016

@Chris Solgat did you ever get an answer to your question about the tasks being held onto?

Chris Solgat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 31, 2016

@Adam White
Yes, but there's not a lot to it.  You can read the accepted answer for What is the importance of the Acknowledge button after re-index?

The answer I received from Support is almost exactly the same:

 

If you don't press the Acknowledge button, JIRA simply holds that acknowledgement page in its cache. Once the acknowledgement is submitted, the system redirects you back to the indexing page and displays some basic information about the indexing task. All of that information is stored in cache. This functionality has no bearing on the actual indexing functionality itself other than kick off the task and monitor its progress. Since JIRA's task manager allows for only one background or foreground index task to occur at a time, you don't have to worry that there are multiple indexing sessions going on. The system does not need feedback from the UI to complete.

So, the system is holding onto something when you don't click the Acknowledge button, but it is just holding on to some lightweight page information in the cache. 

 

 

2 votes
Danilo Conrad
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 16, 2014

For those running JIRA 6.1 or later, it is possible to trigger a re-index via the REST API, with a single command such as the example below (needs JIRA Admin permission):

$ curl -D- -u <user>:<password> -X POST -H "Content-Type: application/json" "http://JIRA_URL:JIRA_PORT/rest/api/2/reindex"

Source:

Leena Bakshi May 10, 2018

Thanks Danilo, would you have something similar for confluence? my curl command used to work for confluence prior to the upgrade ( from v5.6 to v6.3)

2 votes
Adam Saint-Prix
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 4, 2012

David,

This question seems to come up quite a bit. There's a number of different ways to do it, I don't have specifics for Windows, but maybe these will help:

https://answers.atlassian.com/questions/79403/how-to-set-up-auto-re-index-in-jira

https://confluence.atlassian.com/display/JIRACOM/Automating+JIRA+operations+via+wget

https://marketplace.atlassian.com/plugins/org.swift.jira.cli

The JIRA Command Line Interface does support JIRA 3.13, but I don't know if re-indexing is available that far back. You'll have to review the docs to see. Note, you'll want to donwload the correct version that is compatible for 3.13. See version history on the linked page in the marketplace.

Best

Adam Saint-Prix

1 vote
Jason Hensler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 4, 2012

Use this url:

https://jirainstall/secure/admin/jira/IndexReIndex.jspa?os_username=user&os_password=pass

The older versions didn't have auth toakens like the new versions do.

I don't have curl installed but I think the command would be:

curl -k "https://jirainstall/secure/admin/jira/IndexReIndex.jspa?os_username=user&amp;os_password=pass"

0 votes
François Manchon June 2, 2015

Thanks Julian. Your script works just fine with JIRA 5.2.4 right now.

0 votes
Julian Bonkamp April 10, 2014

Here is my script:

 

#!/usr/bin/perl
###################################################################################
# Re-Index.pl by Jason Hensler
# Starts re-index job for jira. Tested with JIra 5.2.4 and 6.0.7
###################################################################################
 
#disable ssl verfication, using this for self-signed cert otherwise comment out.
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
use warnings;
use diagnostics;
use Data::Dumper; 
use LWP::UserAgent;
 
# Change these
my $user = "*****";
my $pass = "******";
my $jira_url = "https://*************************/"; 
my $cookie_jar = $ENV{'HOME'}; #change this if you need to, should only be need is there is a permissions issue.
my $index_type = 1; #This is for jira 5.2 and above. Set to 1 for background re-index or 0 for locking index.
my $error = 0;
 
 
#setup initial connection paramaters
my $status;
print("Creating connection to [$jira_url]... \n");
my $ua = LWP::UserAgent-&gt;new;
$ua-&gt;cookie_jar({ file =&gt; "$cookie_jar/\.cookies.txt" });
$ua-&gt;default_header('X-Atlassian-Token' =&gt; 'no-check');
 
 
#do login
$status = $ua-&gt;post($jira_url.'secure/admin/IndexAdmin.jspa', [ 'os_username'   =&gt; $user, 'os_password'  =&gt; $pass]);
if($status-&gt;header('X-Seraph-LoginReason') eq "AUTHENTICATED_FAILED" || $status-&gt;code !=200) {die("Could not login to jira, verify username and password!\n");}
else {
    print("Successfully logged in to Jira.\n");
    #do websudo
    $status = $ua-&gt;post($jira_url.'secure/admin/WebSudoAuthenticate.jspa',[ 'webSudoPassword'   =&gt; $pass]);
 
    # I'm using the http code here because the user header check stays ok and I didn't want to grep the output for an error... 
    # If we pass sudo check we get redirected to /secure/ and code is 302, otherwise we get served an error page with status 200
    if($status-&gt;code != 302) { 
        unlink('$cookie_jar/.cookies.txt');
        print("We did not sudo properly, check that your password is good and the your user is an admin!\n");
        $error = 1;
    } else {
        print("Successfully passed websudo, kicking off indexing... ");
        #do re-index
        if($index_type == 1) {$index_type='background';}
        $status = $ua-&gt;post($jira_url.'IndexReIndex.jspa', [ 'indexPathOption' =&gt; 'DEFAULT','Re-Index' =&gt;'Re-Index', 'indexingStrategy' =&gt; $index_type]);
        if($status-&gt;code != 302) { 
            print("Could not start re-index, check that your password is good and the your user is an admin!\n");
            $error = 1;
        } else {
            print("Re-index has started.\n");
            print ("Task url: ".$status-&gt;header('location')."\n");
            my $finished = 0;
            my $temp_file = "out.html";
            while ($finished eq 0) {
                my $progress = $ua-&gt;mirror($status-&gt;header('location'),$temp_file);
                sleep(5);
                open(my $tmp, "&lt;", $temp_file);
                while(eof($tmp) != 1) {
                    my $line = readline($tmp);
                    $line =~ s/^\s+|\s+$//g;
                    #print($line);
                    if ( substr($line,0,15) eq "Re-indexing is ") {
                        print ("Reindex is at ".substr($line,15,3)."\n");
                        if(substr($line,15,3) eq "100") {
                            $finished = 1;
                            print ("DONE!\n");
                        }
                    }
                }
                unlink($temp_file);
                sleep(5);
            }
             
            $error = 0;
        }
    }
}
unlink('$cookie_jar/.cookies.txt');
exit $error;

 

 

 

Julian Bonkamp July 23, 2015

At jira 6.2 i get:

Creating connection to [https://**********************/]... 

Use of uninitialized value in string eq at reindex_test.pl line 34 (#1)

    (W uninitialized) An undefined value was used as if it were already

    defined.  It was interpreted as a "" or a 0, but maybe it was a mistake.

    To suppress this warning assign a defined value to your variables.

    

    To help you figure out what was undefined, perl will try to tell you

    the name of the variable (if any) that was undefined.  In some cases

    it cannot do this, so it also tells you what operation you used the

    undefined value in.  Note, however, that perl optimizes your program

    anid the operation displayed in the warning may not necessarily appear

    literally in your program.  For example, "that $foo" is usually

    optimized into "that " . $foo, and the warning will refer to the

    concatenation (.) operator, even though there is no . in

    your program.

    

Uncaught exception from user code:

        Could not login to jira, verify username and password!

What do i wrong?

0 votes
Andrew Chadwell December 11, 2013

Thanks for the fast reply!!!!

Stealing pieces of this discussion as I'm trying to get this to work with wget still not success

IE:

wget --header "X-Atlassian-Token: no-check" http://hostname:8080/secure/admin/jira/IndexReIndex.jspa?os_username=xxxxx&os_password=xxxx

Jason Hensler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 11, 2013
Andrew Chadwell December 12, 2013

Thanks for your quick replies, I'm wanting to continue this discussion but I'm out of the office for 2 weeks. I'm leaving this w/ errors like I cannot get beyond security

2013-12-12 15:50:07,630 http-bio-8080-exec-6 INFO anonymous 950x219x1 - 10.32.114.67 /secure/admin/jira/IndexReIndex.jspa [jira.web.action.XsrfErrorAction] The security token is missing for 'anonymous'. User-Agent : 'curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5'

0 votes
Andrew Chadwell December 11, 2013

How to pass the "lock" option which is the 2nd bullet?

Thanks in advance.

Jason Hensler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 11, 2013

If you mean you want to "lock" jira durring the re-index, set "my $index_type= 0".

0 votes
getit November 18, 2013

A note for Jira 6.1: The view "AdminSummary.jspa" has gone, you can replace the following to make the script working again:

(...)
#do login
$status = $ua-&gt;post($jira_url.'secure/admin/IndexAdmin.jspa', [ 'os_username'   =&gt; $user, 'os_password'  =&gt; $pass]);
if($status-&gt;header('X-Seraph-LoginReason') eq "AUTHENTICATED_FAILED" || $status-&gt;code !=200) {die("Could not login to jira, verify username and password!\n");}
(...)

0 votes
Sean Edwards November 5, 2013

Thank you @Jason Hensler, I will give it a try!

0 votes
Sean Edwards November 4, 2013

I am using the PERL script provided by @Jason Hensler with Jira 5.1.4 and it works very well. My question is how to check the status of reindexing after it's started, specifically, when it finishes.

Does anybody have any ideas on how to do this? I would like to do this in PERL, possibly to add on to the script privided by @Jason Hensler.

Jason Hensler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 5, 2013

See my edit above.

0 votes
Areg Vrtanesyan _Work_ May 18, 2013

Hi

Did anyone tried to do the curl one under the linux?

The curl version of script requires to do the Websudo login once more ....

&lt;input type="hidden" title="ajaxTimeout" value="The call to the JIRA server did not complete within the timeout period.  We are unsure of the result of this operation."&gt;
&lt;input type="hidden" title="JiraVersion" value="5.2.8" /&gt;
&lt;input type="hidden" title="ajaxUnauthorised" value="You are not authorised to perform this operation.  Please log in."&gt;

Regards,

Areg

0 votes
HP December 3, 2012

Any one success to run it in jira 5.* ? Please advise

0 votes
David Hoffman October 4, 2012

It did not fail, it jsut didn't START the Indexing

0 votes
MattS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2012

Did not work how?

0 votes
Harry Chan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2012

Hi, do you have your JIRA with OnDemand, is it self hosted or hosted by another company? This Windows batch script assumes that JIRA is installed in D:\Jira\JIRA-Enterprise-3.13.4 suggesting it's a Windows machine, but if it's hosted by another provider it might not be. Is the version of JIRA correct?

David Hoffman October 4, 2012

The version is correct sadly.

Yes, this is Windows hosted (I Control the host), and the paths are correct.

0 votes
David Hoffman October 3, 2012

I did come across this windows batch script (it uses windows based curl which I already have), but I tried against my hosted atlassian instance (granted it is a special case) but it did not work. Any comments?

set USERNAME=
set PASSWORD=
set INDEX_PATH=D:\Jira\JIRA-Enterprise-3.13.4\indexes

set DASHBOARD_PAGE_URL=http://&lt;JIRA_URL&gt;/secure/Dashboard.jspa
set INDEX_PAGE_URL=http://&lt;JIRA_URL&gt;/secure/admin/jira/IndexReIndex.jspa
set COOKIE_FILE_LOCATION=jiracoookie.txt

curl\curl.exe -k -s --head -u %USERNAME%:%PASSWORD% --cookie-jar %COOKIE_FILE_LOCATION% %DASHBOARD_PAGE_URL%

curl\curl.exe -k -s --cookie %COOKIE_FILE_LOCATION% --header "X-Atlassian-Token: no-check" -d "indexPathOption=DEFAULT" -d "Re-Index=Re-Index" -d "newIndexPath=%INDEX_PATH%" %INDEX_PAGE_URL%

erase %COOKIE_FILE_LOCATION%

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events