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/docker/index.py

179 lines
3.3 KiB

2 years ago
# coding:utf-8
import sys
import io
import os
import time
import re
sys.path.append(os.getcwd() + "/class/core")
import mw
2 years ago
import docker
client = docker.from_env()
2 years ago
app_debug = False
if mw.isAppleSystem():
app_debug = True
def getPluginName():
return 'docker'
def getPluginDir():
return mw.getPluginDir() + '/' + getPluginName()
def getServerDir():
return mw.getServerDir() + '/' + getPluginName()
def getInitDFile():
if app_debug:
return '/tmp/' + getPluginName()
return '/etc/init.d/' + 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(':')
tmp[t[0]] = t[1]
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 status():
data = mw.execShell(
2 years ago
"ps -ef|grep dockerd |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'")
2 years ago
if data[0] == '':
return 'stop'
return 'start'
def initDreplace():
2 years ago
return ''
2 years ago
2 years ago
def dockerOp(method):
2 years ago
file = initDreplace()
if not mw.isAppleSystem():
2 years ago
data = mw.execShell('systemctl ' + method + ' docker')
2 years ago
if data[1] == '':
return 'ok'
return data[1]
return 'fail'
def start():
2 years ago
return dockerOp('start')
2 years ago
def stop():
2 years ago
return dockerOp('stop')
2 years ago
def restart():
2 years ago
status = dockerOp('restart')
2 years ago
log_file = runLog()
mw.execShell("echo '' > " + log_file)
return status
def reload():
2 years ago
return dockerOp('reload')
2 years ago
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'
2 years ago
def conList():
return mw.returnJson(True, 'ok')
2 years ago
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())
2 years ago
elif func == 'con_list':
print(conList())
2 years ago
else:
print('error')