Skip to content

Instantly share code, notes, and snippets.

@stormsilver
Created June 30, 2010 15:42
Show Gist options
  • Save stormsilver/458812 to your computer and use it in GitHub Desktop.
Save stormsilver/458812 to your computer and use it in GitHub Desktop.
set_unless[:cookbook_support][:poll][:dir] = "/data/chef/chef_polls"
if (node[:couchdb][:source_version] && !node[:couchdb][:source_version].empty?)
include_recipe("build-essential")
poll_name = "couchdb"
if (!poll_file(poll_name))
package "js"
package "js-devel"
package "libicu"
package "libicu-devel"
wd = "/tmp/apache-couchdb-#{node[:couchdb][:source_version]}"
tar_dest = "/tmp/apache-couchdb-#{node[:couchdb][:source_version]}.tar.gz"
remote_file tar_dest do
source "http://www.takeyellow.com/apachemirror/couchdb/#{node[:couchdb][:source_version]}/apache-couchdb-#{node[:couchdb][:source_version]}.tar.gz"
checksum "0a20c0f534ce605d7ce2bcc22322f88f7e1e132bd8af177103cca64dc164e0ed"
end
execute "extract #{poll_name}" do
command "tar -xzf #{tar_dest}"
cwd "/tmp"
end
execute "configure #{poll_name}" do
command "./configure --prefix=#{node[:couchdb][:source_destination]} --with-erlang=#{node[:erlang][:source_destination]}/lib/erlang/erts-#{node[:erlang][:erts_version]}/include"
environment "PATH" => "#{node[:erlang][:source_destination]}/bin:#{ENV['PATH']}"
cwd wd
end
execute "make #{poll_name}" do
command "make"
cwd wd
end
execute "make install #{poll_name}" do
command "make install"
cwd wd
end
link "/etc/init.d/couchdb" do
to "#{node[:couchdb][:source_destination]}/etc/rc.d/couchdb"
end
template "#{node[:couchdb][:source_destination]}/etc/couchdb/local.ini" do
source "local.ini.erb"
backup false
owner "root"
group "root"
mode "644"
end
template "/etc/logrotate.d/couchdb" do
source "logrotate.erb"
backup false
owner "root"
group "root"
mode "644"
end
user "couchdb"
group "couchdb"
%W{ var/run/couchdb var/lib/couchdb }.each do |d|
directory "#{node[:couchdb][:source_destination]}/#{d}" do
owner "couchdb"
group "couchdb"
end
end
directory "/var/log/couchdb" do
owner "couchdb"
group "couchdb"
end
service "couchdb" do
supports [:restart, :status]
action [:enable, :start]
end
create_poll_file(poll_name)
end
else
package "couchdb"
directory "/var/lib/couchdb" do
owner "couchdb"
group "couchdb"
recursive true
end
service "couchdb" do
if platform?("centos","redhat","fedora")
start_command "/sbin/service couchdb start &> /dev/null"
stop_command "/sbin/service couchdb stop &> /dev/null"
end
supports [ :restart, :status ]
action [ :enable, :start ]
end
end
define :create_poll_file, :name => nil do
f = resolve_poll_file(params[:name])
file(f) do
backup false
end
end
def poll_file(file)
file = resolve_poll_file(file)
if (File.exist?(file))
Chef::Log.debug("Poll file #{file} exists!")
return true
else
Chef::Log.debug("Poll file #{file} does not exist.")
return false
end
end
def resolve_poll_file(file)
f = file.to_s
if (f[0, 1] == '/')
f = f
else
f = File.join(node[:cookbook_support][:poll][:dir], f)
`mkdir -p #{node[:cookbook_support][:poll][:dir]}`
end
return f
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment