forked from moliware/travis-solr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolr5.sh
executable file
·124 lines (93 loc) · 2.66 KB
/
solr5.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
#!/usr/bin/env bash
set -e
cd $(dirname $0)
export SOLR_VERSION=${SOLR_VERSION:-5.5.0}
export SOLR_NAME="solr-$SOLR_VERSION"
export SOLR_DIR="`pwd`/${SOLR_NAME}"
export SOLR_PORT=${SOLR_PORT:-8983}
export SOLR_SOURCE_URL="http://archive.apache.org/dist/lucene/solr/${SOLR_VERSION}/${SOLR_NAME}.tgz"
export SOLR_ARCHIVE="${SOLR_NAME}.tgz"
export SOLR_CONFIGSET=${SOLR_CONFIGSET:-basic}
solr_responding() {
port=$1
curl -o /dev/null "http://localhost:$port/solr/admin/ping" > /dev/null 2>&1
}
wait_until_solr_responds() {
port=$1
while ! solr_responding $1; do
/bin/echo -n "."
sleep 1
done
}
solr_install() {
#if $SOLR_DIR not exist then try to download solr and extrat
if [ ! -e $SOLR_DIR ]; then
if [ -d "${HOME}/download-cache/" ]; then
export SOLR_ARCHIVE="${HOME}/download-cache/${SOLR_ARCHIVE}"
fi
if [ -f ${SOLR_ARCHIVE} ]; then
# If the tarball doesn't extract cleanly, remove it so it'll download again:
tar -tf ${SOLR_ARCHIVE} > /dev/null || rm ${SOLR_ARCHIVE}
fi
if [ ! -f ${SOLR_ARCHIVE} ]; then
echo "Download ${SOLR_NAME} from ${SOLR_SOURCE_URL}"
curl -Lo $SOLR_ARCHIVE $SOLR_SOURCE_URL
# wget -nv --output-document=`pwd`/$SOLR.tgz $SOLR_SOURCE_URL
fi
echo "Extracting Solr ${SOLR_ARCHIVE} to ${SOLR_DIR}"
tar -xf $SOLR_ARCHIVE
fi
if [ -d "`pwd`/server" ]; then
echo "Create configsets in ${SOLR_DIR}"
cp -ar "`pwd`/server" $SOLR_DIR
fi
echo "Changing dir into ${SOLR_DIR}"
cd $SOLR_DIR
# We use exec to allow process monitors to correctly kill the
# actual Java process rather than this launcher script:
export CMD="bin/solr start -p ${SOLR_PORT}"
echo "Starting server on port ${SOLR_PORT}"
exec $CMD
}
solr_addcore() {
echo "Waiting solr to launch on ${SOLR_PORT}..."
wait_until_solr_responds $SOLR_PORT
if [ -n "$SOLR_CORENAME" ]; then
echo "Add solr cores"
for CORENAME in $SOLR_CORENAME
do
# create core folder
mkdir -p "${SOLR_DIR}/server/solr/${CORENAME}/"
cp -ar "${SOLR_DIR}${SOLR_CONFIGSET}" "${SOLR_DIR}/server/solr/${CORENAME}/"
echo "Configuring Core named ${CORENAME}"
#exec $CMD
curl -o /dev/null "http://localhost:${SOLR_PORT}/solr/admin/cores?action=CREATE&name=${CORENAME}&instanceDir=${CORENAME}" > /dev/null 2>&1
done
fi
}
solr_stop() {
echo "Changing dir into ${SOLR_DIR}"
cd $SOLR_DIR
export CMD="bin/solr stop -p ${SOLR_PORT}"
echo "Stop server on port ${SOLR_PORT}"
exec $CMD
}
while [[ $# -ge 1 ]]
do
key="$1"
case $key in
--install)
solr_install
;;
--addcore)
solr_addcore
;;
--stop)
solr_stop
;;
*)
echo $key # unknown option
;;
esac
shift # past argument or value
done