Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/flexible environment conf #56

Merged
merged 10 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ RUN if [ -d "/packages/" ]; then apt -y install /packages/*deb; fi \
&& tar -xf /tmp/de.pak.tgz -C /usr/share/manticore/ \
&& tar -xf /tmp/ru.pak.tgz -C /usr/share/manticore/

COPY manticore.conf /etc/manticoresearch/
RUN md5sum /etc/manticoresearch/manticore.conf|awk '{print $1}' > /manticore.conf.md5
COPY manticore.conf.sh /etc/manticoresearch/
RUN md5sum /etc/manticoresearch/manticore.conf | awk '{print $1}' > /manticore.conf.md5
COPY sandbox.sql /sandbox.sql
COPY .mysql_history /root/.mysql_history

Expand All @@ -129,7 +129,7 @@ EXPOSE 9308
EXPOSE 9312
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
CMD ["searchd", "--nodetach"]
CMD ["searchd", "-c", "/etc/manticoresearch/manticore.conf.sh", "--nodetach"]

# How to build manually:
# Prepare builder:
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,20 +264,21 @@ The settings must be prefixed with their section name, example for in case of `m
docker run -e EXTRA=1 --name manticore -p 127.0.0.1:9306:9306 -e searchd_mysql_version_string='5.5.0' -d manticoresearch/manticore
```

In case of the `listen` directive, new listening interfaces using the Docker variable `searchd_listen` in addition to the default ones. Multiple interfaces can be declared, separated by a semi-colon ("|"). To listen only on a network address, the `$ip` (retrieved internally from `hostname -i`) can be used as address alias.
If you intend to enable the own `listen` directive, utilize the `searchd_listen` environment variable.

For example `-e searchd_listen='9316:http|9307:mysql|$ip:5443:mysql_vip'` will add an additional SQL interface on port 9307, an SQL VIP listener on port 5443 running only on the instance's IP, and an HTTP listener on port 9316, in addition to the defaults on 9306 and 9308, respectively.
You can specify multiple interfaces separated by a semicolon `("|")`. To exclusively listen on a network address, employ the `$ip` variable (internally retrieved from `hostname -i`) as an address alias.
sanikolaev marked this conversation as resolved.
Show resolved Hide resolved

For instance, using `-e searchd_listen='9316:http|9307:mysql|$ip:5443:mysql_vip'` will incorporate an additional SQL interface on port `9307`,
an SQL VIP listener on port `5443` operating solely on the instance's IP (such as 172.17.0.2), and an HTTP listener on port `9316`.

**Attention**: Setting this variable overrides default listeners!

```bash
$ docker run -e EXTRA=1 --rm -p 1188:9307 -e searchd_mysql_version_string='5.5.0' -e searchd_listen='9316:http|9307:mysql|$ip:5443:mysql_vip' manticore
[Mon Aug 17 07:31:58.719 2020] [1] using config file '/etc/manticoresearch/manticore.conf' (9130 chars)...
listening on all interfaces for http, port=9316
listening on all interfaces for mysql, port=9307
listening on 172.17.0.17:5443 for VIP mysql
listening on all interfaces for mysql, port=9306
listening on UNIX socket /var/run/mysqld/mysqld.sock
listening on 172.17.0.17:9312 for sphinx
listening on all interfaces for http, port=9308
prereading 0 indexes
prereaded 0 indexes in 0.000 sec
accepting connections
Expand Down
30 changes: 30 additions & 0 deletions clt_tests/tests/config-flexible-with-custom-conf.rec
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
––– block: ./base/init –––
––– input –––
echo "" > /tmp/manticore.conf;echo $?
––– output –––
0
––– input –––
docker run --name manticore -v "/tmp/manticore.conf:/etc/manticoresearch/manticore.conf" -d -e searchd_data_dir=/var/lib/manticore -e searchd_log=/var/log/manticore/searchd.log -e searchd_max_packet_size=128M -e searchd_pid_file=/var/run/manticore/searchd.pid -e searchd_query_log_format=sphinxql -e 'searchd_listen=9306:mysql41|/var/run/mysqld/mysqld.sock:mysql41|9312|0.0.0.0:9308:http|$ip:9315-9325:replication' manticoresoftware/manticore:current
––– output –––
#!/[0-9a-z]+/!#
––– input –––
sleep 5;docker logs manticore | grep "accepting connections"
––– output –––
accepting connections
––– input –––
docker exec manticore cat /etc/manticoresearch/manticore.conf.debug
––– output –––
searchd {
query_log_format = sphinxql
log = /var/log/manticore/searchd.log
secondary_indexes = 0
buddy_path =
pid_file = /var/run/manticore/searchd.pid
listen = 9306:mysql41
listen = /var/run/mysqld/mysqld.sock:mysql41
listen = 9312
listen = 0.0.0.0:9308:http
listen = 172.18.0.2:9315-9325:replication
data_dir = /var/lib/manticore
max_packet_size = 128M
}
29 changes: 29 additions & 0 deletions clt_tests/tests/config-flexible-with-default-conf.rec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
––– block: ./base/init –––
––– input –––
docker run -d -e searchd_max_packet_size=64m -e "common_lemmatizer_base=/usr/share/manticore/" --name manticore manticoresoftware/manticore:current
––– output –––
#!/[0-9a-z]+/!#
––– input –––
sleep 5;docker logs manticore | grep "accepting connections"
––– output –––
accepting connections
––– input –––
docker exec manticore cat /etc/manticoresearch/manticore.conf.debug
––– output –––
searchd {
secondary_indexes = 0
buddy_path =
listen = 9306:mysql41
listen = /var/run/mysqld/mysqld.sock:mysql41
listen = 9308:http
listen = %{IPADDR}:9312
listen = %{IPADDR}:9315-9325:replication
max_packet_size = 64m
log = /var/log/manticore/searchd.log
query_log = /var/log/manticore/query.log
pid_file = /var/run/manticore/searchd.pid
data_dir = /var/lib/manticore
}
common {
lemmatizer_base = /usr/share/manticore/
}
49 changes: 7 additions & 42 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,17 @@ _main() {
fi
fi

confHash=$(md5sum /etc/manticoresearch/manticore.conf | awk '{print $1}')
expectedConfHash=$(cat /manticore.conf.md5)

if [[ "$confHash" == "$expectedConfHash" ]]; then
export searchd_listen='9306:mysql41|/var/run/mysqld/mysqld.sock:mysql41|9308:http|$ip:9312|$ip:9315-9325:replication'
fi

if ! _searchd_want_help "@"; then
docker_setup_env "$@"
fi

_replace_conf_from_env

BACKUP_INIT_FOLDER="/docker-entrypoint-initdb.d"

if [ -f "${BACKUP_INIT_FOLDER}/versions.json" ]; then
Expand Down Expand Up @@ -244,46 +249,6 @@ _main() {
exec "$@"
}

_replace_conf_from_env() {
# we exit in case a custom config is provided
if [ "$(md5sum /etc/manticoresearch/manticore.conf | awk '{print $1}')" != "$(cat /manticore.conf.md5)" ]; then return; fi

sed_query=""

while IFS='=' read -r oldname value; do
if [[ $oldname == 'searchd_'* || $oldname == 'common_'* ]]; then
value=$(echo ${!oldname} | sed 's/\//\\\//g')
oldname=$(echo $oldname | sed "s/searchd_//g;s/common_//g;")
newname=$oldname

if [[ $newname == 'listen' ]]; then
oldname="listen_env"
IFS='|' read -ra LISTEN_VALUES <<<"$value"
count=0

for i in "${LISTEN_VALUES[@]}"; do
if [[ $count == 0 ]]; then
value=$i
else
value="$value\n listen = $i"
fi
count=$((count + 1))
done
fi

if [[ -z $sed_query ]]; then
sed_query="s/(#\s)*?$oldname\s?=\s?.*?$/$newname = $value/g"
else
sed_query="$sed_query;s/(#\s)*?$oldname\s?=\s?.*?$/$newname = $value/g"
fi

fi
done < <(env)

if [[ ! -z $sed_query ]]; then
sed -i -E "$sed_query" /etc/manticoresearch/manticore.conf
fi
}
# If we are sourced from elsewhere, don't perform any further actions
if ! _is_sourced; then
_main "$@"
Expand Down
Loading