Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added couchbase 2.0.0 setup scripts

  • Loading branch information...
commit dee8c61891bfdd3815bf7e75e798101165d59b46 1 parent d6b35ea
@ronniedada ronniedada authored
View
35 cookbooks/couchbase/metadata.json
@@ -21,10 +21,22 @@
"replacing": {
},
"attributes": {
- "db_couchbase/cluster/username": {
+ "db_couchbase/version": {
+ "description": "Couchbase Server Edition",
+ "recipes": [
+ "couchbase::setup-2.0.0"
+ ],
+ "calculated": false,
+ "type": "string",
+ "default": "enterprise",
+ "display_name": "CCouchbase Server Edition",
+ "required": "optional"
+ },
+ "db_couchbase/cluster/username": {
"description": "Cluster REST/Web Administrator Username",
"recipes": [
- "couchbase::default"
+ "couchbase::default",
+ "couchbase::setup-2.0.0"
],
"calculated": false,
"type": "string",
@@ -35,7 +47,8 @@
"db_couchbase/cluster/password": {
"description": "Cluster REST/Web Administrator Password",
"recipes": [
- "couchbase::default"
+ "couchbase::default",
+ "couchbase::setup-2.0.0"
],
"calculated": false,
"type": "string",
@@ -46,7 +59,8 @@
"db_couchbase/cluster/tag": {
"description": "Cluster Tag used to auto-join nodes of the same tag, when non-empty",
"recipes": [
- "couchbase::default"
+ "couchbase::default",
+ "couchbase::setup-2.0.0"
],
"calculated": false,
"type": "string",
@@ -57,7 +71,8 @@
"db_couchbase/bucket/name": {
"description": "Bucket Name",
"recipes": [
- "couchbase::default"
+ "couchbase::default",
+ "couchbase::setup-2.0.0"
],
"calculated": false,
"type": "string",
@@ -68,7 +83,8 @@
"db_couchbase/bucket/password": {
"description": "Bucket Password",
"recipes": [
- "couchbase::default"
+ "couchbase::default",
+ "couchbase::setup-2.0.0"
],
"calculated": false,
"type": "string",
@@ -79,7 +95,8 @@
"db_couchbase/bucket/ram": {
"description": "Bucket RAM Quota in MB",
"recipes": [
- "couchbase::default"
+ "couchbase::default",
+ "couchbase::setup-2.0.0"
],
"calculated": false,
"type": "string",
@@ -90,7 +107,8 @@
"db_couchbase/bucket/replica": {
"description": "Bucket Replica Count",
"recipes": [
- "couchbase::default"
+ "couchbase::default",
+ "couchbase::setup-2.0.0"
],
"calculated": false,
"type": "string",
@@ -103,6 +121,7 @@
},
"recipes": {
"couchbase::default": "Install Couchbase Server specific packages. Setup Couchbase Server specific default attributes"
+ "couchbase::setup-2.0.0": "Install Couchbase Server 2.0.0 packages. Setup Couchbase Server speicific default attributes."
},
"version": "0.1.10"
}
View
172 cookbooks/couchbase/recipes/setup-2.0.0.rb
@@ -0,0 +1,172 @@
+#
+# Cookbook Name:: couchbase
+#
+# Copyright RightScale, Inc. All rights reserved. All access and use subject to the
+# RightScale Terms of Service available at http://www.rightscale.com/terms.php and,
+# if applicable, other agreements such as a RightScale Master Subscription Agreement.
+
+rightscale_marker :begin
+
+couchbase_edition = node[:db_couchbase][:edition]
+couchbase_version = "2.0.0"
+couchbase_package = "couchbase-server-#{couchbase_edition}_x86_64_#{couchbase_version}.rpm"
+
+log "downloading #{couchbase_package}"
+
+if not File.exists?("/tmp/#{couchbase_package}")
+ remote_file "/tmp/#{couchbase_package}" do
+ source "http://packages.couchbase.com/releases/#{couchbase_version}/#{couchbase_package}"
+ mode "0644"
+ end
+end
+
+log "installing #{couchbase_package}"
+
+package "couchbase-server" do
+ source "/tmp/#{couchbase_package}"
+ provider Chef::Provider::Package::Rpm
+ action :install
+end
+
+log "configuring #{couchbase_package}"
+
+log("/opt/couchbase/bin/couchbase-cli cluster-init" +
+ " -c 127.0.0.1:8091" +
+ " --cluster-init-username=#{node[:db_couchbase][:cluster][:username]}")
+execute "initializing cluster with username: #{node[:db_couchbase][:cluster][:username]}" do
+ command("sleep 10" +
+ " && /opt/couchbase/bin/couchbase-cli cluster-init" +
+ " -c 127.0.0.1:8091" +
+ " --cluster-init-username=#{node[:db_couchbase][:cluster][:username]}" +
+ " --cluster-init-password=#{node[:db_couchbase][:cluster][:password]}")
+ action :run
+end
+
+unless (node[:block_device].nil? or
+ node[:block_device][:devices].nil? or
+ node[:block_device][:devices][:device1].nil? or
+ node[:block_device][:devices][:device1][:mount_point].nil?)
+ mount_point = node[:block_device][:devices][:device1][:mount_point]
+
+ log "configuring to mount_point: #{mount_point}"
+
+ execute "stopping server" do
+ command "/etc/init.d/couchbase-server stop && sleep 5"
+ action :run
+ end
+
+ execute "moving directory" do
+ command "mv /opt/couchbase #{mount_point}"
+ action :run
+ end
+
+ execute "symlinking directory" do
+ command "ln -s #{mount_point}/couchbase /opt/"
+ action :run
+ end
+
+ execute "starting server" do
+ command "/etc/init.d/couchbase-server start && sleep 10"
+ action :run
+ end
+end
+
+log("/opt/couchbase/bin/couchbase-cli bucket-create" +
+ " -c 127.0.0.1:8091" +
+ " -u #{node[:db_couchbase][:cluster][:username]}" +
+ " --bucket=#{node[:db_couchbase][:bucket][:name]}" +
+ " --bucket-type=couchbase" +
+ " --bucket-ramsize=#{node[:db_couchbase][:bucket][:ram]}" +
+ " --bucket-replica=#{node[:db_couchbase][:bucket][:replica]}")
+execute "creating bucket: #{node[:db_couchbase][:bucket][:name]}" do
+ command("/opt/couchbase/bin/couchbase-cli bucket-create" +
+ " -c 127.0.0.1:8091" +
+ " -u #{node[:db_couchbase][:cluster][:username]}" +
+ " -p #{node[:db_couchbase][:cluster][:password]}" +
+ " --bucket=#{node[:db_couchbase][:bucket][:name]}" +
+ " --bucket-type=couchbase" +
+ " --bucket-password=\"#{node[:db_couchbase][:bucket][:password]}\"" +
+ " --bucket-ramsize=#{node[:db_couchbase][:bucket][:ram]}" +
+ " --bucket-replica=#{node[:db_couchbase][:bucket][:replica]}")
+ action :run
+end
+
+cluster_tag = node[:db_couchbase][:cluster][:tag]
+log("db_couchbase/cluster/tag: #{cluster_tag}")
+
+if cluster_tag and !cluster_tag.empty?
+ now = DateTime.now.strftime("%Y%m%d-%H%M%S.%L")
+ log("clustering - now is #{now}")
+
+ unless `which rs_tag`.empty?
+ ip = node[:cloud][:private_ips][0]
+ if ip
+ log("clustering - private ip is #{ip}")
+
+ add_cmd = "rs_tag -a couchbase_cluster_tag:#{cluster_tag}=#{now}:#{ip}:couchbase"
+ log("clustering - rs_tag add cmd: #{add_cmd}")
+ add_res = `#{add_cmd}`
+ log("clustering - rs_tag add res: #{add_res}")
+
+ qry_cmd = "rs_tag -q couchbase_cluster_tag:#{cluster_tag}"
+ log("clustering - rs_tag qry cmd: #{qry_cmd}")
+ qry_res = `#{qry_cmd}`
+ log("clustering - rs_tag qry res: #{qry_res}")
+
+ username = node[:db_couchbase][:cluster][:username]
+ password = node[:db_couchbase][:cluster][:password]
+
+ cmd = "/opt/couchbase/bin/couchbase-cli server-list" +
+ " -c 127.0.0.1" +
+ " -u #{username}" +
+ " -p #{password}"
+ log("clustering - server-list cmd: #{cmd}")
+ known_hosts = `#{cmd}`.strip
+ log("clustering - server-list res: #{known_hosts}")
+ unless known_hosts.match(/^ERROR:/)
+ if known_hosts.split("\n").length <= 1
+ cmd = "rs_tag -q couchbase_cluster_tag:#{cluster_tag}" +
+ " | grep couchbase_cluster_tag:#{cluster_tag}=" +
+ " | grep -v :#{ip}:couchbase" +
+ " | cut -d '=' -f 2 | cut -d '\"' -f 1 | sort | cut -d ':' -f 2"
+ log("clustering - rs_tag private_ip qry: #{cmd}")
+ private_ips = `#{cmd}`.strip.split("\n")
+ log("clustering - rs_tag private_ip res: #{private_ips}")
+ if private_ips.length >= 1
+ sleep 15
+
+ cmd = "/opt/couchbase/bin/couchbase-cli server-add" +
+ " -c #{private_ips[0]}" +
+ " -u #{username}" +
+ " -p #{password}" +
+ " --server-add=self" +
+ " --server-add-username=#{username}" +
+ " --server-add-password=#{password}"
+ log("clustering - server-add cmd: #{cmd}")
+ join = `#{cmd}`
+ log("clustering - server-add res: #{join}")
+ if join.match(/SUCCESS/)
+ log("clustering - server added")
+ else
+ log("clustering - error: server add failed; " + join)
+ end
+ else
+ log("clustering - no other servers to join")
+ end
+ else
+ log("clustering - already joined")
+ end
+ else
+ log("clustering - error: could not retrieve server-list")
+ end
+ else
+ log("clustering - error: no cloud private ip")
+ end
+ else
+ log("clustering - error: could not find rs_tag")
+ end
+else
+ log("clustering - skipped, no cluster_tag")
+end
+
+rightscale_marker :end
Please sign in to comment.
Something went wrong with that request. Please try again.