-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepareData.sh
More file actions
executable file
·91 lines (74 loc) · 2.92 KB
/
prepareData.sh
File metadata and controls
executable file
·91 lines (74 loc) · 2.92 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# see also: https://github.com/docker-solr/docker-solr/blob/master/Docker-FAQ.md
# note: chown 8983:999 might need to change to 8983:8983 when solr official container gets refreshed in newer version
source ./etc/version-map.sh
if [ "x${VERSION}" == "x" ];then
echo "ERROR ENV VARIABLE VERSION MISSING (try make)";
exit 1;
fi
function sudo_message() {
SUDO_GOT_FLAG=0;
if sudo -n true 2>/dev/null; then
SUDO_GOT_FLAG=1
else
echo "please provide your sudo password below (if required) for preparing the data volume"
fi
}
if [ "x$1" == "x--clean" ]; then
if [ -d "./data" ] ; then
echo "REMOVE SOLR DATA DIRECTORY ./data"
sudo_message
sudo rm -rf ./data
fi
fi
CWD=`pwd`
if [ ! -e "./data" ]; then
#mkdir data && \
#sudo_message && \
#sudo chown 8983:999 data && \
#docker run -it --rm -v $CWD/data:/target solr:${VERSION} cp -r server/solr /target/ && \
#SOLR_CONTAINER=`docker run -d -P -v $CWD/data/solr:/opt/solr/server/solr solr:${VERSION}`
#sleep 1;
#if [ "x${SOLR_CONTAINER}" 1= "x" ]; then
# docker exec ${SOLR_CONTAINER} /opt/solr/bin/solr stop -all && sleep 1 && docker stop ${SOLR_CONTAINER} && docker rm -v ${SOLR_CONTAINER}
# else
# echo "CANNOT FIND SOLR_CONTAINER please check docer ps and stop the solr container FOR solr:${VERSION}";
# fi
mkdir data && mkdir data/logs && sudo_message && sudo chown -R 8983:999 data
if [[ $VERSION =~ ^9 ]]; then
sudo_message && sudo mkdir ./data/data
sudo_message && sudo chown -R 8983:8983 data
docker run -it --rm --name solr_prepare_data -v ${CWD}/data:/target solr:${VERSION} cp -a /var/solr/log4j2.xml /target/;
else
docker run -it --rm --name solr_prepare_data -v ${CWD}/data:/target solr:${VERSION} cp -r server/solr /target/;
fi
echo "SOLR DATA DIR CREATED: $CWD/data";
echo "";
else
echo "SOLR_VERSION: ${VERSION} (expecting luceneMatchVersion: ${version_map["${VERSION}"]})";
echo "${CWD}/data ALREADY EXISTS"
if [[ $VERSION =~ ^9 ]]; then
# locate first available solrconfig in data directory
SOLR_CONFIG_FILE=`find ${CWD}/data -name "solrconfig.xml" -print -quit`
if [[ ! $SOLR_CONFIG_FILE ]]; then
# fallback if not found in data
SOLR_CONFIG_FILE="${CWD}/index_schemas/_default-9.7.0/solrconfig.xml";
fi
elif [[ $VERSION =~ ^7 ]]; then
SOLR_CONFIG_FILE="${CWD}/data/solr/configsets/_default/conf/solrconfig.xml";
else
SOLR_CONFIG_FILE="${CWD}/data/solr/configsets/basic_configs/conf/solrconfig.xml"
fi
echo "SOLR_CONFIG_FILE: ${SOLR_CONFIG_FILE}";
if [[ ! $SOLR_CONFIG_FILE ]]; then
echo "ERROR SOLR_CONFIG_FILE COULD NOT BE LOCATED";
exit 10;
fi
# Version compare
SOLR_DATA_VERSION=`cat "${SOLR_CONFIG_FILE}"|grep luceneMatchVersion|sed "s/ //g"|sed "s/<luceneMatchVersion>//"|sed "s/<\/luceneMatchVersion>//"`
echo "SOLR_DATA_VERSION: ${SOLR_DATA_VERSION}";
if [ "x${SOLR_DATA_VERSION}" != "x${version_map["${VERSION}"]}" ]; then
echo "ERROR SOLR_VERSION NOT MATCH SOLR_DATA_VERSION";
fi
exit 10;
fi