lucene/src/scripts/optimize

100 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# $Id: optimize.template,v 1.3 2005/06/09 15:34:06 billa Exp $
# $Source: /cvs/main/searching/solar-tools/optimize.template,v $
# $Name: r20050725_standardized_server_enabled $
#
# Shell script to force a optimized commit of all changes since last commit
# for a SOLAR server
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
logMessage failed to connect to SOLAR server at port 5051
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 SOLAR at port 5051 failed:
logMessage $rs
logExit failed 2
fi
logExit ended 0