diff --git a/.gitignore b/.gitignore index 86909aa52..324660097 100644 --- a/.gitignore +++ b/.gitignore @@ -119,3 +119,4 @@ data/site.pl data/admin_path.pl data/close.pl ssl/input.pl +data/datadir.pl diff --git a/class/core/config_api.py b/class/core/config_api.py index dfb048748..69ba2aa9b 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -15,7 +15,7 @@ from flask import request class config_api: - __version = '0.2.1' + __version = '0.3.7' def __init__(self): pass diff --git a/plugins/mysql/index.html b/plugins/mysql/index.html index 104612b6a..b8e4ec2ba 100755 --- a/plugins/mysql/index.html +++ b/plugins/mysql/index.html @@ -31,6 +31,7 @@
服务
自启动
配置文件
+存储位置
端口
当前状态
性能优化
diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index e14bc3344..aceff5ef6 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -151,10 +151,6 @@ def getDataDir(): def binLog(): args = getArgs() - # data = checkArgs(args, ['status']) - # if not data[0]: - # return data[1] - conf = getConf() con = public.readFile(conf) @@ -163,7 +159,7 @@ def binLog(): return public.returnJson(False, '0') con = con.replace('#log-bin=mysql-bin', 'log-bin=mysql-bin') con = con.replace('#binlog_format=mixed', 'binlog_format=mixed') - os.system('sync') + public.execShell('sync') restart() else: path = getDataDir() @@ -177,9 +173,9 @@ def binLog(): return public.returnJson(True, dsize) con = con.replace('log-bin=mysql-bin', '#log-bin=mysql-bin') con = con.replace('binlog_format=mixed', '#binlog_format=mixed') - os.system('sync') + public.execShell('sync') restart() - os.system('rm -f ' + path + '/mysql-bin.*') + public.execShell('rm -f ' + path + '/mysql-bin.*') public.writeFile(conf, con) return public.returnJson(True, '设置成功!') @@ -195,12 +191,14 @@ def getErrorLog(): if n == 'error.log': filename = path + '/' + n break + print filename if not os.path.exists(filename): return public.returnJson(False, '指定文件不存在!') if args.has_key('close'): public.writeFile(filename, '') - return public.returnJson(True, '日志已清空') - return public.getNumLines(filename, 1000) + return public.returnJson(False, '日志已清空') + info = public.getNumLines(filename, 1000) + return public.returnJson(True, 'OK', info) def getShowLogFile(): @@ -307,6 +305,57 @@ def initdUinstall(): return 'ok' +def getMyDbPos(): + file = getConf() + content = public.readFile(file) + rep = 'datadir\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + + +def setMyDbPos(): + args = getArgs() + data = checkArgs(args, ['datadir']) + if not data[0]: + return data[1] + + s_datadir = getMyDbPos() + t_datadir = args['datadir'] + if t_datadir == s_datadir: + return public.returnJson(False, '与当前存储目录相同,无法迁移文件!') + + if not os.path.exists(t_datadir): + public.execShell('mkdir -p ' + t_datadir) + + # public.execShell('/etc/init.d/mysqld stop') + stop() + public.execShell('cp -rf ' + s_datadir + '/* ' + t_datadir + '/') + public.execShell('chown -R mysql.mysql ' + t_datadir) + public.execShell('chmod -R 755 ' + t_datadir) + public.execShell('rm -f ' + t_datadir + '/*.pid') + public.execShell('rm -f ' + t_datadir + '/*.err') + + path = getServerDir() + myfile = path + '/etc/my.cnf' + mycnf = public.readFile(myfile) + public.writeFile(path + '/etc/my_backup.cnf', mycnf) + + mycnf = mycnf.replace(s_datadir, t_datadir) + public.writeFile(myfile, mycnf) + start() + + result = public.execShell( + 'ps aux|grep mysqld| grep -v grep|grep -v python') + if len(result[0]) > 10: + public.writeFile('data/datadir.pl', t_datadir) + return public.returnJson(True, '存储目录迁移成功!') + else: + public.execShell('pkill -9 mysqld') + public.writeFile(myfile, public.readFile(path + '/etc/my_backup.cnf')) + start() + return public.returnJson(False, '文件迁移失败!') + + def getMyPort(): file = getConf() content = public.readFile(file) @@ -317,8 +366,9 @@ def getMyPort(): def setMyPort(): args = getArgs() - if not 'port' in args: - return 'port missing' + data = checkArgs(args, ['port']) + if not data[0]: + return data[1] port = args['port'] file = getConf() @@ -586,8 +636,10 @@ def syncToDatabases(): def setRootPwd(): args = getArgs() - if not 'password' in args: - return 'password missing' + data = checkArgs(args, ['password']) + if not data[0]: + return data[1] + password = args['password'] try: pdb = pMysqlDb() @@ -648,15 +700,31 @@ def setUserPwd(): return isError pdb.execute("flush privileges") psdb.where("id=?", (id,)).setField('password', newpassword) - return public.returnJson(True, public.getInfo('修改数据库[{1}]密码成功!', (name))) + return public.returnJson(True, public.getInfo('修改数据库[{1}]密码成功!', (name,))) except Exception as ex: - print str(ex) - return public.returnJson(False, public.getInfo('修改数据库[{1}]密码失败!', (name))) + # print str(ex) + return public.returnJson(False, public.getInfo('修改数据库[{1}]密码失败!', (name,))) -def addDb(): +def setDbPs(): args = getArgs() + data = checkArgs(args, ['id', 'name', 'ps']) + if not data[0]: + return data[1] + ps = args['ps'] + sid = args['id'] + name = args['name'] + try: + psdb = pSqliteDb('databases') + psdb.where("id=?", (sid,)).setField('ps', ps) + return public.returnJson(True, public.getInfo('修改数据库[{1}]备注成功!', (name,))) + except Exception as e: + return public.returnJson(True, public.getInfo('修改数据库[{1}]备注失败!', (name,))) + + +def addDb(): + args = getArgs() data = checkArgs(args, ['password', 'name', 'codeing', 'db_user', 'dataAccess', 'ps']) if not data[0]: @@ -990,6 +1058,10 @@ if __name__ == "__main__": print getErrorLog() elif func == 'show_log': print getShowLogFile() + elif func == 'my_db_pos': + print getMyDbPos() + elif func == 'set_db_pos': + print setMyDbPos() elif func == 'my_port': print getMyPort() elif func == 'set_my_port': @@ -1014,6 +1086,8 @@ if __name__ == "__main__": print getDbAccess() elif func == 'set_db_access': print setDbAccess() + elif func == 'set_db_ps': + print setDbPs() elif func == 'get_db_info': print getDbInfo() elif func == 'repair_table': diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index d8ed8ed4e..09b6b695c 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -88,6 +88,26 @@ function runInfo(){ } +function myDbPos(){ + myPost('my_db_pos','',function(data){ + var con = '