Skip to content

Instantly share code, notes, and snippets.

@gilles
Created November 18, 2010 22:00
Show Gist options
  • Save gilles/705726 to your computer and use it in GitHub Desktop.
Save gilles/705726 to your computer and use it in GitHub Desktop.
Compact chef's couchdb indexes
# vim:ts=2:expandtab
require 'rubygems'
require 'open-uri'
require 'json'
#http://wiki.apache.org/couchdb/Compaction
if JSON::parse(open("http://localhost:5984/chef").read)["disk_size"] > 100_000_000
res = Net::HTTP.post_form(URI.parse('http://localhost:5984/chef/_compact'), {})
puts res.body
end
%w(nodes roles registrations clients data_bags data_bag_items users).each do |view|
puts "check for clean: #{view}"
begin
res = open("http://localhost:5984/chef/_design/#{view}/_info")
if JSON::parse(res.read)['view_index']["disk_size"] > 100_000_000
res = Net::HTTP.post_form(URI.parse("http://localhost:5984/chef/_compact/#{view}"), {})
puts res.body
end
rescue
end
end
Copy link

ghost commented Apr 3, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment