sdsphinx/indexer/indexer-ciblage.sh

46 lines
1.7 KiB
Bash

#!/bin/bash
MYSQL_HOST=ENV_MYSQLHOST
MYSQL_USER=ENV_MYSQLUSER
MYSQL_PASS=ENV_MYSQLPASS
PATH_LOG=/var/lib/sphinxsearch/log
PATH_BIN=/usr/bin
PATH_SQL=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/sql
# Is consolidated ?
output=$(mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS sdv1 < $PATH_SQL/consolidate-ciblage.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")
# Lancement de l'indexation si la consolidation a eu lieu
if [ -n "$idx" ]; then
if [[ "$idx" > 0 ]]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') === INDEXATION CIBLAGE" >> $PATH_LOG/indexer.log
# Enregistrement Debut Indexation
mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS sdv1 -e "UPDATE sphinx_idx SET indexingBegin=NOW() WHERE id=$idx" >> $PATH_LOG/indexer.log
# 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 ciblage >> $PATH_LOG/indexer.log
echo "$(date '+%Y-%m-%d %H:%M:%S') - Sphinx - Fin" >> $PATH_LOG/indexer.log
# Rotation des tables MySQL - @todo
#echo "$(date '+%Y-%m-%d %H:%M:%S') - Rotation Table - Debut" >> $PATH_LOG/indexer.log
#mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS jo < $PATH_SQL/rotate-ciblage.sql >> $PATH_LOG/indexer.log
#echo "$(date '+%Y-%m-%d %H:%M:%S') - Rotation Table - Fin" >> $PATH_LOG/indexer.log
# Enregistrement Fin Indexation
mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS sdv1 -e "UPDATE sphinx_idx SET indexingEnd=NOW() WHERE id=$idx" >> $PATH_LOG/indexer.log
echo "$(date '+%Y-%m-%d %H:%M:%S') === FIN INDEXATION CIBLAGE" >> $PATH_LOG/indexer.log
fi
fi