lucene/src/scripts/optimize

112 lines
2.4 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# Copyright 2006 The Apache Software Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Shell script to force a optimized commit of all changes since last commit
# for a Solr server
orig_dir=$(pwd)
cd ${0%/*}/..
solr_root=$(pwd)
cd ${orig_dir}
unset solr_hostname solr_port webapp_name user verbose
. ${solr_root}/bin/scripts-util
# set up variables
prog=${0##*/}
log=${solr_root}/logs/${prog}.log
# define usage string
USAGE="\
usage: $prog [-h hostname] [-p port] [-u username] [-v]
-h specify Solr hostname
-p specify Solr port number
-w specify name of Solr webapp (defaults to solr)
-u specify user to sudo to before running script
-v increase verbosity
"
# parse args
originalargs="$@"
while getopts h:p:w:u:v OPTION
do
case $OPTION in
h)
solr_hostname="$OPTARG"
;;
p)
solr_port="$OPTARG"
;;
w)
webapp_name="$OPTARG"
;;
u)
user="$OPTARG"
;;
v)
verbose="v"
;;
*)
echo "$USAGE"
exit 1
esac
done
if [[ -z ${solr_port} ]]
then
echo "Solr port number missing in $confFile or command line."
echo "$USAGE"
exit 1
fi
# use default hostname if not specified
if [[ -z ${solr_hostname} ]]
then
solr_hostname=localhost
fi
# use default webapp name if not specified
if [[ -z ${webapp_name} ]]
then
webapp_name=solr
fi
fixUser "$@"
start=`date +"%s"`
logMessage started by $oldwhoami
logMessage command: $0 $@
rs=`curl http://${solr_hostname}:${solr_port}/solr/update -s -d "<optimize/>"`
if [[ $? != 0 ]]
then
logMessage failed to connect to Solr server at port ${solr_port}
logMessage optimize failed
logExit failed 1
fi
# check status of optimize request
rc=`echo $rs|cut -f2 -d'"'`
if [[ $? != 0 ]]
then
logMessage optimize request to Solr at port ${solr_port} failed:
logMessage $rs
logExit failed 2
fi
logExit ended 0