-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from foxdalas/v2
fix exporter for version 2,3,4
- Loading branch information
Showing
11 changed files
with
269 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
version: "3.9" | ||
services: | ||
# exporter: | ||
# container_name: exporter | ||
# command: | ||
# - "--sphinx.address=sphinx" | ||
# - "--sphinx.port=3306" | ||
# build: | ||
# context: . | ||
# dockerfile: Dockerfile.compose | ||
# ports: | ||
# - "9247:9247" | ||
sphinx: | ||
container_name: sphinx | ||
build: | ||
context: tests/sphinx-2 | ||
ports: | ||
- "3306:3306" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
FROM ubuntu:xenial | ||
MAINTAINER romeOz <[email protected]> | ||
|
||
ENV OS_LOCALE="en_US.UTF-8" \ | ||
OS_LANGUAGE="en_US:en" \ | ||
SPHINX_LOG_DIR=/var/log/sphinxsearch \ | ||
SPHINX_CONF=/etc/sphinxsearch/sphinx.conf \ | ||
SPHINX_RUN=/run/sphinxsearch/searchd.pid \ | ||
SPHINX_DATA_DIR=/var/lib/sphinxsearch/data | ||
|
||
RUN buildDeps='software-properties-common python-software-properties' \ | ||
&& apt-get update && apt-get install -y $buildDeps locales --no-install-recommends \ | ||
&& add-apt-repository -y ppa:builds/sphinxsearch-rel22 \ | ||
&& apt-get update \ | ||
&& apt-get install -y sudo sphinxsearch \ | ||
&& mv -f /etc/sphinxsearch/sphinx.conf /etc/sphinxsearch/origin.sphinx.conf \ | ||
&& apt-get purge -y --auto-remove $buildDeps \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
# Forward sphinx logs to docker log collector | ||
&& ln -sf /dev/stdout ${SPHINX_LOG_DIR}/searchd.log \ | ||
&& ln -sf /dev/stdout ${SPHINX_LOG_DIR}/query.log | ||
|
||
# Set the locale | ||
RUN locale-gen ${OS_LOCALE} | ||
ENV LANG=${OS_LOCALE} \ | ||
LANGUAGE=${OS_LANGUAGE} \ | ||
LC_ALL=${OS_LOCALE} | ||
|
||
COPY ./entrypoint.sh /sbin/entrypoint.sh | ||
RUN chmod 755 /sbin/entrypoint.sh | ||
RUN mkdir -p /var/lib/sphinxsearch/index/ | ||
|
||
COPY ./sphinx.conf /etc/sphinxsearch/ | ||
|
||
COPY ./docs.xml /opt/ | ||
|
||
RUN indexer --all --config "/etc/sphinxsearch/sphinx.conf" | ||
|
||
|
||
EXPOSE 3306 | ||
VOLUME ["${SPHINX_DATA_DIR}"] | ||
ENTRYPOINT ["/sbin/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- http://sphinxsearch.com/docs/current/xmlpipe2.html --> | ||
<sphinx:docset> | ||
<sphinx:schema> | ||
<sphinx:field name="subject"/> | ||
<sphinx:field name="content"/> | ||
</sphinx:schema> | ||
<sphinx:document id="1234"> | ||
<content>this is the main content <![CDATA[[and this <cdata> entry | ||
must be handled properly by xml parser lib]]></content> | ||
<published>1012325463</published> | ||
<subject>note how field/attr tags can be | ||
in <b class="red">randomized</b> order</subject> | ||
<misc>some undeclared element</misc> | ||
</sphinx:document> | ||
<sphinx:document id="1235"> | ||
<subject>another subject</subject> | ||
<content>here comes another document, and i am given to understand, | ||
that in-document field order must not matter, sir</content> | ||
<published>1012325467</published> | ||
</sphinx:document> | ||
</sphinx:docset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
SPHINX_MODE=${SPHINX_MODE:-} | ||
SPHINX_BACKUP_DIR=${SPHINX_BACKUP_DIR:-"/tmp/backup"} | ||
SPHINX_BACKUP_FILENAME=${SPHINX_BACKUP_FILENAME:-"backup.last.tar.gz"} | ||
SPHINX_RESTORE=${SPHINX_RESTORE:-} | ||
SPHINX_CHECK=${SPHINX_CHECK:-} | ||
INDEX_NAME=${INDEX_NAME:-} | ||
SPHINX_ROTATE_BACKUP=${SPHINX_ROTATE_BACKUP:-true} | ||
|
||
create_backup_dir() { | ||
if [[ ! -d ${SPHINX_BACKUP_DIR}/ ]]; then | ||
mkdir -p ${SPHINX_BACKUP_DIR}/ | ||
fi | ||
chmod -R 0755 ${SPHINX_BACKUP_DIR} | ||
} | ||
|
||
create_data_dir() { | ||
mkdir -p ${SPHINX_DATA_DIR} | ||
chmod -R 0700 ${SPHINX_DATA_DIR} | ||
} | ||
|
||
rotate_backup() | ||
{ | ||
echo "Rotate backup..." | ||
|
||
if [[ ${SPHINX_ROTATE_BACKUP} == true ]]; then | ||
WEEK=$(date +"%V") | ||
MONTH=$(date +"%b") | ||
let "INDEX = WEEK % 5" || true | ||
if [[ ${INDEX} == 0 ]]; then | ||
INDEX=4 | ||
fi | ||
|
||
test -e ${SPHINX_BACKUP_DIR}/backup.${INDEX}.tar.gz && rm ${SPHINX_BACKUP_DIR}/backup.${INDEX}.tar.gz | ||
mv ${SPHINX_BACKUP_DIR}/backup.tar.gz ${SPHINX_BACKUP_DIR}/backup.${INDEX}.tar.gz | ||
echo "Create backup file: ${SPHINX_BACKUP_DIR}/backup.${INDEX}.tar.gz" | ||
|
||
test -e ${SPHINX_BACKUP_DIR}/backup.${MONTH}.tar.gz && rm ${SPHINX_BACKUP_DIR}/backup.${MONTH}.tar.gz | ||
ln ${SPHINX_BACKUP_DIR}/backup.${INDEX}.tar.gz ${SPHINX_BACKUP_DIR}/backup.${MONTH}.tar.gz | ||
echo "Create backup file: ${SPHINX_BACKUP_DIR}/backup.${MONTH}.tar.gz" | ||
|
||
test -e ${SPHINX_BACKUP_DIR}/backup.last.tar.gz && rm ${SPHINX_BACKUP_DIR}/backup.last.tar.gz | ||
ln ${SPHINX_BACKUP_DIR}/backup.${INDEX}.tar.gz ${SPHINX_BACKUP_DIR}/backup.last.tar.gz | ||
echo "Create backup file: ${SPHINX_BACKUP_DIR}/backup.last.tar.gz" | ||
else | ||
mv ${SPHINX_BACKUP_DIR}/backup.tar.gz ${SPHINX_BACKUP_DIR}/backup.last.tar.gz | ||
echo "Create backup file: ${SPHINX_BACKUP_DIR}/backup.last.tar.gz" | ||
fi | ||
} | ||
|
||
import_backup() | ||
{ | ||
echo "Import dump..." | ||
FILE=$1 | ||
if [[ ${FILE} == default ]]; then | ||
FILE="${SPHINX_BACKUP_DIR}/${SPHINX_BACKUP_FILENAME}" | ||
fi | ||
if [[ ! -f "${FILE}" ]]; then | ||
echo "Unknown backup: ${FILE}" | ||
exit 1 | ||
fi | ||
create_data_dir | ||
tar -C ${SPHINX_DATA_DIR} -xf ${FILE} | ||
} | ||
|
||
sed -i "s~SPHINX_DATA_DIR~${SPHINX_DATA_DIR}~g" ${SPHINX_CONF} | ||
sed -i "s~SPHINX_LOG_DIR~${SPHINX_LOG_DIR}~g" ${SPHINX_CONF} | ||
sed -i "s~SPHINX_RUN~${SPHINX_RUN}~g" ${SPHINX_CONF} | ||
|
||
if [[ ${SPHINX_MODE} == indexing ]]; then | ||
indexer --config ${SPHINX_CONF} --all | ||
fi | ||
|
||
if [[ ${SPHINX_MODE} == backup ]]; then | ||
echo "Backup..." | ||
if [[ ! -d ${SPHINX_DATA_DIR} ]]; then | ||
echo "No such directory: ${SPHINX_DATA_DIR}" | ||
exit 1 | ||
fi | ||
create_backup_dir | ||
cd ${SPHINX_DATA_DIR} | ||
tar --ignore-failed-read -zcvf ${SPHINX_BACKUP_DIR}/backup.tar.gz *.sp* *.ram *.kill *.meta binlog.* | ||
cd - | ||
rotate_backup | ||
exit 0 | ||
fi | ||
|
||
# Restore from backup | ||
if [[ -n ${SPHINX_RESTORE} ]]; then | ||
import_backup ${SPHINX_RESTORE} | ||
fi | ||
|
||
# Check backup | ||
if [[ -n ${SPHINX_CHECK} ]]; then | ||
|
||
echo "Check backup..." | ||
if [[ -z ${INDEX_NAME} ]]; then | ||
echo "Unknown database. INDEX_NAME does not null" | ||
exit 1; | ||
fi | ||
|
||
if [[ ! -d ${SPHINX_DATA_DIR} || -z $(ls -A ${SPHINX_DATA_DIR}) ]]; then | ||
import_backup ${SPHINX_CHECK} | ||
fi | ||
|
||
if [[ $(indextool --config ${SPHINX_CONF} --check ${INDEX_NAME} | grep -w "check passed") ]]; then | ||
echo "Success checking backup" | ||
else | ||
echo "Fail checking backup" | ||
exit 1 | ||
fi | ||
|
||
exit 0 | ||
fi | ||
|
||
# allow arguments to be passed to Sphinx search | ||
if [[ ${1:0:1} = '-' ]]; then | ||
EXTRA_OPTS="$@" | ||
set -- | ||
fi | ||
|
||
# default behaviour is to launch Sphinx search | ||
if [[ -z ${1} ]]; then | ||
echo "Starting Sphinx search demon..." | ||
exec $(which searchd) --config ${SPHINX_CONF} --nodetach ${EXTRA_OPTS} | ||
else | ||
exec "$@" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
source xml | ||
{ | ||
type = xmlpipe2 | ||
xmlpipe_fixup_utf8 = 1 | ||
xmlpipe_command = cat /opt/docs.xml | ||
} | ||
|
||
index test_index | ||
{ | ||
source = xml | ||
path = /var/lib/sphinxsearch/index/test_index | ||
|
||
# @see http://sphinxsearch.com/docs/2.0.1/conf-blend-chars.html | ||
blend_chars = - | ||
|
||
# CALL SUGGEST | ||
min_infix_len = 3 | ||
|
||
# wsparcie dla polskich znaków | ||
# @see http://sphinxsearch.com/wiki/doku.php?id=charset_tables#polish | ||
charset_table = 0..9, A..Z->a..z, a..z, U+0143->U+0144, U+0104->U+0105, U+0106->U+0107, U+0118->U+0119, U+0141->U+0142, U+00D3->U+00F3, U+015A->U+015B, U+0179->U+017A, U+017B->U+017C, U+0105, U+0107, U+0119, U+0142, U+00F3, U+015B, U+017A, U+017C, U+0144 | ||
} | ||
|
||
indexer | ||
{ | ||
mem_limit = 256M | ||
} | ||
|
||
searchd | ||
{ | ||
listen = 3306:mysql41 | ||
log = /var/log/searchd.log | ||
query_log = /var/log/query.log | ||
query_log_format = sphinxql | ||
pid_file = SPHINX_RUN | ||
|
||
# binlogs | ||
binlog_path = # disable logging | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.