Skip to content

Instantly share code, notes, and snippets.

@cwjohnston
Created July 5, 2010 15:23
Show Gist options
  • Save cwjohnston/464459 to your computer and use it in GitHub Desktop.
Save cwjohnston/464459 to your computer and use it in GitHub Desktop.
#
# Author:: Joshua Timberman <[email protected]>
# Author:: Joshua Sierles <[email protected]>
# Cookbook Name:: chef
# Recipe:: manage_couchdb
#
# Copyright 2008-2009, Opscode, Inc
# Copyright 2009, 37signals
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
http_request "compact chef couchDB" do
action :post
url "#{Chef::Config[:couchdb_url]}/chef/_compact"
only_if do
begin
open("#{Chef::Config[:couchdb_url]}/chef")
JSON::parse(open("#{Chef::Config[:couchdb_url]}/chef").read)["disk_size"] > 100_000_000
rescue OpenURI::HTTPError
nil
end
end
end
%w(nodes roles registrations clients data_bags data_bag_items users).each do |view|
http_request "compact chef couchDB view #{view}" do
action :post
url "#{Chef::Config[:couchdb_url]}/chef/_compact/#{view}"
only_if do
begin
open("#{Chef::Config[:couchdb_url]}/chef/_design/#{view}/_info")
JSON::parse(open("#{Chef::Config[:couchdb_url]}/chef/_design/#{view}/_info").read)["view_index"]["disk_size"] > 100_000_000
rescue OpenURI::HTTPError
nil
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment