forked from couchbaselabs/cloud-formation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.erb
269 lines (262 loc) · 9.47 KB
/
template.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
{
"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.small" : { "Arch" : "64" },
"m1.medium" : { "Arch" : "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" },
"m3.medium" : { "Arch" : "64" },
"c1.medium" : { "Arch" : "64" }
<% else %>
"m1.small" : { "Arch" : "32" },
"c1.medium" : { "Arch" : "32" }
<% end %>
},
"AWSRegionArch2AMI" : {
"us-east-1" : { "32" : "ami-7f418316", "64" : "ami-03ada46a" },
"us-west-1" : { "32" : "ami-951945d0", "64" : "ami-03ada46a" },
"eu-west-1" : { "32" : "ami-24506250", "64" : "ami-03ada46a" },
"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 wget nc openssl098e","\n",
"wget ", { "Ref" : "PackageURL" },"\n",
"rpm -i <%= pkg_name %>","\n",
"/bin/sh -c \"", { "Ref" : "AfterInstall" }, "\"\n",
"while ! nc -vz localhost 8091; do sleep 1; done","\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" : "8092",
"ToPort" : "8092",
"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"
} ]
}
},
"IPAddress" : {
"Type" : "AWS::EC2::EIP"
},
"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" ]]}
},
"InstancePrivateIpAddress" : {
"Value" : { "Fn::GetAtt" : [ "ServerNode0", "PrivateIp" ] }
}
}
}