Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add couchbase template

  • Loading branch information...
commit 550dff4d87c21fbd26dab2cc6307c47d7a0c84ea 1 parent 5862791
@wr0ngway authored
View
105 templates/couchbase/config/rubber/deploy-couchbase.rb
@@ -0,0 +1,105 @@
+namespace :rubber do
+
+ namespace :couchbase do
+
+ rubber.allow_optional_tasks(self)
+
+ before "rubber:install_packages", "rubber:couchbase:setup_apt_sources"
+
+ # sources needed for couchbase ruby client, not server
+ task :setup_apt_sources do
+ sources = <<-SOURCES
+ # Ubuntu 11.10 Oneiric Ocelot (Debian unstable)
+ #
+ # preview version needed for ruby client that has rails cache/session
+ #
+ # deb http://packages.couchbase.com/ubuntu oneiric oneiric/main
+ deb http://packages.couchbase.com/preview/ubuntu oneiric oneiric/main
+ SOURCES
+ sources.gsub!(/^[ \t]*/, '')
+ put(sources, "/etc/apt/sources.list.d/couchbase.list")
+ rsudo "wget -O- http://packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add -"
+ end
+
+ after "rubber:install_packages", "rubber:couchbase:install"
+
+ task :install, :roles => :couchbase do
+ rubber.sudo_script 'install_couchbase', <<-ENDSCRIPT
+ if ! grep "^#{rubber_env.couchbase_version}" /opt/couchbase/VERSION.txt &> /dev/null; then
+ # Fetch and install the pkg
+ rm -rf /tmp/couchbase*
+ wget -qNP /tmp #{rubber_env.couchbase_pkg_url}
+ dpkg -i /tmp/couchbase*
+
+ # Clean up after ourselves.
+ rm -rf /tmp/couchbase*
+ fi
+ ENDSCRIPT
+ end
+
+ after "rubber:bootstrap", "rubber:couchbase:bootstrap"
+
+ task :bootstrap, :roles => :couchbase do
+ exists = capture("echo $(ls #{rubber_env.couchbase_db_dir} 2> /dev/null)")
+ if exists.strip.size == 0
+
+ cli = rubber_env.couchbase_cli
+ create_bucket_lines = []
+ ram_size = 0
+ rubber_env.couchbase_buckets.each do |bucket_spec|
+ create_bucket_lines << "#{cli} bucket-create $cluster --bucket=#{bucket_spec['name']} --bucket-type=#{bucket_spec['type']} --bucket-port=#{bucket_spec['port']} --bucket-ramsize=#{bucket_spec['size']} --bucket-replica=#{bucket_spec['replicas']}"
+ ram_size += bucket_spec['size'].to_i
+ end
+
+ rubber.sudo_script 'bootstrap_couchbase', <<-ENDSCRIPT
+ mkdir -p #{rubber_env.couchbase_db_dir}
+ chown -R couchbase:couchbase #{rubber_env.couchbase_db_dir}
+ local_ip=$(ifconfig eth0 | awk -F"[: ]+" 'NR==2 {print $4}')
+ cluster="-c $local_ip:8091 -u #{rubber_env.couchbase_admin_username} -p #{rubber_env.couchbase_admin_password}"
+
+ # Setup cluster
+ #{cli} cluster-init $cluster --cluster-init-ramsize=#{ram_size}
+
+ # initialize the node
+ #{cli} node-init $cluster --node-init-data-path=#{rubber_env.couchbase_db_dir}
+
+ # create the buckets
+ #{create_bucket_lines.join("\n")}
+
+ ENDSCRIPT
+
+ # After everything installed on machines, we need the source tree
+ # on hosts in order to run rubber:config for bootstrapping the db
+ rubber.update_code_for_bootstrap
+
+ # Gen just the conf for couchbase
+ rubber.run_config(:file => "role/couchbase/", :force => true, :deploy_path => release_path)
+
+ restart
+ end
+ end
+
+ desc "Stops the couchbase server"
+ task :stop, :roles => :couchbase, :on_error => :continue do
+ rsudo "service couchbase-server stop || true"
+ end
+
+ desc "Starts the couchbase server"
+ task :start, :roles => :couchbase do
+ rsudo "service couchbase-server start"
+ end
+
+ desc "Restarts the couchbase server"
+ task :restart, :roles => :couchbase do
+ stop
+ start
+ end
+
+ desc "Reloads the couchbase server"
+ task :reload, :roles => :couchbase do
+ restart
+ end
+
+ end
+
+end
View
8 templates/couchbase/config/rubber/role/couchbase/crontab
@@ -0,0 +1,8 @@
+<%
+ @read_cmd = 'crontab -l'
+ @write_cmd = 'crontab -'
+ @additive = ['# start-couchbase-crontab', '# end-couchbase-crontab']
+%>
+
+# Backup couchbase DBs every 3 hours.
+# 0 */3 * * * <%= Rubber.root %>/script/rubber cron --task util:backup --directory=/mnt/couchbase_backups --name=couchbase --command="nice cbbackup <%= rubber_env.couchbase_db_dir %> \%dir\%/\%name\%_<%= rubber_env.host %>_\%time_stamp\%"
View
25 templates/couchbase/config/rubber/rubber-couchbase.yml
@@ -0,0 +1,25 @@
+couchbase_version: 1.8.1
+couchbase_pkg_url: "http://packages.couchbase.com/releases/#{couchbase_version}/couchbase-server-community_x86_64_#{couchbase_version}.deb"
+
+couchbase_pid_file: /opt/couchbase/var/lib/couchbase/couchbase-server.pid
+couchbase_cli: /opt/couchbase/bin/couchbase-cli
+couchbase_db_dir: /mnt/couchbase/data
+
+couchbase_admin_username: Administrator
+couchbase_admin_password: password
+
+couchbase_buckets:
+ - name: "default"
+ type: couchbase
+ size: 200
+ replicas: 1
+ port: 11211
+ - name: "#{app_name}"
+ type: couchbase
+ size: 200
+ replicas: 1
+ port: 11222
+
+gems: [couchbase]
+
+packages: [libcouchbase-dev]
View
3  templates/couchbase/templates.rb
@@ -0,0 +1,3 @@
+if Rubber::Util::is_bundler?
+ append_to_file "Gemfile", "gem 'couchbase'\n"
+end
View
1  templates/couchbase/templates.yml
@@ -0,0 +1 @@
+description: The couchbase module
View
7 templates/monit/config/rubber/role/couchbase/monit-couchbase.conf
@@ -0,0 +1,7 @@
+<%
+ @path = '/etc/monit/monit.d/monit-couchbase.conf'
+%>
+check process couchbase with pidfile <%= rubber_env.couchbase_pid_file %>
+ group couchbase-<%= Rubber.env %>
+ start program = "/usr/bin/env service couchbase-server start"
+ stop program = "/usr/bin/env service couchbase-server stop"
Please sign in to comment.
Something went wrong with that request. Please try again.