-
Notifications
You must be signed in to change notification settings - Fork 38
/
travis-solr.sh
executable file
·203 lines (184 loc) · 5.62 KB
/
travis-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
#!/usr/bin/env bash
SOLR_PORT=${SOLR_PORT:-8983}
SOLR_VERSION=${SOLR_VERSION:-8.1.0}
DEBUG=${DEBUG:-false}
SOLR_CORE=${SOLR_CORE:-core0}
# Since Solr 5.x
SOLR_COLLECTION=${SOLR_COLLECTION:-gettingstarted}
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 3
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"
}
run_solr5_example() {
dir_name=$1
solr_port=$2
./$dir_name/bin/solr -p $solr_port -c -e schemaless
echo "Started"
}
run_solr5() {
dir_name=$1
solr_port=$2
./$dir_name/bin/solr -p $solr_port -c
echo "Started"
}
download_and_run() {
version=$1
case $1 in
3.*)
url="http://archive.apache.org/dist/lucene/solr/${version}/apache-solr-${version}.tgz"
dir_name="apache-solr-${version}"
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.*)
url="http://archive.apache.org/dist/lucene/solr/${version}/solr-${version}.tgz"
dir_name="solr-${version}"
dir_conf="collection1/conf/"
;;
5.*|6.*|7.*|8.*)
url="http://archive.apache.org/dist/lucene/solr/${version}/solr-${version}.tgz"
dir_name="solr-${version}"
;;
*)
echo "Sorry, $1 is not supported or not valid version."
exit 1
esac
download $url $dir_name
if [[ $1 == 5* || $1 == 6* || $1 == 7* || $1 == 8* ]]
then
if [ -z "${SOLR_COLLECTION_CONF}" ]
then
run_solr5_example $dir_name $SOLR_PORT
else
run_solr5 $dir_name $SOLR_PORT
create_collection $dir_name $SOLR_COLLECTION $SOLR_COLLECTION_CONF $SOLR_PORT
fi
if [ -z "${SOLR_DOCS}" ]
then
echo "SOLR_DOCS not defined, skipping initial indexing"
else
post_documents_solr5 $dir_name $SOLR_COLLECTION $SOLR_DOCS $SOLR_PORT
fi
else
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
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 text configs from default single core conf to new core to have proper defaults
cp -R $dir_name/example/solr/conf/{lang,*.txt} $dir_name/example/multicore/$solr_core/conf/
# copies custom configurations
if [ -d "${solr_confs}" ] ; then
cp -R $solr_confs/* $dir_name/example/multicore/$solr_core/conf/
echo "Copied $solr_confs/* to solr conf directory."
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
# enable custom core
if [ "$solr_core" != "core0" -a "$solr_core" != "core1" ] ; then
echo "Adding $solr_core to solr.xml"
sed -i -e "s/<\/cores>/<core name=\"$solr_core\" instanceDir=\"$solr_core\" \/><\/cores>/" $dir_name/example/multicore/solr.xml
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
}
create_collection() {
dir_name=$1
name=$2
dir_conf=$3
solr_port=$4
./$dir_name/bin/solr create -c $name -d $dir_conf -shards 1 -replicationFactor 1 -p $solr_port
echo "Created collection $name"
}
post_documents_solr5() {
dir_name=$1
collection=$2
solr_docs=$3
solr_port=$4
# Post documents
if [ -z "${solr_docs}" ]
then
echo "SOLR_DOCS not defined, skipping initial indexing"
else
echo "Indexing $solr_docs"
echo "./$dir_name/bin/post -c $collection $solr_docs -p$solr_port"
./$dir_name/bin/post -c $collection $solr_docs -p $solr_port
fi
}
download_and_run $SOLR_VERSION