2006-01-26 00:37:29 -05:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2006-03-02 23:33:24 -05:00
|
|
|
# $Id$
|
|
|
|
# $Source: /cvs/main/searching/solr-tools/optimize.template,v $
|
2006-01-26 00:37:29 -05:00
|
|
|
# $Name: r20050725_standardized_server_enabled $
|
|
|
|
|
|
|
|
#
|
|
|
|
# Shell script to force a optimized commit of all changes since last commit
|
2006-03-02 23:33:24 -05:00
|
|
|
# for a Solr server
|
2006-01-26 00:37:29 -05:00
|
|
|
|
|
|
|
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
|
|
|
|
|
|
|
|
# sudo to app user if necessary
|
|
|
|
if [[ $(whoami) != app ]]
|
|
|
|
then
|
|
|
|
sudo -u app $0 "$@"
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
oldwhoami=$(who -m | cut -d' ' -f1 | sed -e's/^.*!//')
|
|
|
|
|
|
|
|
if [[ "${oldwhoami}" == "" ]]
|
|
|
|
then
|
|
|
|
oldwhoami=`ps h -Hfp $(pgrep -g0 ${0##*/}) | tail -1|cut -f1 -d" "`
|
|
|
|
fi
|
|
|
|
|
|
|
|
# set up variables
|
|
|
|
prog=${0##*/}
|
|
|
|
log=logs/${prog}.log
|
|
|
|
|
|
|
|
# define usage string
|
|
|
|
USAGE="\
|
|
|
|
usage: $prog [ -v ]
|
|
|
|
-v increase verbosity
|
|
|
|
"
|
|
|
|
|
|
|
|
unset verbose
|
|
|
|
|
|
|
|
# parse args
|
|
|
|
originalargs="$@"
|
|
|
|
while getopts v OPTION
|
|
|
|
do
|
|
|
|
case $OPTION in
|
|
|
|
v)
|
|
|
|
verbose="v"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "$USAGE"
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(( OPTIND - 1 ))
|
|
|
|
|
|
|
|
start=`date +"%s"`
|
|
|
|
|
|
|
|
function timeStamp
|
|
|
|
{
|
|
|
|
date +'%Y%m%d-%H%M%S'
|
|
|
|
}
|
|
|
|
|
|
|
|
function logMessage
|
|
|
|
{
|
|
|
|
echo $(timeStamp) $@>>$log
|
|
|
|
if [[ -n ${verbose} ]]
|
|
|
|
then
|
|
|
|
echo $@
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function logExit
|
|
|
|
{
|
|
|
|
end=`date +"%s"`
|
|
|
|
diff=`expr $end - $start`
|
|
|
|
echo "$(timeStamp) $1 (elapsed time: $diff sec)">>$log
|
|
|
|
exit $2
|
|
|
|
}
|
|
|
|
|
|
|
|
cd ${0%/*}/../..
|
|
|
|
logMessage started by $oldwhoami
|
|
|
|
logMessage command: $0 $originalargs
|
|
|
|
|
|
|
|
rs=`curl http://localhost:5051/update -s -d "<optimize/>"`
|
|
|
|
if [[ $? != 0 ]]
|
|
|
|
then
|
2006-03-02 23:33:24 -05:00
|
|
|
logMessage failed to connect to Solr server at port 5051
|
2006-01-26 00:37:29 -05:00
|
|
|
logMessage optimize failed
|
|
|
|
logExit failed 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check status of optimize request
|
|
|
|
rc=`echo $rs|cut -f2 -d'"'`
|
|
|
|
if [[ $? != 0 ]]
|
|
|
|
then
|
2006-03-02 23:33:24 -05:00
|
|
|
logMessage optimize request to Solr at port 5051 failed:
|
2006-01-26 00:37:29 -05:00
|
|
|
logMessage $rs
|
|
|
|
logExit failed 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
logExit ended 0
|