Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/plugins/sphinx/index.py

213 lines
4.6 KiB

6 years ago
# coding:utf-8
import sys
import io
import os
import time
6 years ago
import re
6 years ago
sys.path.append(os.getcwd() + "/class/core")
import public
app_debug = False
if public.isAppleSystem():
app_debug = True
def getPluginName():
return 'sphinx'
def getPluginDir():
return public.getPluginDir() + '/' + getPluginName()
def getServerDir():
return public.getServerDir() + '/' + getPluginName()
def getInitDFile():
if app_debug:
return '/tmp/' + getPluginName()
return '/etc/init.d/' + getPluginName()
6 years ago
def getConfTpl():
path = getPluginDir() + "/conf/sphinx.conf"
return path
6 years ago
def getConf():
6 years ago
path = getServerDir() + "/sphinx.conf"
6 years ago
return path
def getInitDTpl():
path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl"
return path
def getArgs():
args = sys.argv[2:]
tmp = {}
args_len = len(args)
if args_len == 1:
t = args[0].strip('{').strip('}')
t = t.split(':')
tmp[t[0]] = t[1]
elif args_len > 1:
for i in range(len(args)):
t = args[i].split(':')
tmp[t[0]] = t[1]
return tmp
6 years ago
def contentReplace(content):
service_path = public.getServerDir()
content = content.replace('{$ROOT_PATH}', public.getRootDir())
content = content.replace('{$SERVER_PATH}', service_path)
6 years ago
content = content.replace('{$SERVER_APP}', service_path + '/sphinx')
return content
6 years ago
6 years ago
def status():
data = public.execShell(
6 years ago
"ps -ef|grep sphinx |grep -v grep | grep -v python | awk '{print $2}'")
6 years ago
if data[0] == '':
return 'stop'
return 'start'
def initDreplace():
file_tpl = getInitDTpl()
service_path = os.path.dirname(os.getcwd())
initD_path = getServerDir() + '/init.d'
if not os.path.exists(initD_path):
os.mkdir(initD_path)
file_bin = initD_path + '/' + getPluginName()
# initd replace
content = public.readFile(file_tpl)
6 years ago
content = contentReplace(content)
6 years ago
public.writeFile(file_bin, content)
public.execShell('chmod +x ' + file_bin)
# config replace
6 years ago
conf_bin = getConf()
if not os.path.exists(conf_bin):
conf_content = public.readFile(getConfTpl())
conf_content = contentReplace(conf_content)
public.writeFile(getServerDir() + '/sphinx.conf', conf_content)
6 years ago
return file_bin
def start():
file = initDreplace()
data = public.execShell(file + ' start')
6 years ago
if data[0] == '':
6 years ago
return 'ok'
6 years ago
return data[0]
6 years ago
def stop():
file = initDreplace()
data = public.execShell(file + ' stop')
6 years ago
if data[0] == '':
6 years ago
return 'ok'
6 years ago
return data[0]
6 years ago
def restart():
file = initDreplace()
data = public.execShell(file + ' restart')
6 years ago
if data[0] == '':
6 years ago
return 'ok'
6 years ago
return data[0]
6 years ago
def reload():
file = initDreplace()
data = public.execShell(file + ' reload')
if data[1] == '':
return 'ok'
return 'fail'
def initdStatus():
if not app_debug:
6 years ago
if public.isAppleSystem():
6 years ago
return "Apple Computer does not support"
initd_bin = getInitDFile()
if os.path.exists(initd_bin):
return 'ok'
return 'fail'
def initdInstall():
import shutil
if not app_debug:
6 years ago
if public.isAppleSystem():
6 years ago
return "Apple Computer does not support"
source_bin = initDreplace()
initd_bin = getInitDFile()
shutil.copyfile(source_bin, initd_bin)
public.execShell('chmod +x ' + initd_bin)
return 'ok'
def initdUinstall():
if not app_debug:
6 years ago
if public.isAppleSystem():
6 years ago
return "Apple Computer does not support"
initd_bin = getInitDFile()
os.remove(initd_bin)
return 'ok'
6 years ago
def runLog():
path = getConf()
content = public.readFile(path)
rep = 'log\s*=\s*(.*)'
tmp = re.search(rep, content)
return tmp.groups()[0]
def queryLog():
path = getConf()
content = public.readFile(path)
rep = 'query_log\s*=\s*(.*)'
tmp = re.search(rep, content)
return tmp.groups()[0]
6 years ago
if __name__ == "__main__":
func = sys.argv[1]
if func == 'status':
print status()
elif func == 'start':
print start()
elif func == 'stop':
print stop()
elif func == 'restart':
print restart()
elif func == 'reload':
print reload()
elif func == 'initd_status':
print initdStatus()
elif func == 'initd_install':
print initdInstall()
elif func == 'initd_uninstall':
print initdUinstall()
elif func == 'conf':
print getConf()
elif func == 'run_log':
print runLog()
6 years ago
elif func == 'query_log':
print queryLog()
6 years ago
else:
print 'error'