#!/bin/sh
# This file mimics creating / updating / unloading / deleting solr cores
# Create a new core
# arg 1: core name
create_solr_core() {
# creates a new Solr core
if [ "$1" = "" ]; then
echo -n "Name of core to create: "
read name
else
name=$1
fi
if [ -d "/var/lib/solr/data/$name" ]; then
echo "Cannot create $name: core with same name already exists"
exit 1
else
mkdir /var/lib/solr/data/$name
chown tomcat6.tomcat6 /var/lib/solr/data/$name
mkdir -p /etc/solr/conf/$name/conf
cp -a /etc/solr/conftemplate/* /etc/solr/conf/$name/conf/
# Create multiple instances so that we can use this with the apachesolr module
# and the search_api module. Can add more in the future.
find /etc/solr/conf/$name/conf -name "solrconfig.xml*" -exec sed -i "s/CORENAME/$name/" {} \;
# Use the second argument to automatically specify which solrconfig.xml file to use
if [ "$2" = "" ]; then
echo -n "Original configuration will be used"
else
config=$2
schema_filename="/etc/solr/conf/$name/conf/schema.xml.$config"
config_filename="/etc/solr/conf/$name/conf/solrconfig.xml.$config"
if [ -e "$config_filename" ] && [ -e "$schema_filename" ]; then
cp -f $config_filename /etc/solr/conf/$name/conf/solrconfig.xml
cp -f $schema_filename /etc/solr/conf/$name/conf/schema.xml
echo "USING new config $config_filename"
else
echo "config $config_filename could not be found. Using original configuration. Please update solrconfig.xml and/or schema.xml and reload the using solr-admin.sh reload $name"
fi
fi
curl "http://localhost:8080/solr/admin/cores?action=CREATE&name=$name&instanceDir=/etc/solr/conf/$name"
echo "Please read status from solr - by all accounts (pending a proper name), core $name was created"
fi
exit 0
}
# Reload existing core
# arg 1: core name
reload_solr_core() {
# reloads a Solr core
if [ "$1" = "" ]; then
echo -n "Name of core to reload: "
read name
else
name=$1
fi
if [ ! -d /var/lib/solr/data/$name ] || [ $name = "" ]; then
echo "Core doesn't exist"
exit
fi
curl "http://localhost:8080/solr/admin/cores?action=RELOAD&core=$name"
echo "Core $name has been reloaded"
}
# Update existing core
# arg 1: core name
unload_solr_core() {
if [ "$1" = "" ]; then
echo -n "Name of core to remove: "
read name
else
name=$1
fi
if [ -d "/var/lib/solr/data/$name" ]; then
curl "http://localhost:8080/solr/admin/cores?action=UNLOAD&core=$name"
echo "Core $name has been unloaded"
else
echo "Core $name does not exist"
fi
}
# Remove existing core
# arg 1: core name
remove_solr_core() {
if [ "$1" = "" ]; then
echo -n "Name of core to remove: "
read name
else
name=$1
fi
if [ -d "/var/lib/solr/data/$name" ]; then
unload_solr_core $name
rm -rf /var/lib/solr/data/$name
rm -rf /etc/solr/conf/$name
echo "Deleted configuration settings for $name"
else
echo "Core $name does not exist"
fi
exit 0
}
case "$1" in
create)
create_solr_core $2 $3
;;
reload)
reload_solr_core $2
;;
unload)
unload_solr_core $2
;;
remove)
remove_solr_core $2
;;
esac
exit 0