mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-18 23:45:52 +08:00
Update index.py
This commit is contained in:
+63
-28
@@ -31,6 +31,28 @@ def getInitDFile():
|
|||||||
return '/etc/init.d/' + getPluginName()
|
return '/etc/init.d/' + getPluginName()
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
def getConf(version):
|
||||||
|
path = getPluginDir() + "/init.d/php" + version + '.tpl'
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
def status(version):
|
def status(version):
|
||||||
data = public.execShell(
|
data = public.execShell(
|
||||||
"ps -ef|grep php |grep -v grep | grep -v python | awk '{print $2}'")
|
"ps -ef|grep php |grep -v grep | grep -v python | awk '{print $2}'")
|
||||||
@@ -39,33 +61,50 @@ def status(version):
|
|||||||
return 'start'
|
return 'start'
|
||||||
|
|
||||||
|
|
||||||
|
def initDreplace(version):
|
||||||
|
|
||||||
|
file_tpl = getConf(version)
|
||||||
|
service_path = public.getServerDir()
|
||||||
|
|
||||||
|
initD_path = getServerDir() + '/init.d'
|
||||||
|
if not os.path.exists(initD_path):
|
||||||
|
os.mkdir(initD_path)
|
||||||
|
file_bin = initD_path + '/php' + version
|
||||||
|
|
||||||
|
content = public.readFile(file_tpl)
|
||||||
|
content = content.replace('{$SERVER_PATH}', service_path)
|
||||||
|
|
||||||
|
public.writeFile(file_bin, content)
|
||||||
|
public.execShell('chmod +x ' + file_bin)
|
||||||
|
return file_bin
|
||||||
|
|
||||||
|
|
||||||
|
def phpOp(version, method):
|
||||||
|
file = initDreplace(version)
|
||||||
|
data = public.execShell(file + ' ' + method)
|
||||||
|
print data
|
||||||
|
if data[1] == '':
|
||||||
|
return 'ok'
|
||||||
|
return 'fail'
|
||||||
|
|
||||||
|
|
||||||
def start(version):
|
def start(version):
|
||||||
path = os.path.dirname(os.getcwd())
|
return phpOp(version, 'start')
|
||||||
cmd = path + "/redis/bin/redis-server"
|
|
||||||
cmd = cmd + " " + path + "/redis/redis.conf"
|
|
||||||
data = public.execShell(cmd)
|
|
||||||
if data[0] == '':
|
|
||||||
return 'ok'
|
|
||||||
return 'fail'
|
|
||||||
|
|
||||||
|
|
||||||
def stop():
|
def stop(version):
|
||||||
data = public.execShell(
|
return phpOp(version, 'stop')
|
||||||
"ps -ef|grep redis |grep -v grep |grep -v python |awk '{print $2}' | xargs kill -9")
|
|
||||||
if data[0] == '':
|
|
||||||
return 'ok'
|
|
||||||
return 'fail'
|
|
||||||
|
|
||||||
|
|
||||||
def restart():
|
def restart(version):
|
||||||
return 'ok'
|
return phpOp(version, 'restart')
|
||||||
|
|
||||||
|
|
||||||
def reload():
|
def reload(version):
|
||||||
return 'ok'
|
return phpOp(version, 'reload')
|
||||||
|
|
||||||
|
|
||||||
def runInfo():
|
def runInfo(version):
|
||||||
path = os.path.dirname(os.getcwd())
|
path = os.path.dirname(os.getcwd())
|
||||||
cmd = path + "/redis/bin/redis-cli info"
|
cmd = path + "/redis/bin/redis-cli info"
|
||||||
data = public.execShell(cmd)[0]
|
data = public.execShell(cmd)[0]
|
||||||
@@ -96,10 +135,6 @@ def runInfo():
|
|||||||
return public.getJson(result)
|
return public.getJson(result)
|
||||||
|
|
||||||
|
|
||||||
def getConf():
|
|
||||||
path = os.path.dirname(os.getcwd()) + "/redis/redis.conf"
|
|
||||||
return path
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
func = sys.argv[1]
|
func = sys.argv[1]
|
||||||
version = sys.argv[2]
|
version = sys.argv[2]
|
||||||
@@ -107,16 +142,16 @@ if __name__ == "__main__":
|
|||||||
if func == 'status':
|
if func == 'status':
|
||||||
print status(version)
|
print status(version)
|
||||||
elif func == 'start':
|
elif func == 'start':
|
||||||
print start()
|
print start(version)
|
||||||
elif func == 'stop':
|
elif func == 'stop':
|
||||||
print stop()
|
print stop(version)
|
||||||
elif func == 'restart':
|
elif func == 'restart':
|
||||||
print restart()
|
print restart(version)
|
||||||
elif func == 'reload':
|
elif func == 'reload':
|
||||||
print reload()
|
print reload(version)
|
||||||
elif func == 'run_info':
|
elif func == 'run_info':
|
||||||
print runInfo()
|
print runInfo(version)
|
||||||
elif func == 'conf':
|
elif func == 'conf':
|
||||||
print getConf()
|
print getConf(version)
|
||||||
else:
|
else:
|
||||||
print "fail"
|
print "fail"
|
||||||
|
|||||||
Reference in New Issue
Block a user