piler/util/indexer.main.sh.in

63 lines
1.6 KiB
Bash
Raw Permalink Normal View History

2013-07-09 10:12:42 +02:00
#!/bin/bash
set -o nounset
set -o errexit
set -o pipefail
2013-07-09 10:12:42 +02:00
MAINTMPFILE="/var/run/piler/main.indexer.tmp"
CONFIG_FILE="SYSCONFDIR/piler/sphinx.conf"
INDEXDIR=sphinx
PRIORITY="mail.info"
TOUCHFILE="/var/piler/stat/indexer"
MAIN_INDEX="main1"
2013-07-09 10:12:42 +02:00
if [[ -f SYSCONFDIR/piler/MANTICORE ]]; then
CONFIG_FILE=SYSCONFDIR/piler/manticore.conf
INDEXDIR=manticore
fi
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
2013-07-09 10:12:42 +02:00
finish() {
rm -f "$MAINTMPFILE"
2013-07-09 10:12:42 +02:00
}
get_index_size() {
local mainfiles="$1"
local sum=0
# shellcheck disable=SC2034
while read -r a b; do
sum=$(( sum + b ))
done < <( find /var/piler/${INDEXDIR}/ -type f -name "$mainfiles" -printf "%TY%Tm%Td %s\\n" )
printf "%d" $sum
}
if [[ -f "$MAINTMPFILE" ]]; then
echo "INDEXER ERROR: indexer merging to main index is already running. It started at $(cat "$MAINTMPFILE")" | logger -p "$PRIORITY"
exit 1
fi
date > "$MAINTMPFILE"
touch "$TOUCHFILE"
2013-07-09 10:12:42 +02:00
trap finish EXIT
echo "INDEXER INFO: merging to main started" | logger -p "$PRIORITY"
2013-07-09 10:12:42 +02:00
indexer --config "$CONFIG_FILE" --quiet --merge "$MAIN_INDEX" dailydelta1 --merge-dst-range deleted 0 0 --rotate
2013-07-09 10:12:42 +02:00
echo "INDEXER INFO: merging to main finished" | logger -p "$PRIORITY"
2013-07-09 10:12:42 +02:00
sleep 5
echo "INDEXER INFO: resetting daily delta started" | logger -p "$PRIORITY"
2013-07-09 10:12:42 +02:00
indexer --config "$CONFIG_FILE" --quiet dailydelta1 --rotate
2013-07-09 10:12:42 +02:00
echo "INDEXER INFO: resetting daily delta finished" | logger -p "$PRIORITY"
2013-07-09 10:12:42 +02:00
get_index_size "main*.sp[dp]" > /var/piler/stat/total_index_size
get_index_size "${MAIN_INDEX}*.sp[dp]" > /var/piler/stat/current_main_index_size