sphinx to systemd

pull/109/head
midoks 3 years ago
parent 49d0020e21
commit a58a0ec001
  1. 18
      plugins/sphinx/conf/sphinx.conf
  2. 72
      plugins/sphinx/index.py
  3. 12
      plugins/sphinx/init.d/sphinx.service.tpl

@ -2,10 +2,6 @@
# Minimal Sphinx configuration sample (clean, simple, functional) # Minimal Sphinx configuration sample (clean, simple, functional)
# #
indexer
{
mem_limit = 218M
}
searchd searchd
{ {
@ -13,12 +9,20 @@ searchd
listen = 9306:mysql41 listen = 9306:mysql41
log = {$SERVER_APP}/index/searchd.log log = {$SERVER_APP}/index/searchd.log
query_log = {$SERVER_APP}/index/query.log query_log = {$SERVER_APP}/index/query.log
pid_file = {$SERVER_APP}/index/searchd.pid
#workers = threads # for RT to work
binlog_path = {$SERVER_APP}/index/binlog
read_timeout = 5 read_timeout = 5
max_children = 0 max_children = 0
pid_file = {$SERVER_APP}/index/searchd.pid
seamless_rotate = 1 seamless_rotate = 1
preopen_indexes = 1 preopen_indexes = 1
unlink_old = 1 unlink_old = 1
#workers = threads # for RT to work }
binlog_path = {$SERVER_APP}/index/binlog
index mydocs
{
type = rt
path = {$SERVER_APP}/bin/doc
rt_field = title
rt_attr_json = j
} }

@ -146,6 +146,17 @@ def initDreplace():
conf_content = contentReplace(conf_content) conf_content = contentReplace(conf_content)
mw.writeFile(getServerDir() + '/sphinx.conf', conf_content) mw.writeFile(getServerDir() + '/sphinx.conf', conf_content)
# systemd
systemDir = '/lib/systemd/system'
systemService = systemDir + '/sphinx.service'
systemServiceTpl = getPluginDir() + '/init.d/sphinx.service.tpl'
if os.path.exists(systemDir) and not os.path.exists(systemService):
service_path = mw.getServerDir()
se_content = mw.readFile(systemServiceTpl)
se_content = se_content.replace('{$SERVER_PATH}', service_path)
mw.writeFile(systemService, se_content)
mw.execShell('systemctl daemon-reload')
mkdirAll() mkdirAll()
return file_bin return file_bin
@ -165,45 +176,35 @@ def checkIndexSph():
return True return True
def start(): def sphOp(method):
file = initDreplace() file = initDreplace()
data = sphinxConfParse() if not mw.isAppleSystem():
if 'index' in data: data = mw.execShell('systemctl ' + method + ' sphinx')
if checkIndexSph(): if data[1] == '':
rebuild() return 'ok'
time.sleep(5) return 'fail'
else:
return '配置不正确!'
data = mw.execShell(file + ' start') data = mw.execShell(file + ' ' + method)
if data[1] == '': if data[1] == '':
return 'ok' return 'ok'
return data[1] return data[1]
def start():
return sphOp('start')
def stop(): def stop():
file = initDreplace() return sphOp('stop')
data = mw.execShell(file + ' stop')
if data[1] == '':
return 'ok'
return data[1]
def restart(): def restart():
file = initDreplace() return sphOp('restart')
data = mw.execShell(file + ' restart')
if data[1] == '':
return 'ok'
return data[1]
def reload(): def reload():
file = initDreplace() return sphOp('reload')
data = mw.execShell(file + ' reload')
if data[1] == '':
return 'ok'
return 'fail'
def rebuild(): def rebuild():
@ -215,36 +216,29 @@ def rebuild():
def initdStatus(): def initdStatus():
if not app_debug:
if mw.isAppleSystem(): if mw.isAppleSystem():
return "Apple Computer does not support" return "Apple Computer does not support"
initd_bin = getInitDFile()
if os.path.exists(initd_bin): shell_cmd = 'systemctl status sphinx | grep loaded | grep "enabled;"'
return 'ok' data = mw.execShell(shell_cmd)
if data[0] == '':
return 'fail' return 'fail'
return 'ok'
def initdInstall(): def initdInstall():
import shutil
if not app_debug:
if mw.isAppleSystem(): if mw.isAppleSystem():
return "Apple Computer does not support" return "Apple Computer does not support"
source_bin = initDreplace() mw.execShell('systemctl enable sphinx')
initd_bin = getInitDFile()
shutil.copyfile(source_bin, initd_bin)
mw.execShell('chmod +x ' + initd_bin)
mw.execShell('chkconfig --add ' + getPluginName())
return 'ok' return 'ok'
def initdUinstall(): def initdUinstall():
if not app_debug:
if mw.isAppleSystem(): if mw.isAppleSystem():
return "Apple Computer does not support" return "Apple Computer does not support"
initd_bin = getInitDFile()
os.remove(initd_bin) mw.execShell('systemctl disable sphinx')
mw.execShell('chkconfig --del ' + getPluginName())
return 'ok' return 'ok'

@ -0,0 +1,12 @@
[Unit]
Description=Open Source Search Server
After=network.target
[Service]
Type=forking
ExecStart={$SERVER_PATH}/bin/bin/searchd -c {$SERVER_APP}/sphinx.conf
ExecReload=/bin/kill -USR2 $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
Loading…
Cancel
Save