sdsphinx/indexer/slave-dir.sh
2015-09-23 13:02:19 +00:00

49 lines
1.4 KiB
Bash

#!/bin/bash
MYSQL_HOST=192.168.3.30
MYSQL_USER=sphinx
MYSQL_PASS=indexer
PATH_LOG=/var/lib/sphinxsearch/log
PATH_BIN=/usr/bin
PATH_SQL=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/sql
# Indexation déjà lancé
FILEINDEX=$PATH_LOG/dir-$(date '+%Y%m%d').idx
if [ -f "$FILEINDEX" ]; then
exit 0
fi
# Indexation sur le master ?
output=$(mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS sdv1 < $PATH_SQL/slave-dir.sql)
idx='';
for line in "$output"; do
idx="$line";
done
# Suppression fin de ligne
idx=$(echo $idx|sed -e "s/^[idx ]*//g"||sed -e "s/[ ]*$//g")
echo "$(date '+%Y-%m-%d %H:%M:%S') === TENTATIVE INDEXATION DIR" >> $PATH_LOG/indexer.log
# Lancement de l'indexation
if [ -n "$idx" ]; then
if [[ "$idx" > 0 ]]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') === INDEXATION DIR" >> $PATH_LOG/indexer.log
# Create file to indicate indexing
rm -f $PATH_LOG/dir-*.idx
echo "START $(date '+%Y-%m-%d %H:%M:%S')" >> $FILEINDEX
# Sphinx rotate
echo "$(date '+%Y-%m-%d %H:%M:%S') - Sphinx - Debut" >> $PATH_LOG/indexer.log
$PATH_BIN/indexer --config /etc/sphinxsearch/sphinx.conf --rotate dir dir_phx >> $PATH_LOG/indexer.log
echo "$(date '+%Y-%m-%d %H:%M:%S') - Sphinx - Fin" >> $PATH_LOG/indexer.log
echo "FIN $(date '+%Y-%m-%d %H:%M:%S')" >> $FILEINDEX
echo "$(date '+%Y-%m-%d %H:%M:%S') === FIN INDEXATION DIR" >> $PATH_LOG/indexer.log
fi
fi