Skip to content

Instantly share code, notes, and snippets.

@manveru
Created March 14, 2011 04:09
Show Gist options
  • Save manveru/868757 to your computer and use it in GitHub Desktop.
Save manveru/868757 to your computer and use it in GitHub Desktop.
compact bigcouch clusters
require 'makura'
require 'rye'
root = Makura::Server.new('http://host:5984')
nodes = root.membership['cluster_nodes']
p nodes: nodes
nodes.each do |node|
node_name = node[/@(\w+)/, 1]
puts "Connecting to #{node_name}"
url = "http://#{node_name}:5986"
box = Rye::Box.new(node_name, port: 2304)
ret = box.curl("-s", "#{url}/_all_dbs")
dbs = JSON.parse(ret.stdout.to_s)
dbs.each do |db|
db_url = "#{url}/#{Makura.escape(db)}"
ret = box.curl("-s", db_url)
info = JSON.parse(ret.stdout.to_s)
if info['compact_running']
puts "Compact already running for #{db_url}"
else
puts "Starting compact for #{db_url}"
ret = box.curl("-s",
"-X", "POST",
"-H", "Content-Type: application/json",
"#{db_url}/_compact")
p JSON.parse(ret.stdout.to_s)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment