-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoeawresources_reindex.sh
executable file
·66 lines (57 loc) · 2.85 KB
/
oeawresources_reindex.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
if [ "$1" = "" ] ; then
echo "$0 password [login] [stack_name] [portainer_api_base]"
echo ""
echo "Reingests OEAW resources' Solr database."
echo "It's done by removing volumes storing Solr data and records harvested with OAI-PMH and restarting the whole indexing process. "
echo ""
echo "Parameters:"
echo ' password, login - Portainer credentialsi (login default value "admin")'
echo ' stack_name - OEAW resources Portainer stack name (default value "resources")'
echo ' portainer_api_base - Portainer REST API base URL (default value "https://portainer.sisyphos.arz.oeaw.ac.at/api")'
echo ""
exit
fi
PSWD=$1
LOGIN=$2
LOGIN=${LOGIN:="admin"}
STACK_NAME=$3
STACK_NAME=${STACK_NAME:="resources"}
APIURL=$4
APIURL=${APIURL:="https://portainer.sisyphos.arz.oeaw.ac.at/api"}
function check_request () {
CODE=`echo -e "$1" | head -n 1 | tr -d '\r\n'`
if [ "$CODE" != "HTTP/2 200 " ] && [ "$CODE" != "HTTP/2 204 " ] ; then
echo -e " failed\n\n$1"
exit 1
fi
echo " succeeded"
}
TOKEN=`curl -s -S "$APIURL/auth" -H "Content-Type: application-json" --data-binary "{\"Username\": \"$LOGIN\", \"Password\": \"$PSWD\"}" | jq -r '.jwt'`
STACK_ID=`curl -s -S -H "Authorization: Bearer $TOKEN" "$APIURL/stacks" | jq -r ".[] | select(.Name == \"$STACK_NAME\") | .Id"`
echo "## Stopping the '$STACK_NAME' stack"
R=`curl -s -S -i -H "Authorization: Bearer $TOKEN" -X POST "$APIURL/stacks/$STACK_ID/stop"`
check_request "$R"
VOLUMES=`curl -s -S -H "Authorization: Bearer $TOKEN" https://portainer.sisyphos.arz.oeaw.ac.at/api/endpoints/1/docker/volumes | \
jq -r ".Volumes[] | select((.Name | startswith(\"${STACK_NAME}_\")) and ((.Name | contains(\"solr\")) or (.Name | contains(\"harvest\")))) | .Name"`
for v in $VOLUMES ; do
echo "## Removing volume '$v'"
R=`curl -s -S -i -H "Authorization: Bearer $TOKEN" -X DELETE "$APIURL/endpoints/1/docker/volumes/$v"`
check_request "$R"
done
echo "## Starting the '$STACK_NAME' stack"
R=`curl -s -S -i -H "Authorization: Bearer $TOKEN" -X POST "$APIURL/stacks/$STACK_ID/start"`
check_request "$R"
CONTAINERS=`curl -s -S -H "Authorization: Bearer $TOKEN" "$APIURL/endpoints/1/docker/containers/json" -G -d "filters={\"label\":[\"com.docker.compose.project=$STACK_NAME\"]}" | \
jq '.[].Names[]' -r | \
sed -e 's/^\///g'`
WEB_CONTAINER=`echo -e "$CONTAINERS" | grep web`
SOLR_CONTAINER=`echo -e "$CONTAINERS" | grep solr`
echo "## Data removed successfully"
echo ""
echo "To harvest OAI-PMH records run the following command in the web application docker container ($WEB_CONTAINER):"
echo " /var/www/vufind/harvest/harvest_oai.sh"
echo ""
echo "To import harvested records once harvesting ended run the following command AS ROOT in the solr docker container ($SOLR_CONTAINER):"
echo " /opt/aksearch/harvest/batch-import-marc-single.sh -d /opt/harvest"
echo ""