From 5e41a1ee73f146204e80b0863362fa2eb049541a Mon Sep 17 00:00:00 2001 From: Steven Dake Date: Sun, 26 Aug 2012 18:09:43 -0700 Subject: [PATCH] Make RDS (mysql) wait until setup is finished before proceeding It is possible a service dependent on RDS may issue commands to the RDS service before mysql has finished installing. Added a wait condition to force synchronization. Change-Id: I6abf2d62e92d19945c587deeb61605df2c97ec85 Signed-off-by: Steven Dake --- heat/engine/dbinstance.py | 45 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/heat/engine/dbinstance.py b/heat/engine/dbinstance.py index 5ed960aa..54bcb6cc 100644 --- a/heat/engine/dbinstance.py +++ b/heat/engine/dbinstance.py @@ -77,6 +77,16 @@ mysql_template = r''' "Resources": { + "DatabaseInstanceCfnUser" : { + "Type" : "AWS::IAM::User" + }, + "DatabaseInstanceKeys" : { + "Type" : "AWS::IAM::AccessKey", + "Properties" : { + "UserName" : {"Ref": "DatabaseInstanceCfnUser"} + } + }, + "DatabaseInstance": { "Type": "AWS::EC2::Instance", "Metadata": { @@ -104,7 +114,21 @@ mysql_template = r''' "KeyName": { "Ref": "KeyName" }, "UserData": { "Fn::Base64": { "Fn::Join": ["", [ "#!/bin/bash -v\n", - "/opt/aws/bin/cfn-init\n", + "# Helper function\n", + "function error_exit\n", + "{\n", + " /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", + { "Ref" : "WaitHandle" }, "'\n", + " exit 1\n", + "}\n", + + "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" }, + " -r DatabaseInstance", + " --access-key ", { "Ref" : "DatabaseInstanceKeys" }, + " --secret-key ", + {"Fn::GetAtt": ["DatabaseInstanceKeys", "SecretAccessKey"]}, + " --region ", { "Ref" : "AWS::Region" }, + " || error_exit 'Failed to run cfn-init'\n", "# Setup MySQL root password and create a user\n", "mysqladmin -u root password '", {"Ref":"MasterUserPassword"},"'\n", "cat << EOF | mysql -u root --password='", @@ -115,9 +139,26 @@ mysql_template = r''' "IDENTIFIED BY \"", { "Ref" : "MasterUserPassword" }, "\";\n", "FLUSH PRIVILEGES;\n", "EXIT\n", - "EOF\n" + "EOF\n", + "# Database setup completed, signal success\n", + "/opt/aws/bin/cfn-signal -e 0 -r \"MySQL server setup complete\" '", + { "Ref" : "WaitHandle" }, "'\n" + ]]}} } + }, + + "WaitHandle" : { + "Type" : "AWS::CloudFormation::WaitConditionHandle" + }, + + "WaitCondition" : { + "Type" : "AWS::CloudFormation::WaitCondition", + "DependsOn" : "DatabaseInstance", + "Properties" : { + "Handle" : {"Ref" : "WaitHandle"}, + "Timeout" : "600" + } } }, -- 2.45.2