-
Notifications
You must be signed in to change notification settings - Fork 0
/
solradmin.sh
182 lines (164 loc) · 5.35 KB
/
solradmin.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
#!/bin/bash
#
# Solradmin.
# Created By: Jeffrey Cohen
# BluePrint IT
# Date: 09/02/2015
# Version 1.0
#variables
SOLRROOT=/usr/share/apache-solr/example/solr
SOLRDATA=$SOLRROOT
SOLRCONF=$SOLRROOT/$CORENAME/conf
SOLRCONFTEMPLATE=$SOLRROOT/templatecore
SOLRSERVER=127.0.0.1
SOLRPORT=8983
LOGFILE=/var/log/solradmin.log
OWNER=root.root
ACTION=$1
CORENAME=$2
CORENAME2=$3
# creates a new Solr core
if [ "$ACTION" = "create" ]; then
if [ "$CORENAME" = "" ]; then
echo -n "Name of core to create: "
read CORENAME
fi
if [ -d $SOLRDATA/$CORENAME ] || [ $CORENAME = "" ]; then
echo "Core already exist"
exit
fi
mkdir $SOLRDATA/$CORENAME
# chown $OWNER $SOLRDATA/$CORENAME #currently root so no need for change
cp -r $SOLRCONFTEMPLATE/* $SOLRROOT/$CORENAME
sed "s/example/$CORENAME/" $SOLRROOT/$CORENAME/conf/schema.xml > $SOLRROOT/$CORENAME/conf/schema.tmp # set nice corename
cp $SOLRROOT/$CORENAME/conf/schema.tmp $SOLRROOT/$CORENAME/conf/schema.xml
sed "s/.*<\/cores>.*/ <core name=\"$CORENAME\" instanceDir=\"$CORENAME\" \/>\n&/" $SOLRDATA/solr.xml > $SOLRDATA/solr.tmp
cp $SOLRDATA/solr.tmp $SOLRDATA/solr.xml
curl --silent "http://$SOLRSERVER:$SOLRPORT/solr/admin/cores?action=CREATE&name=$CORENAME&instanceDir=$SOLRDATA/$CORENAME" > /dev/nul #load core
echo `date` $ACTION $CORENAME >> $LOGFILE
echo Created $CORENAME
exit 0
fi
# Reload a Core
if [ "$ACTION" = "reload" ]; then
if [ "$CORENAME" = "" ]; then
echo -n "Name of core to reload: "
read CORENAME
fi
if [ ! -d $SOLRDATA/$CORENAME ] || [ $CORENAME = "" ]; then
echo "Core doesn't exist"
exit
fi
curl --silent "http://$SOLRSERVER:$SOLRPORT/solr/admin/cores?action=RELOAD&core=$CORENAME" > /dev/nul
echo `date` $ACTION $CORENAME >> $LOGFILE
echo Reload $CORENAME
exit 0
fi
# swaps two Solr cores
#
# not ready
#if [ "$ACTION" = "swap" ]; then
# if [ "$CORENAME2" = "" ]; then
# echo -n "Name of first core: "
# read CORENAME
# echo -n "Name of second core: "
# read CORENAME2
# fi
#
# if [ ! -d $SOLRDATA/$CORENAME ] || [ $CORENAME2 = "" ]; then
# echo "Core doesn't exist"
# exit
# fi
#
# curl --silent "http://$SOLRSERVER:$SOLRPORT/solr/admin/cores?action=SWAP&core=$name1&other=$CORENAME2" > /dev/nul
# echo `date` $ACTION $CORENAME $CORENAME2 >> $LOGFILE
# echo swapped $CORENAME $CORENAME2
#
# exit 0
#fi
# Delete a Core
if [ "$ACTION" = "delete" ]; then
clear
echo "*************************************************************************"
echo "*************************************************************************"
echo ""
echo " You are about to *permanently* delete a core!"
echo " There is no going back"
echo ""
echo "*************************************************************************"
echo "*************************************************************************"
echo
echo -n "Type 'delete core' to continue or control-c to bail: "
read answer
if [ "$answer" != "delete core" ]; then
exit
fi
# removes a Solr core
if [ "$CORENAME" = "" ]; then
echo -n "Name of core to remove: "
read CORENAME
fi
if [ ! -d $SOLRDATA/$CORENAME ] || [ $CORENAME = "" ]; then
echo "Core doesn't exist"
exit
fi
echo Please wait....
# needs to delete config line from $SOLRDATA/solr.xml
# sed #remove core from config
sed "/$CORENAME/d" $SOLRDATA/solr.xml > $SOLRDATA/solr.tmp
cp $SOLRDATA/solr.tmp $SOLRDATA/solr.xml
curl --silent "http://$SOLRSERVER:$SOLRPORT/solr/admin/cores?action=UNLOAD&core=$CORENAME" > /dev/nul/
sleep 5
rm -rf $SOLRDATA/$CORENAME
echo `date` $ACTION $CORENAME >> $LOGFILE
echo DELETED $CORENAME
exit 0
fi
# merges two Solr cores
if [ "$ACTION" = "merg" ]; then
if [ "$CORENAME2" = "" ]; then
echo -n "Name of first core: "
read CORENAME
echo -n "Name of second core: "
read CORENAME2
fi
if [ ! -d $SOLRDATA/$CORENAME ] || [ $CORENAME2 = "" ]; then
echo "Core doesn't exist"
exit
fi
curl --silent "http://$SOLRSERVER:$SOLRPORT/solr/$CORENAME/update" --data-binary '' -H 'Content-type:text/xml; charset=utf-8' > /dev/nul
curl --silent "http://$SOLRSERVER:$SOLRPORT/solr/$CORENAME2/update" --data-binary '' -H 'Content-type:text/xml; charset=utf-8' > /dev/nul
curl --silent "http://$SOLRSERVER:$SOLRPORT/solr/admin/cores?action=mergeindexes&core=$CORENAME&indexDir=$SOLRDATA/$CORENAME2/index" > /dev/nul
curl --silent "http://$SOLRSERVER:$SOLRPORT/solr/$CORENAME/update" --data-binary '' -H 'Content-type:text/xml; charset=utf-8' > /dev/nul
curl --silent "http://$SOLRSERVER:$SOLRPORT/solr/$CORENAME2/update" --data-binary '' -H 'Content-type:text/xml; charset=utf-8' > /dev/nul
echo `date` $ACTION $CORENAME >> $LOGFILE
echo merged $CORENAME $CORENAME2
exit 0
fi
#show cores
# nice but need some work :)
if [ "$ACTION" = "show" ];then
ls $SOLRDATA
exit 0
fi
# Display Usage
echo 'Usage: acton [core1] [core2]'
echo ''
echo 'create: Creating a new core'
echo 'Reload: Reloading a core'
echo 'swap: swapping a core Not yet functional'
echo 'delete: Deleting a core'
echo 'merge: Merg cores'
echo 'show: show cores'
echo ''
exit 0
# central logging disabled
#
#if [ $CORENAME2 = "" ]; then
# echo 'date' $ACTION $CORENAME >> $LOGFILE
# echo $ACTION $CORENAME
#else
# echo 'date' $ACTION $CORENAME $CORENAME2 >> $LOGFILE
# echo $ACTION $CORENAME $CORENAME2
#fi
exit 0