]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Add WaitConditions to HA template
authorAngus Salkeld <asalkeld@redhat.com>
Mon, 7 May 2012 10:47:28 +0000 (20:47 +1000)
committerAngus Salkeld <asalkeld@redhat.com>
Mon, 7 May 2012 10:47:28 +0000 (20:47 +1000)
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
templates/WordPress_Single_Instance_With_HA.template

index 88c49d7b3dfcb9daf3dabd8b7a13a23a851fb0ad..cd3d2eb05c87b921007b241f4a8c204d3364af79 100644 (file)
 
               "/etc/cfn/notify-on-httpd-restarted" : {
                 "content" : { "Fn::Join" : ["", [
-               "#!/bin/sh\n",
-               "logger -t cfn-event 'http got restarted'\n"
+                "#!/bin/sh\n",
+                "logger -t cfn-event 'http got restarted'\n"
                 ]]},
                 "mode"    : "000700",
                 "owner"   : "root",
                 "group"   : "root"
               },
 
+              "/tmp/setup.mysql" : {
+                "content" : { "Fn::Join" : ["", [
+                "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n",
+                "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" },
+                ".* TO '", { "Ref" : "DBUsername" }, "'@'localhost'\n",
+                "IDENTIFIED BY '", { "Ref" : "DBPassword" }, "';\n",
+                "FLUSH PRIVILEGES;\n",
+                "EXIT\n"
+                  ]]},
+                "mode"  : "000644",
+                "owner" : "root",
+                "group" : "root"
+              },
+
               "/etc/cfn/hooks.conf" : {
                 "content": { "Fn::Join" : ["", [
                   "[cfn-http-restarted]\n",
         "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 WikiDatabase ",
+          "    --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" : "DBRootPassword" }, "'\n",
-          "cat << EOF | mysql -u root --password='", { "Ref" : "DBRootPassword" }, "'\n",
-          "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n",
-          "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO \"", { "Ref" : "DBUsername" }, "\"@\"localhost\"\n",
-          "IDENTIFIED BY \"", { "Ref" : "DBPassword" }, "\";\n",
-          "FLUSH PRIVILEGES;\n",
-          "EXIT\n",
-          "EOF\n",
-          "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ /usr/share/wordpress/wp-config.php\n",
+          "mysqladmin -u root password '", { "Ref" : "DBRootPassword" },
+          "' || error_exit 'Failed to initialize root password'\n",
+
+          "mysql -u root --password='", { "Ref" : "DBRootPassword" },
+          "' < /tmp/setup.mysql || error_exit 'Failed to create database.'\n",
 
           "# install cfn-hup crontab\n",
-          "crontab /tmp/cfn-hup-crontab.txt\n"
+          "crontab /tmp/cfn-hup-crontab.txt\n",
+
+          "# All is well so signal success\n",
+          "/opt/aws/bin/cfn-signal -e 0 -r \"Wiki server setup complete\" '",
+          { "Ref" : "WaitHandle" }, "'\n"
         ]]}}
       }
+    },
+
+    "WaitHandle" : {
+      "Type" : "AWS::CloudFormation::WaitConditionHandle"
+    },
+
+    "WaitCondition" : {
+      "Type" : "AWS::CloudFormation::WaitCondition",
+      "DependsOn" : "WikiDatabase",
+      "Properties" : {
+        "Handle" : {"Ref" : "WaitHandle"},
+        "Timeout" : "300"
+      }
     }
   },