Skip to content

Instantly share code, notes, and snippets.

@AlexeySetevoi
Last active November 27, 2018 14:42
Show Gist options
  • Save AlexeySetevoi/3487d90a3bd42410baffa74d067a701c to your computer and use it in GitHub Desktop.
Save AlexeySetevoi/3487d90a3bd42410baffa74d067a701c to your computer and use it in GitHub Desktop.
Systemd unit template to run multi-instance sphinx 2, jinja2-ansible. Sphinx 2 jinja config.
env: "dev"
sphinx_instname: "searchd-{{ env }}"
sphinx_run_path: "/var/run/sphinxsearch"
sphinx_log_path: "/var/log/sphinxsearch"
sphinx_data_path: "/var/lib/sphinxsearch/{{ sphinx_instname }}"
sphinx_confname: "{{ sphinx_instname }}.conf"
sphinx_sock_path: "{{ sphinx_run_path }}/{{ sphinx_instname }}.sock"
sphinx_pid_path: "{{ sphinx_run_path }}/{{ sphinx_instname }}.pid"
sphinx_sockmysql_path: "{{ sphinx_run_path }}/{{ sphinx_instname }}-mysql.sock"
sphinx_sockmysql_conf: "{{ sphinx_sockmysql_path }}:mysql41"
sphinx_log: "{{ sphinx_log_path }}/{{ sphinx_instname }}.log"
sphinx_querylog: "{{ sphinx_log_path }}/{{ sphinx_instname }}-query.log"
sphinx_binlog_path: "{{ sphinx_data_path }}"
#############################################################################
## data source definition
#############################################################################
source _localdb {
type = pgsql
sql_host = localhost
sql_user = {{ db_pg_user }}
sql_pass = {{ db_pg_password }}
sql_db = {{ db_pg_name }}
sql_port = {{ db_pg_passw }}
}
source test : _localdb {
sql_query = SELECT 1 as test
sql_field_string = test
sql_attr_string = weight
sql_ranged_throttle = 0
}
#############################################################################
## index definition
#############################################################################
index testindex {
source = test
path = {{ sphinx_data_path }}/test
docinfo = extern
mlock = 0
morphology = stem_en
min_word_len = 1
html_strip = 0
}
#############################################################################
## indexer settings
#############################################################################
indexer {
mem_limit = 256M
# max_iops = 40 max_iosize = 1048576 max_xmlpipe2_field = 4M write_buffer = 1M max_file_field_buffer = 32M
}
#############################################################################
## searchd settings
#############################################################################
searchd {
listen = {{ sphinx_sock_path }}
listen = {{ sphinx_sockmysql_conf }}
log = {{ sphinx_log }}
query_log = {{ sphinx_querylog }}
read_timeout = 5
client_timeout = 300
max_children = 30
pid_file = {{ sphinx_pid_path }}
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
# attr_flush_period = 900 ondisk_dict_default = 1
mva_updates_pool = 1M
max_packet_size = 8M
# crash_log_path = /var/log/sphinxsearch/crash
max_filters = 256
max_filter_values = 4096
# listen_backlog = 5 read_buffer = 256K read_unhinted = 32K
max_batch_queries = 32
# subtree_docs_cache = 4M subtree_hits_cache = 8M
workers = threads # for RT to work
# dist_threads = 4 binlog_path = # disable logging
binlog_path = {{ sphinx_binlog_path }}
# binlog.001 etc will be created there binlog_max_log_size = 256M thread_stack = 128K expansion_limit = 1000 rt_flush_period = 900 query_log_format = sphinxql mysql_version_string = 5.0.37 plugin_dir =
# /usr/local/sphinx/lib collation_server = utf8_general_ci collation_libc_locale = ru_RU.UTF-8 watchdog = 1 compat_sphinxql_magics = 1
}
# --eof--
[Unit]
Description=SphinxSearch Search Engine for %I
After=network.target remote-fs.target nss-lookup.target
After=syslog.target
[Service]
Type=forking
User=sphinxsearch
Group=sphinxsearch
# Run ExecStartPre with root-permissions
PermissionsStartOnly=true
ExecStartPre=/bin/mkdir -p {{ sphinx_run_path }}
ExecStartPre=/bin/chown sphinxsearch.sphinxsearch {{ sphinx_run_path }}
# Run ExecStart with User=sphinxsearch / Group=sphinxsearch
ExecStart=/usr/bin/searchd --config /etc/sphinxsearch/%i.conf
ExecStop=/usr/bin/searchd --config /etc/sphinxsearch/%i.conf --stopwait
KillMode=process
KillSignal=SIGTERM
SendSIGKILL=no
LimitNOFILE=infinity
PIDFile={{ sphinx_run_path }}/%i.pid
[Install]
WantedBy=multi-user.target
[email protected]
[email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment