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

193 lines
4.3 KiB

7 years ago
# coding:utf-8
import sys
import io
import os
import time
sys.path.append(os.getcwd() + "/class/core")
import public
6 years ago
app_debug = False
if public.isAppleSystem():
app_debug = True
7 years ago
6 years ago
def getPluginName():
return 'mysql'
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()
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 getConf():
path = getServerDir() + '/conf/my.cnf'
return path
def getInitdTpl():
path = getPluginDir() + '/init.d/mysql.tpl'
return path
def contentReplace(content):
service_path = public.getServerDir()
content = content.replace('{$ROOT_PATH}', public.getRootDir())
content = content.replace('{$SERVER_PATH}', service_path)
return content
def initDreplace():
initd_tpl = getInitdTpl()
initD_path = getServerDir() + '/init.d'
if not os.path.exists(initD_path):
os.mkdir(initD_path)
file_bin = initD_path + '/' + getPluginName()
if not os.path.exists(file_bin):
content = public.readFile(initd_tpl)
content = contentReplace(content)
public.writeFile(file_bin, content)
public.execShell('chmod +x ' + file_bin)
mysql_conf_dir = getServerDir() + '/conf'
if not os.path.exists(mysql_conf_dir):
os.mkdir(mysql_conf_dir)
mysql_conf = mysql_conf_dir + '/my.cnf'
if not os.path.exists(mysql_conf):
mysql_conf_tpl = getPluginDir() + '/conf/my.cnf'
content = public.readFile(mysql_conf_tpl)
content = contentReplace(content)
public.writeFile(mysql_conf, content)
return file_bin
7 years ago
def status():
data = public.execShell(
6 years ago
"ps -ef|grep mysqld |grep -v grep | grep -v python | awk '{print $2}'")
7 years ago
if data[0] == '':
return 'stop'
return 'start'
def start():
6 years ago
init_file = initDreplace()
6 years ago
initMysql = getServerDir() + '/scripts/mysql_install_db ' + '--basedir=' + \
getServerDir() + ' --datadir=' + getServerDir() + '/bin/mysql/data'
6 years ago
return initMysql
6 years ago
cmd = getServerDir() + '/bin/mysqld_safe ' + getServerDir() + \
'/conf/my.cnf ' + '--user=mysql&'
6 years ago
# return cmd
7 years ago
data = public.execShell(cmd)
if data[0] == '':
6 years ago
return 'stop'
return data[0]
7 years ago
def stop():
data = public.execShell(
6 years ago
"ps -ef|grep mysql |grep -v grep |grep -v python |awk '{print $2}' | xargs kill -9")
7 years ago
if data[0] == '':
return 'ok'
return 'fail'
def restart():
return 'ok'
def reload():
return 'ok'
6 years ago
def initdStatus():
if not app_debug:
if public.isAppleSystem():
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:
if public.isAppleSystem():
return "Apple Computer does not support"
mysql_bin = initDreplace()
initd_bin = getInitDFile()
shutil.copyfile(mysql_bin, initd_bin)
public.execShell('chmod +x ' + initd_bin)
return 'ok'
def initdUinstall():
if not app_debug:
if public.isAppleSystem():
return "Apple Computer does not support"
initd_bin = getInitDFile()
os.remove(initd_bin)
return 'ok'
7 years ago
if __name__ == "__main__":
func = sys.argv[1]
6 years ago
if func == 'status':
7 years ago
print status()
elif func == 'start':
print start()
elif func == 'stop':
print stop()
elif func == 'restart':
print restart()
elif func == 'reload':
print reload()
6 years ago
elif func == 'initd_status':
print initdStatus()
elif func == 'initd_install':
print initdInstall()
elif func == 'initd_uninstall':
print initdUinstall()
elif func == 'run_info':
print runInfo()
elif func == 'conf':
print getConf()
else:
print 'error'