mirror of https://github.com/midoks/mdserver-web
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.
187 lines
3.5 KiB
187 lines
3.5 KiB
# coding:utf-8
|
|
|
|
import sys
|
|
import io
|
|
import os
|
|
import time
|
|
import re
|
|
|
|
sys.path.append(os.getcwd() + "/class/core")
|
|
import mw
|
|
|
|
import docker
|
|
|
|
|
|
app_debug = False
|
|
if mw.isAppleSystem():
|
|
app_debug = True
|
|
|
|
|
|
def getDClient():
|
|
try:
|
|
client = docker.from_env()
|
|
except Exception as e:
|
|
client = docker.DockerClient(
|
|
base_url='unix:///Users/midoks/.docker/run/docker.sock')
|
|
return client
|
|
|
|
|
|
def getPluginName():
|
|
return 'docker'
|
|
|
|
|
|
def getPluginDir():
|
|
return mw.getPluginDir() + '/' + getPluginName()
|
|
|
|
|
|
def getServerDir():
|
|
return mw.getServerDir() + '/' + getPluginName()
|
|
|
|
|
|
def getConf():
|
|
path = getServerDir() + "/redis.conf"
|
|
return path
|
|
|
|
|
|
def getConfTpl():
|
|
path = getPluginDir() + "/config/redis.conf"
|
|
return path
|
|
|
|
|
|
def getInitDTpl():
|
|
path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl"
|
|
return path
|
|
|
|
|
|
def getArgs():
|
|
args = sys.argv[3:]
|
|
tmp = {}
|
|
args_len = len(args)
|
|
|
|
if args_len == 1:
|
|
t = args[0].strip('{').strip('}')
|
|
if t.strip() == '':
|
|
tmp = []
|
|
else:
|
|
t = t.split(':', 1)
|
|
tmp[t[0]] = t[1]
|
|
tmp[t[0]] = t[1]
|
|
elif args_len > 1:
|
|
for i in range(len(args)):
|
|
t = args[i].split(':', 1)
|
|
tmp[t[0]] = t[1]
|
|
return tmp
|
|
|
|
|
|
def status():
|
|
data = mw.execShell(
|
|
"ps -ef|grep docker |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'")
|
|
|
|
if data[0] == '':
|
|
return 'stop'
|
|
return 'start'
|
|
|
|
|
|
def initDreplace():
|
|
return ''
|
|
|
|
|
|
def dockerOp(method):
|
|
file = initDreplace()
|
|
|
|
if not mw.isAppleSystem():
|
|
data = mw.execShell('systemctl ' + method + ' docker')
|
|
if data[1] == '':
|
|
return 'ok'
|
|
return data[1]
|
|
return 'fail'
|
|
|
|
|
|
def start():
|
|
return dockerOp('start')
|
|
|
|
|
|
def stop():
|
|
return dockerOp('stop')
|
|
|
|
|
|
def restart():
|
|
status = dockerOp('restart')
|
|
|
|
log_file = runLog()
|
|
mw.execShell("echo '' > " + log_file)
|
|
return status
|
|
|
|
|
|
def reload():
|
|
return dockerOp('reload')
|
|
|
|
|
|
def initdStatus():
|
|
if mw.isAppleSystem():
|
|
return "Apple Computer does not support"
|
|
|
|
shell_cmd = 'systemctl status ' + \
|
|
getPluginName() + ' | grep loaded | grep "enabled;"'
|
|
data = mw.execShell(shell_cmd)
|
|
if data[0] == '':
|
|
return 'fail'
|
|
return 'ok'
|
|
|
|
|
|
def initdInstall():
|
|
if mw.isAppleSystem():
|
|
return "Apple Computer does not support"
|
|
|
|
mw.execShell('systemctl enable ' + getPluginName())
|
|
return 'ok'
|
|
|
|
|
|
def initdUinstall():
|
|
if mw.isAppleSystem():
|
|
return "Apple Computer does not support"
|
|
|
|
mw.execShell('systemctl disable ' + getPluginName())
|
|
return 'ok'
|
|
|
|
|
|
def conList():
|
|
|
|
c = getDClient()
|
|
|
|
clist = c.containers.list(all=True)
|
|
|
|
print(clist)
|
|
return mw.returnJson(True, 'ok')
|
|
|
|
|
|
def runLog():
|
|
return getServerDir() + '/data/redis.log'
|
|
|
|
|
|
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())
|
|
elif func == 'con_list':
|
|
print(conList())
|
|
else:
|
|
print('error')
|
|
|