diff --git a/plugins/mysql/bak/index_2022_6_18.py b/plugins/mysql/bak/index_2022_6_18.py index 8fa90ed11..5651a0406 100755 --- a/plugins/mysql/bak/index_2022_6_18.py +++ b/plugins/mysql/bak/index_2022_6_18.py @@ -284,6 +284,19 @@ def initMysqlData(): return 1 +def initMysql57Data(): + datadir = getDataDir() + if not os.path.exists(datadir + '/mysql'): + serverdir = getServerDir() + myconf = serverdir + "/etc/my.cnf" + user = pGetDbUser() + cmd = 'cd ' + serverdir + ' && ./bin/mysqld --defaults-file=' + myconf + \ + ' --initialize --explicit_defaults_for_timestamp' + mw.execShell(cmd) + return 0 + return 1 + + def initMysql8Data(): datadir = getDataDir() if not os.path.exists(datadir + '/mysql'): @@ -328,13 +341,13 @@ def initMysql8Pwd(): data = mw.execShell( "ps -ef|grep mysql|grep -v grep|grep -v py|grep -v init.d|awk '{print $2}'") if data[0] != "": - #print("mysql start ok!") + # print("mysql start ok!") is_start = True break time.sleep(0.5) if not is_start: - #print("mysql start fail!") + # print("mysql start fail!") return False serverdir = getServerDir() @@ -348,7 +361,8 @@ def initMysql8Pwd(): if len(password) == 0: return True - #print('localhost', 3306, 'root', password, "/www/server/mysql/mysql.sock") + # print('localhost', 3306, 'root', password, + # "/www/server/mysql/mysql.sock") # import MySQLdb as mdb # dbconn = mdb.connect(host='localhost', port=3306, user='root', @@ -400,11 +414,16 @@ def myOp(version, method): def my8cmd(version, method): - # mysql 8.0 ok + # mysql 8.0 and 5.7 ok init_file = initDreplace(version) cmd = init_file + ' ' + method - try: + + if version == '5.7': + initMysql57Data() + elif version == '8.0': initMysql8Data() + try: + if not mysql8IsInitedPasswd(): setSkipGrantTables(True) cmd_init_start = init_file + ' start' @@ -433,13 +452,13 @@ def my8cmd(version, method): sub.wait(5) return 'ok' except Exception as e: - print(e) + return str(e) return 'fail' def appCMD(version, action): - if version == '8.0': + if version == '8.0' or version == '5.7': return my8cmd(version, action) return myOp(version, action) @@ -1485,7 +1504,7 @@ def getMasterStatus(version=''): db = pMysqlDb() dlist = db.query('show slave status') - #print(dlist, len(dlist)) + # print(dlist, len(dlist)) if len(dlist) > 0 and (dlist[0][10] == 'Yes' or dlist[0][11] == 'Yes'): data['slave_status'] = True diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 5651a0406..16b4ef28d 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -168,6 +168,17 @@ def initDreplace(version=''): content = contentReplace(content) mw.writeFile(mysql_conf, content) + # systemd + systemDir = '/lib/systemd/system' + systemService = systemDir + '/mysql.service' + systemServiceTpl = getPluginDir() + '/init.d/mysql.service.tpl' + if os.path.exists(systemDir) and not os.path.exists(systemService): + service_path = mw.getServerDir() + se_content = mw.readFile(systemServiceTpl) + se_content = se_content.replace('{$SERVER_PATH}', service_path) + mw.writeFile(systemService, se_content) + mw.execShell('systemctl daemon-reload') + if mw.getOs() != 'darwin': mw.execShell('chown -R mysql mysql ' + getServerDir()) return file_bin @@ -484,33 +495,26 @@ def initdStatus(): if mw.isAppleSystem(): return "Apple Computer does not support" - initd_bin = getInitDFile() - if os.path.exists(initd_bin): - return 'ok' - return 'fail' + shell_cmd = 'systemctl status mysql | grep loaded | grep "enabled;"' + data = mw.execShell(shell_cmd) + if data[0] == '': + return 'fail' + return 'ok' def initdInstall(): - import shutil - if not app_debug: - if mw.isAppleSystem(): - return "Apple Computer does not support" + if mw.isAppleSystem(): + return "Apple Computer does not support" - mysql_bin = initDreplace() - initd_bin = getInitDFile() - shutil.copyfile(mysql_bin, initd_bin) - mw.execShell('chmod +x ' + initd_bin) - mw.execShell('chkconfig --add ' + getPluginName()) + mw.execShell('systemctl enable mysql') return 'ok' def initdUinstall(): - if not app_debug: - if mw.isAppleSystem(): - return "Apple Computer does not support" - mw.execShell('chkconfig --del ' + getPluginName()) - initd_bin = getInitDFile() - os.remove(initd_bin) + if mw.isAppleSystem(): + return "Apple Computer does not support" + + mw.execShell('systemctl disable mysql') return 'ok' diff --git a/plugins/mysql/init.d/mysql.service.tpl b/plugins/mysql/init.d/mysql.service.tpl new file mode 100644 index 000000000..02da45de3 --- /dev/null +++ b/plugins/mysql/init.d/mysql.service.tpl @@ -0,0 +1,20 @@ +[Unit] +Description=MySQL Server +After=network.service + +[Service] +User=mysql +Group=mysql +Type=forking +ExecStart={$SERVER_PATH}/mysql/bin/mysqld --defaults-file={$SERVER_PATH}/mysql/etc/my.cnf --daemonize +TimeoutSec=0 +PermissionsStartOnly=true +LimitNOFILE=5000 +Restart=on-failure +RestartSec=10 +RestartPreventExitStatus=1 +PrivateTmp=false + + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/plugins/php/index.py b/plugins/php/index.py index 6cd61bd9c..07a32a82c 100755 --- a/plugins/php/index.py +++ b/plugins/php/index.py @@ -290,7 +290,7 @@ def initdStatus(version): if mw.isAppleSystem(): return "Apple Computer does not support" - shell_cmd = 'systemctl status ' + version + ' | grep loaded | grep "enabled;"' + shell_cmd = 'systemctl status php' + version + ' | grep loaded | grep "enabled;"' data = mw.execShell(shell_cmd) if data[0] == '': return 'fail'