mysql up systemd

pull/109/head
midoks 3 years ago
parent 1b01f9c4c3
commit fe47f5c77c
  1. 35
      plugins/mysql/bak/index_2022_6_18.py
  2. 32
      plugins/mysql/index.py
  3. 20
      plugins/mysql/init.d/mysql.service.tpl
  4. 2
      plugins/php/index.py

@ -284,6 +284,19 @@ def initMysqlData():
return 1 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(): def initMysql8Data():
datadir = getDataDir() datadir = getDataDir()
if not os.path.exists(datadir + '/mysql'): if not os.path.exists(datadir + '/mysql'):
@ -328,13 +341,13 @@ def initMysql8Pwd():
data = mw.execShell( data = mw.execShell(
"ps -ef|grep mysql|grep -v grep|grep -v py|grep -v init.d|awk '{print $2}'") "ps -ef|grep mysql|grep -v grep|grep -v py|grep -v init.d|awk '{print $2}'")
if data[0] != "": if data[0] != "":
#print("mysql start ok!") # print("mysql start ok!")
is_start = True is_start = True
break break
time.sleep(0.5) time.sleep(0.5)
if not is_start: if not is_start:
#print("mysql start fail!") # print("mysql start fail!")
return False return False
serverdir = getServerDir() serverdir = getServerDir()
@ -348,7 +361,8 @@ def initMysql8Pwd():
if len(password) == 0: if len(password) == 0:
return True 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 # import MySQLdb as mdb
# dbconn = mdb.connect(host='localhost', port=3306, user='root', # dbconn = mdb.connect(host='localhost', port=3306, user='root',
@ -400,11 +414,16 @@ def myOp(version, method):
def my8cmd(version, method): def my8cmd(version, method):
# mysql 8.0 ok # mysql 8.0 and 5.7 ok
init_file = initDreplace(version) init_file = initDreplace(version)
cmd = init_file + ' ' + method cmd = init_file + ' ' + method
try:
if version == '5.7':
initMysql57Data()
elif version == '8.0':
initMysql8Data() initMysql8Data()
try:
if not mysql8IsInitedPasswd(): if not mysql8IsInitedPasswd():
setSkipGrantTables(True) setSkipGrantTables(True)
cmd_init_start = init_file + ' start' cmd_init_start = init_file + ' start'
@ -433,13 +452,13 @@ def my8cmd(version, method):
sub.wait(5) sub.wait(5)
return 'ok' return 'ok'
except Exception as e: except Exception as e:
print(e) return str(e)
return 'fail' return 'fail'
def appCMD(version, action): def appCMD(version, action):
if version == '8.0': if version == '8.0' or version == '5.7':
return my8cmd(version, action) return my8cmd(version, action)
return myOp(version, action) return myOp(version, action)
@ -1485,7 +1504,7 @@ def getMasterStatus(version=''):
db = pMysqlDb() db = pMysqlDb()
dlist = db.query('show slave status') 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'): if len(dlist) > 0 and (dlist[0][10] == 'Yes' or dlist[0][11] == 'Yes'):
data['slave_status'] = True data['slave_status'] = True

@ -168,6 +168,17 @@ def initDreplace(version=''):
content = contentReplace(content) content = contentReplace(content)
mw.writeFile(mysql_conf, 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': if mw.getOs() != 'darwin':
mw.execShell('chown -R mysql mysql ' + getServerDir()) mw.execShell('chown -R mysql mysql ' + getServerDir())
return file_bin return file_bin
@ -484,33 +495,26 @@ def initdStatus():
if mw.isAppleSystem(): if mw.isAppleSystem():
return "Apple Computer does not support" return "Apple Computer does not support"
initd_bin = getInitDFile() shell_cmd = 'systemctl status mysql | grep loaded | grep "enabled;"'
if os.path.exists(initd_bin): data = mw.execShell(shell_cmd)
return 'ok' if data[0] == '':
return 'fail' return 'fail'
return 'ok'
def initdInstall(): def initdInstall():
import shutil
if not app_debug:
if mw.isAppleSystem(): if mw.isAppleSystem():
return "Apple Computer does not support" return "Apple Computer does not support"
mysql_bin = initDreplace() mw.execShell('systemctl enable mysql')
initd_bin = getInitDFile()
shutil.copyfile(mysql_bin, initd_bin)
mw.execShell('chmod +x ' + initd_bin)
mw.execShell('chkconfig --add ' + getPluginName())
return 'ok' return 'ok'
def initdUinstall(): def initdUinstall():
if not app_debug:
if mw.isAppleSystem(): if mw.isAppleSystem():
return "Apple Computer does not support" return "Apple Computer does not support"
mw.execShell('chkconfig --del ' + getPluginName())
initd_bin = getInitDFile() mw.execShell('systemctl disable mysql')
os.remove(initd_bin)
return 'ok' return 'ok'

@ -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

@ -290,7 +290,7 @@ def initdStatus(version):
if mw.isAppleSystem(): if mw.isAppleSystem():
return "Apple Computer does not support" 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) data = mw.execShell(shell_cmd)
if data[0] == '': if data[0] == '':
return 'fail' return 'fail'

Loading…
Cancel
Save