Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
254 lines (247 sloc) 8.98 KB
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Template for <%= pkg_base %> server on EC2",
"Parameters" : {
"KeyName" : {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance",
"Type" : "String"
},
"InstanceType": {
"Default": "<%= default_instance_type %>",
"Description": "Type of EC2 instances for the <%= pkg_base %> servers",
"Type": "String"
},
"PackageURL" : {
"Description" : "URL to <%= pkg_base %> server software package",
"Type" : "String",
"Default" : "<%= pkg_url %>"
},
"RESTPassword" : {
"NoEcho": "true",
"Description" : "Password for REST Administrator API and web-console interface",
"Type" : "String"
},
"RAMPerServer" : {
"Description" : "RAM quota in MB for each node in the cluster",
"Type" : "Number",
"Default" : "500",
"MinValue" : "200"
},
"RAMForDefaultBucket" : {
"Description" : "RAM quota in MB for each node for the default bucket. Should be <= RAMPerServer. Set to 0 for no default bucket.",
"Type" : "Number",
"Default" : "500",
"MinValue" : "0"
},
"ExistingClusterHostPort" : {
"Description" : "Optional 'host:port', if you want to join new node(s) to an existing cluster node. Leave as 'host:port' to not join to an existing cluster",
"Type" : "String",
"Default" : "host:port"
},
"UserTag" : {
"Description" : "Optional tag value, to help track your launched EC2 instances",
"Type" : "String",
"Default" : "none"
},
"AfterInstall" : {
"Description" : "Optional single-line sh script to run after install, before configuration/join.",
"Type" : "String",
"Default" : "#"
},
"AfterConfigure" : {
"Description" : "Optional single-line sh script to run after configuration/join.",
"Type" : "String",
"Default" : "#"
}
<% if pkg_base == 'couchbase' %>
,
"NumVBuckets" : {
"Description" : "Optional number of vbuckets.",
"Type" : "String",
"Default" : "default"
}
<% end %>
},
"Mappings" : {
"AWSInstanceType2Arch" : {
<% if pkg_64 %>
"m1.large" : { "Arch" : "64" },
"m1.xlarge" : { "Arch" : "64" },
"m2.xlarge" : { "Arch" : "64" },
"m2.2xlarge" : { "Arch" : "64" },
"m2.4xlarge" : { "Arch" : "64" },
"c1.xlarge" : { "Arch" : "64" },
"cc1.4xlarge" : { "Arch" : "64" }
<% else %>
"m1.small" : { "Arch" : "32" },
"c1.medium" : { "Arch" : "32" }
<% end %>
},
"AWSRegionArch2AMI" : {
"us-east-1" : { "32" : "ami-7f418316", "64" : "ami-7341831a" },
"us-west-1" : { "32" : "ami-951945d0", "64" : "ami-971945d2" },
"eu-west-1" : { "32" : "ami-24506250", "64" : "ami-20506254" },
"ap-southeast-1" : { "32" : "ami-74dda626", "64" : "ami-7edda62c" },
"ap-northeast-1" : { "32" : "ami-dcfa4edd", "64" : "ami-e8fa4ee9" }
}
},
"Resources" : {
<% for i in (0..(num_instances - 1)) %>
"ServerNode<%= i %>" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"KeyName" : { "Ref" : "KeyName" },
"SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ],
"ImageId": {
"Fn::FindInMap": [
"AWSRegionArch2AMI",
{
"Ref": "AWS::Region"
},
{
"Fn::FindInMap": [
"AWSInstanceType2Arch",
{
"Ref": "InstanceType"
},
"Arch"
]
}
]
},
"InstanceType" : { "Ref" : "InstanceType" },
"Tags" : [ {
"Key" : "Name",
"Value" : { "Fn::Join" : ["", [ { "Ref" : "AWS::StackName" }, "-<%= i %>" ]]}
}, {
"Key" : "PackageURL",
"Value" : { "Ref" : "PackageURL" }
}, {
"Key" : "UserTag",
"Value" : { "Ref" : "UserTag" }
}
],
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash -ex","\n",
"yum -y install openssl098e","\n",
"wget ", { "Ref" : "PackageURL" },"\n",
"rpm -i <%= pkg_base %>-server-<%= pkg_ver %>*.rpm","\n",
"/bin/sh -c \"", { "Ref" : "AfterInstall" }, "\"\n",
"sleep 5","\n",
<% if pkg_base == 'couchbase' %>
"if [ \"default\" != \"", { "Ref" : "NumVBuckets" }, "\" ]; then","\n",
" wget https://raw.github.com/couchbaselabs/rampup/master/after-install","\n",
" chmod a+x after-install","\n",
" ./after-install ", { "Ref" : "NumVBuckets" },"\n",
"fi","\n",
<% end %>
"if [ \"host:port\" != \"", { "Ref" : "ExistingClusterHostPort" }, "\" ]; then","\n",
" echo Existing <%= pkg_base %> cluster...","\n",
" /opt/<%= pkg_base %>/bin/<%= cli %> server-add",
" -u Administrator -p ", { "Ref" : "RESTPassword" },
" -c ", { "Ref" : "ExistingClusterHostPort" },
" --server-add=`hostname -i`:8091","\n",
"else","\n",
" echo New <%= pkg_base %> cluster...","\n",
<% if i == 0 %>
" /opt/<%= pkg_base %>/bin/<%= cli %> cluster-init -c 127.0.0.1",
" --cluster-init-username=Administrator",
" --cluster-init-password=", { "Ref" : "RESTPassword" },
" --cluster-init-ramsize=", { "Ref" : "RAMPerServer" },"\n",
" if [ \"0\" != \"", { "Ref" : "RAMForDefaultBucket" }, "\" ]; then","\n",
" /opt/<%= pkg_base %>/bin/<%= cli %> bucket-create -c 127.0.0.1",
" -u Administrator -p ", { "Ref" : "RESTPassword" },
" --bucket=default",
" --bucket-type=<%= pkg_base %>",
" --bucket-password=",
" --bucket-ramsize=", { "Ref" : "RAMForDefaultBucket" },
" --bucket-replica=1","\n",
" fi","\n",
<% else %>
" /opt/<%= pkg_base %>/bin/<%= cli %> server-add",
" -u Administrator -p ", { "Ref" : "RESTPassword" },
" -c ", { "Fn::GetAtt" : [ "ServerNode0", "PublicIp" ] },
" --server-add=`hostname -i`:8091","\n",
<% end %>
"fi","\n",
"/bin/sh -c \"", { "Ref" : "AfterConfigure" }, "\"\n"
<% if i == 0 %>
,
"curl -X PUT -H 'Content-Type:' --data-binary '{\"Status\" : \"SUCCESS\",",
"\"Reason\" : \"ServerNode0 node is ready\",",
"\"UniqueId\" : \"<%= pkg_base %>\",",
"\"Data\" : \"Done\"}' ",
"\"", {"Ref" : "WaitForServerNode0WaitHandle"}, "\"\n"
<% end %>
]]}}
}
<% if i > 0 %>
,
"DependsOn" : "WaitForServerNode0"
<% end %>
},
<% end %>
"InstanceSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" :
"Enable SSH access via port 22, web access to 8091, membase/memcached protocol access to 11211 and 11210, and erlang access",
"SecurityGroupIngress" : [ {
"IpProtocol" : "tcp",
"FromPort" : "22",
"ToPort" : "22",
"CidrIp" : "0.0.0.0/0"
}, {
"IpProtocol" : "tcp",
"FromPort" : "8091",
"ToPort" : "8091",
"CidrIp" : "0.0.0.0/0"
}, {
"IpProtocol" : "tcp",
"FromPort" : "11211",
"ToPort" : "11211",
"CidrIp" : "0.0.0.0/0"
}, {
"IpProtocol" : "tcp",
"FromPort" : "11210",
"ToPort" : "11210",
"CidrIp" : "0.0.0.0/0"
}, {
"IpProtocol" : "tcp",
"FromPort" : "11209",
"ToPort" : "11209",
"CidrIp" : "0.0.0.0/0"
}, {
"IpProtocol" : "tcp",
"FromPort" : "4369",
"ToPort" : "4369",
"CidrIp" : "0.0.0.0/0"
}, {
"IpProtocol" : "tcp",
"FromPort" : "21100",
"ToPort" : "21299",
"CidrIp" : "0.0.0.0/0"
} ]
}
},
"WaitForServerNode0WaitHandle" : {
"Type" : "AWS::CloudFormation::WaitConditionHandle",
"Properties" : {
}
},
"WaitForServerNode0" : {
"Type" : "AWS::CloudFormation::WaitCondition",
"DependsOn" : "ServerNode0",
"Properties" : {
"Handle" : {"Ref" : "WaitForServerNode0WaitHandle"},
"Timeout" : "1200"
}
}
},
"Outputs" : {
"RESTWebConsoleURL" : {
"Description" : "The URL for the newly created <%= pkg_base %> node(s)",
"Value" : { "Fn::Join" : ["", [ "http://", { "Fn::GetAtt" : [ "ServerNode0", "PublicIp" ] }, ":8091" ]]}
}
}
}
Jump to Line
Something went wrong with that request. Please try again.