-
Notifications
You must be signed in to change notification settings - Fork 0
/
solrcloud-upload-configset.sh
executable file
·42 lines (36 loc) · 1.75 KB
/
solrcloud-upload-configset.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env sh
COUNTER=0;
# /app/samvera/hyrax-webapp/solr/conf
CONFDIR="${1}"
if [ "$SOLR_ADMIN_USER" ]; then
solr_user_settings="--user $SOLR_ADMIN_USER:$SOLR_ADMIN_PASSWORD"
fi
solr_config_name="${SOLR_CONFIGSET_NAME:-solrconfig}"
# Solr Cloud ConfigSet API URLs
solr_config_list_url="http://$SOLR_HOST:$SOLR_PORT/api/cluster/configs?omitHeader=true"
solr_config_upload_url="http://$SOLR_HOST:$SOLR_PORT/solr/admin/configs?action=UPLOAD&name=${solr_config_name}"
while [ $COUNTER -lt 30 ]; do
echo "-- Looking for Solr (${SOLR_HOST}:${SOLR_PORT})..."
if nc -z "${SOLR_HOST}" "${SOLR_PORT}"; then
# shellcheck disable=SC2143,SC2086
if curl --silent --user 'fake:fake' "$solr_config_list_url" | grep -q '401'; then
# the solr pods come up and report available before they are ready to accept trusted configs
# only try to upload the config if auth is on.
if curl --silent $solr_user_settings "$solr_config_list_url" | grep -q "$solr_config_name"; then
echo "-- ConfigSet already exists; skipping creation ...";
else
echo "-- ConfigSet for ${CONFDIR} does not exist; creating ..."
(cd "$CONFDIR" && zip -r - *) | curl -X POST $solr_user_settings --header "Content-Type:application/octet-stream" --data-binary @- "$solr_config_upload_url"
fi
exit
else
echo "-- Solr at $solr_config_list_url is accepting unauthorized connections; we can't upload a trusted ConfigSet."
echo "-- It's possible SolrCloud is bootstrapping its configuration, so this process will retry."
echo "-- see: https://solr.apache.org/guide/8_6/configsets-api.html#configsets-upload"
fi
fi
COUNTER=$(( COUNTER+1 ));
sleep 5s
done
echo "--- ERROR: failed to create Solr ConfigSet after 5 minutes";
exit 1