bug fix: remote mysql install

This commit is contained in:
Usman Nasir
2020-07-05 13:26:46 +05:00
parent 575551d1fa
commit 758273dbc6
3 changed files with 35 additions and 10 deletions

View File

@@ -92,6 +92,7 @@ def get_Ubuntu_release():
class preFlightsChecks: class preFlightsChecks:
debug = 1
cyberPanelMirror = "mirror.cyberpanel.net/pip" cyberPanelMirror = "mirror.cyberpanel.net/pip"
cdn = 'cyberpanel.sh' cdn = 'cyberpanel.sh'
@@ -429,6 +430,11 @@ class preFlightsChecks:
else: else:
writeDataToFile.writelines(items) writeDataToFile.writelines(items)
if self.distro == ubuntu:
os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
writeDataToFile.close()
if self.remotemysql == 'ON': if self.remotemysql == 'ON':
command = "sed -i 's|'HOST': 'localhost',|'HOST': '%s',|g' %s" % (self.mysqlhost, path) command = "sed -i 's|'HOST': 'localhost',|'HOST': '%s',|g' %s" % (self.mysqlhost, path)
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
@@ -439,11 +445,6 @@ class preFlightsChecks:
command = "sed -i 's|'PORT':''|'PORT':'%s'|g' %s" % (self.mysqlport, path) command = "sed -i 's|'PORT':''|'PORT':'%s'|g' %s" % (self.mysqlport, path)
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
if self.distro == ubuntu:
os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
writeDataToFile.close()
logging.InstallLog.writeToFile("settings.py updated!") logging.InstallLog.writeToFile("settings.py updated!")
#self.setupVirtualEnv(self.distro) #self.setupVirtualEnv(self.distro)
@@ -2164,6 +2165,11 @@ def main():
mysqluser = args.mysqluser mysqluser = args.mysqluser
mysqlpassword = args.mysqlpassword mysqlpassword = args.mysqlpassword
mysqlport = args.mysqlport mysqlport = args.mysqlport
if preFlightsChecks.debug:
print('mysqlhost: %s, mysqluser: %s, mysqlpassword: %s, mysqlport: %s' % (mysqlhost, mysqluser, mysqlpassword, mysqlport))
time.sleep(10)
else: else:
remotemysql = args.remotemysql remotemysql = args.remotemysql
mysqlhost = '' mysqlhost = ''

View File

@@ -8,6 +8,7 @@ import errno
import MySQLdb as mariadb import MySQLdb as mariadb
import install import install
from os.path import exists from os.path import exists
import time
#distros #distros
centos=0 centos=0
@@ -630,6 +631,11 @@ def Main(cwd, mysql, distro, ent, serial = None, port = "8090", ftp = None, dns
writeToFile.write(dumps(mysqlData)) writeToFile.write(dumps(mysqlData))
writeToFile.close() writeToFile.close()
if install.preFlightsChecks.debug:
print(open(file_name, 'r').read())
time.sleep(10)
try: try:
command = 'chmod 640 %s' % (file_name) command = 'chmod 640 %s' % (file_name)
@@ -668,9 +674,6 @@ def Main(cwd, mysql, distro, ent, serial = None, port = "8090", ftp = None, dns
mysqlUtilities.createDatabase("cyberpanel","cyberpanel", InstallCyberPanel.mysqlPassword) mysqlUtilities.createDatabase("cyberpanel","cyberpanel", InstallCyberPanel.mysqlPassword)
import time
time.sleep(10)
if ftp == None: if ftp == None:
installer.installPureFTPD() installer.installPureFTPD()
installer.installPureFTPDConfigurations(mysql) installer.installPureFTPDConfigurations(mysql)

View File

@@ -1,4 +1,6 @@
import subprocess, shlex import subprocess, shlex
import install
import time
class mysqlUtilities: class mysqlUtilities:
@@ -6,14 +8,16 @@ class mysqlUtilities:
def createDatabase(dbname, dbuser, dbpassword): def createDatabase(dbname, dbuser, dbpassword):
try: try:
createDB = "CREATE DATABASE " + dbname
try: try:
from json import loads from json import loads
mysqlData = loads(open("/etc/cyberpanel/mysqlPassword", 'r').read()) mysqlData = loads(open("/etc/cyberpanel/mysqlPassword", 'r').read())
createDB = "CREATE DATABASE " + dbname
initCommand = 'mysql -h %s --port %s -u %s -p%s -e "' % (mysqlData['mysqlhost'], mysqlData['mysqlport'], mysqlData['mysqluser'], mysqlData['mysqlpassword']) initCommand = 'mysql -h %s --port %s -u %s -p%s -e "' % (mysqlData['mysqlhost'], mysqlData['mysqlport'], mysqlData['mysqluser'], mysqlData['mysqlpassword'])
except: except:
passFile = "/etc/cyberpanel/mysqlPassword" passFile = "/etc/cyberpanel/mysqlPassword"
@@ -21,11 +25,14 @@ class mysqlUtilities:
data = f.read() data = f.read()
password = data.split('\n', 1)[0] password = data.split('\n', 1)[0]
createDB = "CREATE DATABASE " + dbname
initCommand = 'mysql -u root -p' + password + ' -e "' initCommand = 'mysql -u root -p' + password + ' -e "'
command = initCommand + createDB + '"' command = initCommand + createDB + '"'
if install.preFlightsChecks.debug:
print(command)
time.sleep(10)
cmd = shlex.split(command) cmd = shlex.split(command)
res = subprocess.call(cmd) res = subprocess.call(cmd)
@@ -36,6 +43,10 @@ class mysqlUtilities:
command = initCommand + createUser + '"' command = initCommand + createUser + '"'
if install.preFlightsChecks.debug:
print(command)
time.sleep(10)
cmd = shlex.split(command) cmd = shlex.split(command)
res = subprocess.call(cmd) res = subprocess.call(cmd)
@@ -44,6 +55,11 @@ class mysqlUtilities:
else: else:
dropDB = "GRANT ALL PRIVILEGES ON " + dbname + ".* TO '" + dbuser + "'@'localhost'" dropDB = "GRANT ALL PRIVILEGES ON " + dbname + ".* TO '" + dbuser + "'@'localhost'"
command = initCommand + dropDB + '"' command = initCommand + dropDB + '"'
if install.preFlightsChecks.debug:
print(command)
time.sleep(10)
cmd = shlex.split(command) cmd = shlex.split(command)
res = subprocess.call(cmd) res = subprocess.call(cmd)