From 9225d5b32ef57ed479ad39cb5e83d7bc5e419ecc Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Fri, 13 Nov 2020 21:08:11 +0100 Subject: [PATCH] Obsoleted util/watch_sphinx_main_index.sh by refactoring indexer.main.sh Signed-off-by: Janos SUTO --- etc/cron.jobs.in | 1 - util/Makefile.in | 1 - util/indexer.main.sh.in | 49 +++++++++++++++++++++------------ util/watch_sphinx_main_index.sh | 3 -- 4 files changed, 32 insertions(+), 22 deletions(-) delete mode 100755 util/watch_sphinx_main_index.sh diff --git a/etc/cron.jobs.in b/etc/cron.jobs.in index c849a1e9..80d57523 100644 --- a/etc/cron.jobs.in +++ b/etc/cron.jobs.in @@ -6,7 +6,6 @@ */15 * * * * /usr/bin/indexer --config SYSCONFDIR/piler/sphinx.conf --quiet note1 --rotate */5 * * * * /usr/bin/find LOCALSTATEDIR/piler/www/tmp -type f -name i.\* -exec rm -f {} \; */5 * * * * /usr/bin/find LOCALSTATEDIR/piler/error -type f|wc -l > LOCALSTATEDIR/piler/stat/error -3 * * * * LIBEXECDIR/piler/watch_sphinx_main_index.sh 2 0 * * * LIBEXECDIR/piler/pilerpurge.py ### optional: populate accouting data diff --git a/util/Makefile.in b/util/Makefile.in index afe2701d..77c5f67b 100644 --- a/util/Makefile.in +++ b/util/Makefile.in @@ -46,7 +46,6 @@ install: $(INSTALL) -m 0755 $(srcdir)/purge.sh $(DESTDIR)$(libexecdir)/piler $(INSTALL) -m 0755 $(srcdir)/pilerpurge.py $(DESTDIR)$(libexecdir)/piler $(INSTALL) -m 0755 $(srcdir)/postinstall.sh $(DESTDIR)$(libexecdir)/piler - $(INSTALL) -m 0755 $(srcdir)/watch_sphinx_main_index.sh $(DESTDIR)$(libexecdir)/piler $(INSTALL) -m 0755 $(srcdir)/db-mysql.sql $(DESTDIR)$(datarootdir)/piler $(INSTALL) -m 0755 $(srcdir)/db-mysql-root.sql.in $(DESTDIR)$(datarootdir)/piler diff --git a/util/indexer.main.sh.in b/util/indexer.main.sh.in index 8bf1549a..28d7756e 100755 --- a/util/indexer.main.sh.in +++ b/util/indexer.main.sh.in @@ -1,34 +1,49 @@ #!/bin/bash -export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin -MAINTMPFILE=/var/run/piler/main.indexer.tmp -INDEXER="indexer --config SYSCONFDIR/piler/sphinx.conf" -PRIORITY=mail.error -TOUCHFILE=/var/piler/stat/indexer +set -o nounset +set -o errexit +set -o pipefail -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 +MAINTMPFILE="/var/run/piler/main.indexer.tmp" +SPHINX_CONFIG="SYSCONFDIR/piler/sphinx.conf" +PRIORITY="mail.error" +TOUCHFILE="/var/piler/stat/indexer" +MAIN_INDEX="main1" -date > $MAINTMPFILE +export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" -touch $TOUCHFILE - -function finish { - rm -f $MAINTMPFILE +finish() { + rm -f "$MAINTMPFILE" } + +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" + trap finish EXIT -echo "INDEXER INFO: merging to main started" | logger -p $PRIORITY +echo "INDEXER INFO: merging to main started" | logger -p "$PRIORITY" -$INDEXER --quiet --merge main1 dailydelta1 --merge-dst-range deleted 0 0 --rotate +indexer --config "$SPHINX_CONFIG" --quiet --merge "$MAIN_INDEX" dailydelta1 --merge-dst-range deleted 0 0 --rotate -echo "INDEXER INFO: merging to main finished" | logger -p $PRIORITY +echo "INDEXER INFO: merging to main finished" | logger -p "$PRIORITY" sleep 5 -echo "INDEXER INFO: resetting daily delta started" | logger -p $PRIORITY +echo "INDEXER INFO: resetting daily delta started" | logger -p "$PRIORITY" -$INDEXER --quiet dailydelta1 --rotate +indexer --config "$SPHINX_CONFIG" --quiet dailydelta1 --rotate -echo "INDEXER INFO: resetting daily delta finished" | logger -p $PRIORITY +echo "INDEXER INFO: resetting daily delta finished" | logger -p "$PRIORITY" +sum=0 +while read -r a b; do + sum=$(( sum + b )) +done < <( find /var/piler/sphinx/ -type f -name main\*.spd -printf "%TY%Tm%Td %s\\n" ) +printf "%d" $sum > /var/piler/stat/main_index_size diff --git a/util/watch_sphinx_main_index.sh b/util/watch_sphinx_main_index.sh deleted file mode 100755 index 3d330f95..00000000 --- a/util/watch_sphinx_main_index.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -find /var/piler/sphinx/ -type f -name main\*.spd -printf "%TY%Tm%Td %s\\n" | sort -r | head -1 | cut -f2 -d ' ' > /var/piler/stat/main_index_size