Update index.py

pull/109/head
midoks 4 years ago
parent 5f55ea6327
commit b6d3e52212
  1. 88
      plugins/mysql/index.py

@ -70,8 +70,8 @@ def getConf():
return path return path
def getInitdTpl(): def getInitdTpl(version=''):
path = getPluginDir() + '/init.d/mysql.tpl' path = getPluginDir() + '/init.d/mysql' + version + '.tpl'
return path return path
@ -105,8 +105,8 @@ def pMysqlDb():
return db return db
def initDreplace(): def initDreplace(version=''):
initd_tpl = getInitdTpl() initd_tpl = getInitdTpl(version)
initD_path = getServerDir() + '/init.d' initD_path = getServerDir() + '/init.d'
if not os.path.exists(initD_path): if not os.path.exists(initD_path):
@ -125,7 +125,7 @@ def initDreplace():
mysql_conf = mysql_conf_dir + '/my.cnf' mysql_conf = mysql_conf_dir + '/my.cnf'
if not os.path.exists(mysql_conf): if not os.path.exists(mysql_conf):
mysql_conf_tpl = getPluginDir() + '/conf/my.cnf' mysql_conf_tpl = getPluginDir() + '/conf/my' + version + '.cnf'
content = mw.readFile(mysql_conf_tpl) content = mw.readFile(mysql_conf_tpl)
content = contentReplace(content) content = contentReplace(content)
mw.writeFile(mysql_conf, content) mw.writeFile(mysql_conf, content)
@ -133,7 +133,7 @@ def initDreplace():
return file_bin return file_bin
def status(): def status(version=''):
data = mw.execShell( data = mw.execShell(
"ps -ef|grep mysqld |grep -v grep | grep -v python | awk '{print $2}'") "ps -ef|grep mysqld |grep -v grep | grep -v python | awk '{print $2}'")
if data[0] == '': if data[0] == '':
@ -229,6 +229,18 @@ def initMysqlData():
return 1 return 1
def initMysql8Data():
datadir = getDataDir()
if not os.path.exists(datadir + '/mysql'):
serverdir = getServerDir()
user = pGetDbUser()
cmd = 'cd ' + serverdir + ' && ./bin/mysqld --basedir=' + serverdir + ' --datadir=' + \
datadir + ' --initialize'
mw.execShell(cmd)
return 0
return 1
def initMysqlPwd(): def initMysqlPwd():
time.sleep(5) time.sleep(5)
@ -241,6 +253,18 @@ def initMysqlPwd():
return True return True
def initMysql8Pwd():
time.sleep(2)
serverdir = getServerDir()
pwd = mw.getRandomString(16)
cmd_pass = serverdir + '/bin/mysql -uroot password ' + pwd
pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,))
print mw.execShell(cmd_pass)
return True
def myOp(method): def myOp(method):
import commands import commands
init_file = initDreplace() init_file = initDreplace()
@ -249,27 +273,50 @@ def myOp(method):
initData = initMysqlData() initData = initMysqlData()
subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True,
bufsize=4096, stderr=subprocess.PIPE) bufsize=4096, stderr=subprocess.PIPE)
if (initData == 0): if initData == 0:
initMysqlPwd() initMysqlPwd()
return 'ok' return 'ok'
except Exception as e: except Exception as e:
return str(e) return str(e)
def start(): def my8cmd(version, method):
return myOp('start') init_file = initDreplace(version)
cmd = init_file + ' ' + method
try:
print(cmd)
initData = initMysql8Data()
subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True,
bufsize=4096, stderr=subprocess.PIPE)
if initData == 0:
initMysql8Pwd()
return 'ok'
except Exception as e:
print(e)
return 'fail'
def appCMD(version, action):
if version == '8.0':
return my8cmd(version, action)
return myOp(action)
def start(version):
return appCMD(version, 'start')
def stop(): def stop(version):
return myOp('stop') return appCMD(version, 'stop')
def restart(): def restart(version):
return myOp('restart') return appCMD(version, 'restart')
def reload(): def reload(version):
return myOp('reload') return appCMD(version, 'reload')
def initdStatus(): def initdStatus():
@ -1030,16 +1077,17 @@ def getTotalStatistics():
if __name__ == "__main__": if __name__ == "__main__":
func = sys.argv[1] func = sys.argv[1]
version = sys.argv[2]
if func == 'status': if func == 'status':
print status() 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 == 'initd_status': elif func == 'initd_status':
print initdStatus() print initdStatus()
elif func == 'initd_install': elif func == 'initd_install':

Loading…
Cancel
Save