Skip to content

Instantly share code, notes, and snippets.

@acdha
Last active February 27, 2016 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acdha/e140179134a780aecebf to your computer and use it in GitHub Desktop.
Save acdha/e140179134a780aecebf to your computer and use it in GitHub Desktop.
Crude but effective cron watchdog for Apache Solr
#!/bin/bash
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/>'
#!/bin/sh
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 'http://127.0.0.1:8986/solr/en/admin/ping' && exit 0
sleep 1
done
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