SOLR-2046: add common functions to scripts-util

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@990160 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Koji Sekiguchi 2010-08-27 14:10:11 +00:00
parent 44468e02bf
commit 2c8219cf43
19 changed files with 75 additions and 327 deletions

View File

@ -83,6 +83,8 @@ Upgrading from Solr 1.4
backward compatible, it should be trivial to migrate as the SpellingOptions class
just encapsulates the parameters that were passed in to the methods before the change. (gsingers)
* readercycle script was removed. (SOLR-2046)
Detailed Change List
----------------------
@ -275,6 +277,7 @@ Optimizations
percentage of the number of unique terms in the field. Extreme cases
yield speedups over 3x. (yonik)
* SOLR-2046: add common functions to scripts-util. (koji)
Bug Fixes
----------------------

View File

@ -33,13 +33,13 @@ log=${solr_root}/logs/${prog}.log
# define usage string
USAGE="\
usage: $prog [-h hostname] [-p port] [-d dir] [-w webappname] [-u username] [-U url] [-v] [-V]
usage: $prog [-h hostname] [-p port] [-d dir] [-w webapp_name] [-u username] [-U url] [-v] [-V]
-h specify Solr hostname (defaults to localhost)
-p specify Solr port number
-w specify name of Solr webapp (defaults to solr)
-u specify user to sudo to before running script
-U specify full update url (overrides -h,-p,-w parameters)
-d specify directory holding index data
-d specify directory holding index data (defaults to data)
-v increase verbosity
-V output debugging info
"
@ -80,40 +80,9 @@ done
[[ -n $debug ]] && set -x
# use default value for data_dir if not specified
# relative path starts at ${solr_root}
if [[ -z ${data_dir} ]]
then
data_dir=${solr_root}/data
elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]]
then
data_dir=${solr_root}/${data_dir}
fi
dataDir
if [[ -n ${solr_url} ]]
then
curl_url=${solr_url}
else
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
curl_url=http://${solr_hostname}:${solr_port}/${webapp_name}/update
fi
curlUrl
fixUser "$@"

View File

@ -22,7 +22,6 @@ orig_dir=$(pwd)
cd ${0%/*}/..
solr_root=$(pwd)
cd ${orig_dir}
curl_url=""
unset solr_hostname solr_port data_dir webapp_name user verbose debug solr_url
. ${solr_root}/bin/scripts-util
@ -80,40 +79,9 @@ done
[[ -n $debug ]] && set -x
# use default value for data_dir if not specified
# relative path starts at ${solr_root}
if [[ -z ${data_dir} ]]
then
data_dir=${solr_root}/data
elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]]
then
data_dir=${solr_root}/${data_dir}
fi
dataDir
if [[ -n ${solr_url} ]]
then
curl_url=${solr_url}
else
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
curl_url=http://${solr_hostname}:${solr_port}/${webapp_name}/update
fi
curlUrl
fixUser "$@"

View File

@ -31,7 +31,7 @@ log=${solr_root}/logs/${prog}.log
# define usage string
USAGE="\
usage: $prog [-d dir] [-u username] [-v]
usage: $prog [-d dir] [-u username] [-v] [-V]
-d specify directory holding index data
-u specify user to sudo to before running script
-v increase verbosity
@ -62,15 +62,7 @@ done
[[ -n $debug ]] && set -x
# use default value for data_dir if not specified
# relative path starts at ${solr_root}
if [[ -z ${data_dir} ]]
then
data_dir=${solr_root}/data
elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]]
then
data_dir=${solr_root}/${data_dir}
fi
dataDir
fixUser "$@"

View File

@ -31,7 +31,7 @@ log=${solr_root}/logs/${prog}.log
# define usage string
USAGE="\
usage: $prog -D <days> | -N <num> [-d dir] [-u username] [-v]
usage: $prog -D <days> | -N <num> [-d dir] [-u username] [-v] [-V]
-D <days> cleanup backups more than <days> days old
-N <num> keep the most recent <num> number of backups and
cleanup up the remaining ones that are not being pulled
@ -79,15 +79,7 @@ fi
fixUser "$@"
# use default value for data_dir if not specified
# relative path starts at ${solr_root}
if [[ -z ${data_dir} ]]
then
data_dir=${solr_root}/data
elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]]
then
data_dir=${solr_root}/${data_dir}
fi
dataDir
function remove
{

View File

@ -22,7 +22,6 @@ orig_dir=$(pwd)
cd ${0%/*}/..
solr_root=$(pwd)
cd ${orig_dir}
curl_url=""
unset solr_hostname solr_port webapp_name user verbose debug solr_url
. ${solr_root}/bin/scripts-util
@ -76,30 +75,7 @@ done
[[ -n $debug ]] && set -x
if [[ -n ${solr_url} ]]
then
curl_url=${solr_url}
else
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
curl_url=http://${solr_hostname}:${solr_port}/${webapp_name}/update
fi
curlUrl
fixUser "$@"

View File

@ -22,7 +22,6 @@ orig_dir=$(pwd)
cd ${0%/*}/..
solr_root=$(pwd)
cd ${orig_dir}
curl_url=""
unset solr_hostname solr_port webapp_name user verbose debug solr_url
. ${solr_root}/bin/scripts-util
@ -33,7 +32,7 @@ log=${solr_root}/logs/${prog}.log
# define usage string
USAGE="\
usage: $prog [-h hostname] [-p port] [-u username] [-U url] [-v] [-V]
usage: $prog [-h hostname] [-p port] [-w webapp_name] [-u username] [-U url] [-v] [-V]
-h specify Solr hostname (defaults to localhost)
-p specify Solr port number
-w specify name of Solr webapp (defaults to solr)
@ -44,7 +43,6 @@ usage: $prog [-h hostname] [-p port] [-u username] [-U url] [-v] [-V]
"
# parse args
originalargs="$@"
while getopts h:p:w:u:U:vV OPTION
do
case $OPTION in
@ -77,30 +75,7 @@ done
[[ -n $debug ]] && set -x
if [[ -n ${solr_url} ]]
then
curl_url=${solr_url}
else
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
curl_url=http://${solr_hostname}:${solr_port}/${webapp_name}/update
fi
curlUrl
fixUser "$@"

View File

@ -1,129 +0,0 @@
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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 all old readers closed and a new reader to be opened
# for a Solr server
orig_dir=$(pwd)
cd ${0%/*}/..
solr_root=$(pwd)
cd ${orig_dir}
curl_url=""
unset solr_hostname solr_port webapp_name user verbose debug solr_url
. ${solr_root}/bin/scripts-util
# set up variables
prog=${0##*/}
log=${solr_root}/logs/${prog}.log
# define usage string
USAGE="\
usage: $prog [-p hostname] [-p port] [-w webapp_name] [-u username] [-U url] [-v] [-V]
-h specify Solr hostname (defaults to localhost)
-p specify Solr port number
-w specify name of Solr webapp (defaults to solr)
-u specify user to sudo to before running script
-U specify full update url (overrides -h,-p,-w parameters)
-v increase verbosity
-V output debugging info
"
# parse args
originalargs="$@"
while getopts h:p:w:u:U:vV OPTION
do
case $OPTION in
h)
solr_hostname="$OPTARG"
;;
p)
solr_port="$OPTARG"
;;
w)
webapp_name="$OPTARG"
;;
u)
user="$OPTARG"
;;
U)
solr_url="$OPTARG"
;;
v)
verbose="v"
;;
V)
debug="V"
;;
*)
echo "$USAGE"
exit 1
esac
done
[[ -n $debug ]] && set -x
if [[ -n ${solr_url} ]]
then
curl_url=${solr_url}
else
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
curl_url=http://${solr_hostname}:${solr_port}/${webapp_name}/update
fi
fixUser "$@"
setStartTime
logMessage started by $oldwhoami
logMessage command: $0 $@
rs=`curl ${curl_url} -s -H 'Content-type:text/xml; charset=utf-8' -d "<commit/>"`
if [[ $? != 0 ]]
then
logMessage failed to connect to Solr server at ${curl_url}
logMessage reader cycle failed
logExit failed 1
fi
# check status of commit request
echo $rs | grep '<response.*status="0"' > /dev/null 2>&1
if [[ $? != 0 ]]
then
logMessage reader cycle request to Solr at ${curl_url} failed:
logMessage $rs
logExit failed 2
fi
logExit ended 0

View File

@ -31,7 +31,7 @@ log=${solr_root}/logs/rsyncd.log
# define usage string
USAGE="\
usage: $prog [-u username] [-v]
usage: $prog [-u username] [-v] [-V]
-u specify user to sudo to before running script
-v increase verbosity
-V output debugging info

View File

@ -30,7 +30,7 @@ log=${solr_root}/logs/rsyncd.log
# define usage string
USAGE="\
usage: $prog [-u username] [-v]
usage: $prog [-u username] [-v] [-V]
-u specify user to sudo to before running script
-v increase verbosity
-V output debugging info

View File

@ -31,7 +31,7 @@ log=${solr_root}/logs/rsyncd.log
# define usage string
USAGE="\
usage: $prog [-d dir] [-p portnum] [-u username] [-v]
usage: $prog [-d dir] [-p portnum] [-u username] [-v] [-V]
-d specify directory holding index data
-p specify rsyncd port number
-u specify user to sudo to before running script
@ -82,15 +82,7 @@ then
fi
fi
# use default value for data_dir if not specified
# relative path starts at ${solr_root}
if [[ -z ${data_dir} ]]
then
data_dir=${solr_root}/data
elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]]
then
data_dir=${solr_root}/${data_dir}
fi
dataDir
logMessage started by $oldwhoami
logMessage command: $0 $@

View File

@ -31,7 +31,7 @@ log=${solr_root}/logs/rsyncd.log
# define usage string
USAGE="\
usage: $prog [-u username] [-v]
usage: $prog [-u username] [-v] [-V]
-u specify user to sudo to before running script
-v increase verbosity
-V output debugging info

View File

@ -68,6 +68,48 @@ function timeStamp
date +'%Y/%m/%d %H:%M:%S'
}
function curlUrl
{
curl_url=""
if [[ -n ${solr_url} ]]
then
curl_url=${solr_url}
else
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
curl_url=http://${solr_hostname}:${solr_port}/${webapp_name}/update
fi
}
function dataDir
{
# use default value for data_dir if not specified
# relative path starts at ${solr_root}
if [[ -z ${data_dir} ]]
then
data_dir=${solr_root}/data
elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]]
then
data_dir=${solr_root}/${data_dir}
fi
}
function logMessage
{
echo $(timeStamp) $@>>$log

View File

@ -31,7 +31,7 @@ log=${solr_root}/logs/${prog}.log
# define usage string
USAGE="\
usage: $prog -D <days> | -N <num> [-d dir] [-u username] [-v]
usage: $prog -D <days> | -N <num> [-d dir] [-u username] [-v] [-V]
-D <days> cleanup snapshots more than <days> days old
-N <num> keep the most recent <num> number of snapshots and
cleanup up the remaining ones that are not being pulled
@ -79,15 +79,7 @@ fi
fixUser "$@"
# use default value for data_dir if not specified
# relative path starts at ${solr_root}
if [[ -z ${data_dir} ]]
then
data_dir=${solr_root}/data
elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]]
then
data_dir=${solr_root}/${data_dir}
fi
dataDir
function remove
{

View File

@ -36,7 +36,7 @@ PIDFILE="${LOCKDIR}/PID"
# define usage string
USAGE="\
usage: $prog [-M master] [-S sdir] [-d dir] [-u username] [-v]
usage: $prog [-M master] [-S sdir] [-d dir] [-u username] [-v] [-V]
-M master specify hostname of master server from where to pull index
snapshot
-S specify directory holding snapshot status on master server
@ -92,15 +92,7 @@ fi
fixUser "$@"
# use default value for data_dir if not specified
# relative path starts at ${solr_root}
if [[ -z ${data_dir} ]]
then
data_dir=${solr_root}/data
elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]]
then
data_dir=${solr_root}/${data_dir}
fi
dataDir
# assume relative path to start at ${solr_root}
if [[ "`echo ${master_status_dir}|cut -c1`" != "/" ]]

View File

@ -32,7 +32,7 @@ log=${solr_root}/logs/${prog}.log
# define usage string
USAGE="\
usage: $prog [-M master] [-P portnum] [-D mdir] [-S sdir] [-n snapshot] [-d dir] [-u username] [-svz]
usage: $prog [-M master] [-P portnum] [-D mdir] [-S sdir] [-n snapshot] [-d dir] [-u username] [-svVz]
-M master specify hostname of master server from where to pull index
snapshot
-P port specify rsyncd port number of master server from where to
@ -130,15 +130,7 @@ fi
fixUser "$@"
# use default value for data_dir if not specified
# relative path starts at ${solr_root}
if [[ -z ${data_dir} ]]
then
data_dir=${solr_root}/data
elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]]
then
data_dir=${solr_root}/${data_dir}
fi
dataDir
# assume relative path to start at ${solr_root}
if [[ "`echo ${master_data_dir}|cut -c1`" != "/" ]]

View File

@ -31,7 +31,7 @@ log=${solr_root}/logs/snappuller.log
# define usage string
USAGE="\
usage: $prog [-u username] [-v]
usage: $prog [-u username] [-v] [-V]
-u specify user to sudo to before running script
-v increase verbosity
-V output debugging info

View File

@ -31,7 +31,7 @@ log=${solr_root}/logs/snappuller.log
# define usage string
USAGE="\
usage: $prog [-u username] [-v]
usage: $prog [-u username] [-v] [-V]
-u specify user to sudo to before running script
-v increase verbosity
-V output debugging info

View File

@ -31,7 +31,7 @@ log=${solr_root}/logs/${prog}.log
# define usage string
USAGE="\
usage: $prog [-d dir] [-u username] [-v]
usage: $prog [-d dir] [-u username] [-v] [-V] [-c]
-d specify directory holding index data
-u specify user to sudo to before running script
-v increase verbosity
@ -68,15 +68,7 @@ done
fixUser "$@"
# use default value for data_dir if not specified
# relative path starts at ${solr_root}
if [[ -z ${data_dir} ]]
then
data_dir=${solr_root}/data
elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]]
then
data_dir=${solr_root}/${data_dir}
fi
dataDir
setStartTime