Skip to content

Instantly share code, notes, and snippets.

@mikeblum
Last active July 3, 2016 18:50
Show Gist options
  • Save mikeblum/32b8c933435eb2f5d407e79dea118f93 to your computer and use it in GitHub Desktop.
Save mikeblum/32b8c933435eb2f5d407e79dea118f93 to your computer and use it in GitHub Desktop.
Chef recipe for creating a Solr instance
# recipes/default.rb
# Cookbook Name:: apache_solr
# Recipe:: default
#
# Copyright 2016, Michael Blum
#
if node['solr']['install_java']
include_recipe 'java_se'
end
src_filename = ::File.basename(node['solr']['url'])
src_filepath = "#{Chef::Config['file_cache_path']}/#{src_filename}"
extract_path = "#{node['solr']['dir']}-#{node['solr']['version']}"
solr_path = "#{extract_path}/#{node['solr']['version'].split('.')[0].to_i < 5 ? 'example' : 'server'}"
solr_logs = "/var/solr/logs"
solr_log_file = "/var/solr/logs/solr.log"
remote_file src_filepath do
source node['solr']['url']
action :create_if_missing
end
bash 'configure_solr_logging' do
code <<-EOH
mkdir -p #{solr_logs}
touch #{solr_log_file}
chmod 777 #{solr_log_file}
EOH
not_if { ::File.exist?(solr_log_file) }
end
bash 'install_solr_service' do
cwd ::File.dirname(src_filepath)
code <<-EOH
tar xzf #{src_filename} solr-#{node['solr']['version']}/bin/install_solr_service.sh --strip-components=2
bash ./install_solr_service.sh #{src_filename} -f -d /var/solr -u solr -p 8983
EOH
not_if { ::File.exist?(extract_path) }
end
service 'solr' do
supports :restart => true, :status => true
action [:enable, :start]
end
name 'apache_solr'
maintainer 'Michael Blum'
maintainer_email '[email protected]'
license 'Apache License 2.0'
description 'Installs/Configures apache_solr'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.1.0'
supports 'amazon'
supports 'ubuntu'
depends 'java_se'
# attributes/default.rb
# Cookbook Name:: apache_solr
# Recipe:: default
#
# Copyright 2016, Michael Blum
#
default['java_se']['uri'] = "https://s3.amazonaws.com/chef-pantry/java"
default['solr']['user'] = "solr"
default['solr']['group'] = "solr"
default['solr']['version'] = "6.0.0"
default['solr']['url'] = "https://s3.amazonaws.com/chef-pantry/apache/solr-6.0.0.tgz"
default['solr']['install_java'] = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment