Skip to content

Instantly share code, notes, and snippets.

@acdha acdha/optimize-solr
Last active Feb 27, 2016

What would you like to do?
Crude but effective cron watchdog for Apache Solr
set -eu
exec >/dev/null
sleep $((120 + ($RANDOM % 1800)))
curl -s http://localhost:8986/solr/{ar,en,es,fr,pt,ru,zh}/update -H 'Content-Type: text/xml' --data-binary '<commit waitSearcher="true"/>'
curl -s http://localhost:8986/solr/{ar,en,es,fr,pt,ru,zh}/update -H "Content-Type: text/xml" --data-binary '<optimize/>'
set -eu
# Test whether Solr is up several times to avoid race conditions when Solr is
# starting up or very busy (i.e. rebuilding & optimizing the index)
for i in `seq 1 15`; do
curl -o /dev/null --silent --fail --show-error '' && exit 0
sleep 1
logger -s -t wdl-solr-watchdog "Solr is unresponsive. Attempting to restart..."
# Ensure that the permissions have not been clobbered by another task and that the directory
# has not been removed:
install -d -m 0755 /opt/wdl/solr/work
# We rely on Upstart to restart Solr after it exists.
pkill -n -f wdl/solr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.