Commit 19266848 authored by Łukasz Nowak's avatar Łukasz Nowak

- implement upgrade of mysql

 - change how arguments are passed to be explicit and give responsilibty
   to runner
 - provide more useful messages


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44207 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 80eaaedd
......@@ -522,16 +522,16 @@ SSLRandomSeed connect builtin
self.substituteTemplate(self.getTemplateFilename('my.cnf.in'),
mysql_conf))
mysql_command_list = [self.options['mysql_binary'].strip(),
'--no-defaults', '-B', '--user=root',
'--socket=%s' % mysql_conf['socket'],
]
mysql_script = pkg_resources.resource_string(__name__,
'template/initmysql.sql.in') % mysql_conf
self.path_list.extend(zc.buildout.easy_install.scripts([('mysql_update',
__name__ + '.mysql', 'updateMysql')], self.ws,
sys.executable, self.wrapper_directory, arguments=[mysql_command_list,
mysql_script]))
sys.executable, self.wrapper_directory, arguments=[dict(
mysql_script=mysql_script,
mysql_binary=self.options['mysql_binary'].strip(),
mysql_upgrade_binary=self.options['mysql_upgrade_binary'].strip(),
socket=mysql_conf['socket'],
)]))
self.path_list.extend(zc.buildout.easy_install.scripts([('mysqld',
__name__ + '.mysql', 'runMysql')], self.ws,
sys.executable, self.wrapper_directory, arguments=[dict(
......
import os
import subprocess
import sys
import time
......@@ -33,21 +32,34 @@ def runMysql(args):
def updateMysql(args):
mysql_command_list = args[0]
mysql_script = args[1]
conf = args[0]
sleep = 30
is_succeed = False
while True:
if not is_succeed:
mysql = subprocess.Popen(mysql_command_list, stdin=subprocess.PIPE,
mysql_upgrade_list = [conf['mysql_upgrade_binary'], '--no-defaults', '--user=root', '--socket=%s' % conf['socket']]
mysql_upgrade = subprocess.Popen(mysql_upgrade_list, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = mysql_upgrade.communicate()[0]
if mysql_upgrade.returncode is None:
mysql_upgrade.kill()
if mysql_upgrade.returncode != 0 and not 'is already upgraded' in result:
print "Command %r failed with result:\n%s" % (mysql_upgrade_list, result)
print 'Sleeping for %ss and retrying' % sleep
else:
if mysql_upgrade.returncode == 0:
print "MySQL database upgraded with result:\n%s" % result
else:
print "No need to upgrade MySQL database"
mysql_list = [conf['mysql_binary'].strip(), '--no-defaults', '-B', '--user=root', '--socket=%s' % conf['socket']]
mysql = subprocess.Popen(mysql_list, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = mysql.communicate(mysql_script)[0]
result = mysql.communicate(conf['mysql_script'])[0]
if mysql.returncode is None:
mysql.kill()
if mysql.returncode != 0:
print 'Script failed with: %s' % result
print 'Command %r failed with:\n%s' % (mysql_list, result)
print 'Sleeping for %ss and retrying' % sleep
else:
is_succeed = True
print 'Script succesfully run on database, exiting'
print 'SlapOS initialisation script succesfully applied on database.'
time.sleep(sleep)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment