-
Notifications
You must be signed in to change notification settings - Fork 18
/
testing-solr.sh
executable file
·238 lines (221 loc) · 7.24 KB
/
testing-solr.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/usr/bin/env bash
SOLR_PORT=${SOLR_PORT:-8983}
SOLR_VERSION=${SOLR_VERSION:-4.10.2}
DEBUG=${DEBUG:-false}
SOLR_CORE=${SOLR_CORE:-core0}
download() {
FILE="$2.tgz"
if [ -f $FILE ];
then
echo "File $FILE exists."
tar -zxf $FILE
else
echo "File $FILE does not exist. Downloading solr from $1..."
curl -O $1
tar -zxf $FILE
fi
echo "Downloaded!"
}
is_solr_up(){
echo "Checking if Solr is up on http://localhost:$SOLR_PORT/solr/admin/cores"
http_code=`echo $(curl -s -o /dev/null -w "%{http_code}" "http://localhost:$SOLR_PORT/solr/admin/cores")`
return `test $http_code = "200"`
}
wait_for_solr(){
while ! is_solr_up; do
sleep 5
done
}
run() {
dir_name=$1
solr_port=$2
solr_core=$3
# Run solr
echo "Running with folder $dir_name"
echo "Starting solr on port ${solr_port}..."
# go to the solr folder
cd $1/example
if [ "$DEBUG" = "true" ]
then
java -Djetty.port=$solr_port -Dsolr.solr.home=multicore -jar start.jar &
else
java -Djetty.port=$solr_port -Dsolr.solr.home=multicore -jar start.jar > /dev/null 2>&1 &
fi
wait_for_solr
cd ../../
echo "Started"
}
download_and_run() {
case $1 in
3.5.0)
url="http://archive.apache.org/dist/lucene/solr/3.5.0/apache-solr-3.5.0.tgz"
dir_name="apache-solr-3.5.0"
dir_conf="conf/"
;;
3.6.0)
url="http://archive.apache.org/dist/lucene/solr/3.6.0/apache-solr-3.6.0.tgz"
dir_name="apache-solr-3.6.0"
dir_conf="conf/"
;;
3.6.1)
url="http://archive.apache.org/dist/lucene/solr/3.6.1/apache-solr-3.6.1.tgz"
dir_name="apache-solr-3.6.1"
dir_conf="conf/"
;;
3.6.2)
url="http://archive.apache.org/dist/lucene/solr/3.6.2/apache-solr-3.6.2.tgz"
dir_name="apache-solr-3.6.2"
dir_conf="conf/"
;;
4.0.0)
url="http://archive.apache.org/dist/lucene/solr/4.0.0/apache-solr-4.0.0.tgz"
dir_name="apache-solr-4.0.0"
dir_conf="collection1/conf/"
;;
4.1.0)
url="http://archive.apache.org/dist/lucene/solr/4.1.0/solr-4.1.0.tgz"
dir_name="solr-4.1.0"
dir_conf="collection1/conf/"
;;
4.2.0)
url="http://archive.apache.org/dist/lucene/solr/4.2.0/solr-4.2.0.tgz"
dir_name="solr-4.2.0"
dir_conf="collection1/conf/"
;;
4.2.1)
url="http://archive.apache.org/dist/lucene/solr/4.2.1/solr-4.2.1.tgz"
dir_name="solr-4.2.1"
dir_conf="collection1/conf/"
;;
4.3.1)
url="http://archive.apache.org/dist/lucene/solr/4.3.1/solr-4.3.1.tgz"
dir_name="solr-4.3.1"
dir_conf="collection1/conf/"
;;
4.4.0)
url="http://archive.apache.org/dist/lucene/solr/4.4.0/solr-4.4.0.tgz"
dir_name="solr-4.4.0"
dir_conf="collection1/conf/"
;;
4.5.0)
url="http://archive.apache.org/dist/lucene/solr/4.5.0/solr-4.5.0.tgz"
dir_name="solr-4.5.0"
dir_conf="collection1/conf/"
;;
4.5.1)
url="http://archive.apache.org/dist/lucene/solr/4.5.1/solr-4.5.1.tgz"
dir_name="solr-4.5.1"
dir_conf="collection1/conf/"
;;
4.6.0)
url="http://archive.apache.org/dist/lucene/solr/4.6.0/solr-4.6.0.tgz"
dir_name="solr-4.6.0"
dir_conf="collection1/conf/"
;;
4.6.1)
url="http://archive.apache.org/dist/lucene/solr/4.6.1/solr-4.6.1.tgz"
dir_name="solr-4.6.1"
dir_conf="collection1/conf/"
;;
4.7.0)
url="http://archive.apache.org/dist/lucene/solr/4.7.0/solr-4.7.0.tgz"
dir_name="solr-4.7.0"
dir_conf="collection1/conf/"
;;
4.7.1)
url="http://archive.apache.org/dist/lucene/solr/4.7.1/solr-4.7.1.tgz"
dir_name="solr-4.7.1"
dir_conf="collection1/conf/"
;;
4.7.2)
url="http://archive.apache.org/dist/lucene/solr/4.7.2/solr-4.7.2.tgz"
dir_name="solr-4.7.2"
dir_conf="collection1/conf/"
;;
4.8.0)
url="http://archive.apache.org/dist/lucene/solr/4.8.0/solr-4.8.0.tgz"
dir_name="solr-4.8.0"
dir_conf="collection1/conf/"
;;
4.8.1)
url="http://archive.apache.org/dist/lucene/solr/4.8.1/solr-4.8.1.tgz"
dir_name="solr-4.8.1"
dir_conf="collection1/conf/"
;;
4.9.0)
url="http://archive.apache.org/dist/lucene/solr/4.9.0/solr-4.9.0.tgz"
dir_name="solr-4.9.0"
dir_conf="collection1/conf/"
;;
4.9.1)
url="http://archive.apache.org/dist/lucene/solr/4.9.1/solr-4.9.1.tgz"
dir_name="solr-4.9.1"
dir_conf="collection1/conf/"
;;
4.10.2)
url="http://archive.apache.org/dist/lucene/solr/4.10.2/solr-4.10.2.tgz"
dir_name="solr-4.10.2"
dir_conf="collection1/conf/"
;;
esac
download $url $dir_name
add_core $dir_name $dir_conf $SOLR_CORE $SOLR_CONFS
run $dir_name $SOLR_PORT $SOLR_CORE
if [ -z "${SOLR_DOCS}" ]
then
echo "$solr_docs not defined, skipping initial indexing"
else
post_documents $dir_name $SOLR_DOCS $SOLR_CORE $SOLR_PORT
fi
}
add_core() {
dir_name=$1
dir_conf=$2
solr_core=$3
solr_confs=$4
# prepare our folders
[[ -d "${dir_name}/example/multicore/${solr_core}" ]] || mkdir $dir_name/example/multicore/$solr_core
[[ -d "${dir_name}/example/multicore/${solr_core}/conf" ]] || mkdir $dir_name/example/multicore/$solr_core/conf
# copy full solr example first
cp -R $dir_name/example/solr/$dir_conf/* $dir_name/example/multicore/$solr_core/conf
# overwrite with custom configurations
if [ -d "${solr_confs}" ] ; then
cp -R $solr_confs/* $dir_name/example/multicore/$solr_core/conf/
else
for file in $solr_confs
do
if [ -f "${file}" ]; then
cp $file $dir_name/example/multicore/$solr_core/conf
echo "Copied $file into solr conf directory."
else
echo "${file} is not valid";
exit 1
fi
done
fi
}
post_documents() {
dir_name=$1
solr_docs=$2
solr_core=$3
solr_port=$4
# Post documents
if [ -z "${solr_docs}" ]
then
echo "SOLR_DOCS not defined, skipping initial indexing"
else
echo "Indexing $solr_docs"
java -Dtype=application/json -Durl=http://localhost:$solr_port/solr/$solr_core/update/json -jar $dir_name/example/exampledocs/post.jar $solr_docs
fi
}
check_version() {
case $1 in
3.5.0|3.6.0|3.6.1|3.6.2|4.0.0|4.1.0|4.2.0|4.2.1|4.3.1|4.4.0|4.5.0|4.5.1|4.6.0|4.6.1|4.7.0|4.7.1|4.7.2|4.8.0|4.8.1|4.9.0|4.9.1|4.10.2);;
*)
echo "Sorry, $1 is not supported or not valid version."
exit 1
;;
esac
}
check_version $SOLR_VERSION
download_and_run $SOLR_VERSION