Commit 7d185eac authored by Vincent Pelletier's avatar Vincent Pelletier

Exit loop when database is created.

parent ce45dbdc
...@@ -42,52 +42,50 @@ def updateMysql(args): ...@@ -42,52 +42,50 @@ def updateMysql(args):
sleep = 30 sleep = 30
is_succeed = False is_succeed = False
while True: while True:
if not is_succeed: mysql_upgrade_list = [conf['mysql_upgrade_binary'], '--no-defaults', '--user=root', '--socket=%s' % conf['socket']]
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)
mysql_upgrade = subprocess.Popen(mysql_upgrade_list, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) result = mysql_upgrade.communicate()[0]
result = mysql_upgrade.communicate()[0] if mysql_upgrade.returncode is None:
if mysql_upgrade.returncode is None: mysql_upgrade.kill()
mysql_upgrade.kill() if mysql_upgrade.returncode != 0 and not 'is already upgraded' in result:
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 "Command %r failed with result:\n%s" % (mysql_upgrade_list, result) else:
print 'Sleeping for %ss and retrying' % sleep if mysql_upgrade.returncode == 0:
print "MySQL database upgraded with result:\n%s" % result
else: else:
if mysql_upgrade.returncode == 0: print "No need to upgrade MySQL database"
print "MySQL database upgraded with result:\n%s" % result mysql_list = [conf['mysql_binary'].strip(), '--no-defaults', '-B', '--user=root', '--socket=%s' % conf['socket']]
else: mysql = subprocess.Popen(mysql_list, stdin=subprocess.PIPE,
print "No need to upgrade MySQL database" stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
mysql_list = [conf['mysql_binary'].strip(), '--no-defaults', '-B', '--user=root', '--socket=%s' % conf['socket']] result = mysql.communicate(conf['mysql_script'])[0]
mysql = subprocess.Popen(mysql_list, stdin=subprocess.PIPE, if mysql.returncode is None:
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) mysql.kill()
result = mysql.communicate(conf['mysql_script'])[0] if mysql.returncode != 0:
if mysql.returncode is None: print 'Command %r failed with:\n%s' % (mysql_list, result)
mysql.kill() else:
# import timezone database
mysql_tzinfo_to_sql_binary = os.path.join(
os.path.dirname(conf['mysql_binary'].strip()), 'mysql_tzinfo_to_sql')
zoneinfo_directory = '%s/zoneinfo' % os.path.dirname(pytz.__file__)
mysql_tzinfo_to_sql_list = [mysql_tzinfo_to_sql_binary, zoneinfo_directory]
mysql_tzinfo_to_sql = subprocess.Popen(mysql_tzinfo_to_sql_list, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
timezone_sql = mysql_tzinfo_to_sql.communicate()[0]
if mysql.returncode != 0: if mysql.returncode != 0:
print 'Command %r failed with:\n%s' % (mysql_list, result) print 'Command %r failed with:\n%s' % (mysql_tzinfo_to_sql_list, result)
print 'Sleeping for %ss and retrying' % sleep
else: else:
# import timezone database mysql = subprocess.Popen(mysql_list + ['mysql',], stdin=subprocess.PIPE,
mysql_tzinfo_to_sql_binary = os.path.join( stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
os.path.dirname(conf['mysql_binary'].strip()), 'mysql_tzinfo_to_sql') result = mysql.communicate(timezone_sql)[0]
zoneinfo_directory = '%s/zoneinfo' % os.path.dirname(pytz.__file__) if mysql.returncode is None:
mysql_tzinfo_to_sql_list = [mysql_tzinfo_to_sql_binary, zoneinfo_directory] mysql.kill()
mysql_tzinfo_to_sql = subprocess.Popen(mysql_tzinfo_to_sql_list, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
timezone_sql = mysql_tzinfo_to_sql.communicate()[0]
if mysql.returncode != 0: if mysql.returncode != 0:
print 'Command %r failed with:\n%s' % (mysql_tzinfo_to_sql_list, result) print 'Command %r failed with:\n%s' % (mysql_list, result)
print 'Sleeping for %ss and retrying' % sleep is_succeed = True
else: if is_succeed:
mysql = subprocess.Popen(mysql_list + ['mysql',], stdin=subprocess.PIPE, print 'SlapOS initialisation script succesfully applied on database.'
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) break
result = mysql.communicate(timezone_sql)[0] print 'Sleeping for %ss and retrying' % sleep
if mysql.returncode is None:
mysql.kill()
if mysql.returncode != 0:
print 'Command %r failed with:\n%s' % (mysql_list, result)
print 'Sleeping for %ss and retrying' % sleep
is_succeed = True
print 'SlapOS initialisation script succesfully applied on database.'
sys.stdout.flush() sys.stdout.flush()
sys.stderr.flush() sys.stderr.flush()
time.sleep(sleep) 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