Skip to content

Instantly share code, notes, and snippets.

@rcreasey
Created April 14, 2010 16:50
Show Gist options
  • Save rcreasey/366043 to your computer and use it in GitHub Desktop.
Save rcreasey/366043 to your computer and use it in GitHub Desktop.
service_link 'apache' do
version [node[:apache][:version], node[:apache][:worker]].join('-')
end
directory "/etc/httpd" do
owner "root"
group "root"
mode 0755
action :create
not_if { File.exists?('/etc/httpd') }
end
directory "/etc/httpd/conf" do
owner "root"
group "root"
mode 0755
action :create
recursive true
not_if { File.directory?( "/etc/httpd/conf" ) }
end
template "/etc/init.d/httpd" do
source "httpd.initd.erb"
owner "root"
group "root"
mode 0755
backup false
end
service "httpd" do
action :enable
supports :status => true
end
template "/etc/httpd/conf/httpd.conf" do
source "httpd.conf.erb"
owner "root"
group "root"
mode 0644
backup false
end
link '/etc/httpd/conf/mime.types' do
link_type :symbolic
to '/z/conf/apache/mime.types'
not_if { File.symlink?( '/etc/httpd/conf/mime.types' ) }
end
user "apache" do
comment "Apache Worker"
uid 80
home "/usr/local/apache"
shell "/sbin/nologin"
supports :manage_home => false
action :create
end
set_unless[:apache] = Mash.new
set_unless[:apache][:worker] = "prefork"
set_unless[:apache][:version] = "2.2.14"
set[:apache][:mirror] = "http://apache.mirrors.redwire.net/httpd"
set[:apache][:path] = "/z/services/apache/#{apache.version}-#{apache.worker}"
set[:apache][:filename] = "httpd-#{apache.version}.tar.gz"
include_attribute 'build::apache'
include_attribute 'build::mysql'
set_unless[:php] = Mash.new
set_unless[:php][:version] = '5.3.2'
set[:php][:mirror] = "http://us.php.net/distributions"
set[:php][:path] = "/z/services/php/#{php.version}"
set[:php][:filename] = "php-#{php.version}.tar.gz"
set_unless[:apache][:path] = "/z/services/apache/latest"
set_unless[:php][:mods] = [
{:name => 'bcmath' },
{:name => 'bz2' },
{:name => 'curl', :requires => %w(curl curl-devel) },
{:name => 'exif' },
{:name => 'ftp' },
{:name => 'gd', :options => "--with-jpeg=/usr --with-jpeg-dir=/usr --with-freetype=/usr --with-png=/usr --enable-gd-native-ttf", :requires => %w(gd-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel) },
{:name => 'geoip', :source => 'http://pecl.php.net/get/geoip-1.0.7.tgz', :requires => %w(GeoIP-devel) },
{:name => 'gettext' },
{:name => 'imagick', :source => 'http://pecl.php.net/get/imagick-2.3.0.tgz', :requires => %w(ImageMagick ImageMagick-devel) },
{:name => 'ldap', :requires => %w(openldap-devel) },
{:name => 'mbstring' },
{:name => 'mcrypt', :options => '--with-mcrypt=/usr', :requires => %w(libmcrypt libmcrypt-devel) },
{:name => 'memcache', :source => 'http://pecl.php.net/get/memcache-2.2.5.tgz' },
{:name => 'openssl', :pre => 'mv config0.m4 config.m4' },
{:name => 'pecl_http', :source => 'http://pecl.php.net/get/pecl_http-1.6.6.tgz' },
{:name => 'pcntl' },
{:name => 'pdo_mysql', :options => '--with-pdo-mysql=mysqlnd' },
{:name => 'phar', :source => 'http://pecl.php.net/get/phar-2.0.0.tgz' },
{:name => 'shmop', :requires => %w(net-snmp-devel) },
{:name => 'snmp' },
{:name => 'soap' },
{:name => 'sockets' },
{:name => 'sysvmsg' },
{:name => 'sysvsem' },
{:name => 'sysvshm' },
{:name => 'tidy', :requires => %w(libtidy libtidy-devel) },
{:name => 'xmlrpc' },
{:name => 'xsl', :options => '--with-xsl=/usr', :requires => %w(libxslt libxslt-devel) },
{:name => 'zip', :options => '--with-zlib=/usr', :requires => %w(zlib zlib-devel) },
{:name => 'zlib', :pre => "mv config0.m4 config.m4", :options => '--with-zlib=/usr', :requires => %w(zlib zlib-devel)},
{:name => 'xdebug', :source => 'http://pecl.php.net/get/xdebug-2.0.5.tgz' }]
define :source_package do
source_root = params[:source_root] || "/export/source"
build_root = params[:build_root] || "/export/builds"
build_directory = "#{build_root}/#{$1}" if params[:filename] =~ /(.*)\.(tar\.gz|tgz|tar\.bz2|tb2)/
verify_source = params[:verify_check].nil? ? params[:prefix] : params[:verify_check]
[source_root, build_root].each do |r|
directory r do
mode 0755
action :create
not_if { File.directory?( r ) }
end
end
# extract command
archiver_command = case params[:filename]
when /(tar.gz)|(tgz)$/
'tar xzf'
when /(tar.bz2)|(tb2)$/
'tar xjf'
when /tar$/
'tar xf'
when /zip$/
'unzip'
else
raise "Unknown source archive format: #{archive_name}"
end
commands = {:download => "wget -cq #{params[:location]}/#{params[:filename]}",
:extract => "#{archiver_command} #{source_root}/#{params[:filename]}",
:configure => "./configure --prefix=#{params[:prefix]} ",
:compile => 'make',
:install => 'make install'}
# decide what to configure
if params[:configure]
if params[:configure][:with]
params[:configure][:with] = params[:configure][:with].compact.reject {|s| s.empty?}
commands[:configure] << params[:configure][:with].map {|o| "--with-#{o} "}.join(' ')
end
if params[:configure][:enable]
params[:configure][:enable] = params[:configure][:enable].compact.reject {|s| s.empty?}
commands[:configure] << params[:configure][:enable].map {|o| "--enable-#{o} " unless o.eql?('')}.join(' ')
end
if params[:configure][:disable]
params[:configure][:disable] = params[:configure][:disable].compact.reject {|s| s.empty?}
commands[:configure] << params[:configure][:disable].map {|o| "--disable-#{o} " unless o.eql?('')}.join(' ')
end
if params[:configure][:other]
params[:configure][:other] = params[:configure][:other].compact.reject {|s| s.empty?}
commands[:configure] << params[:configure][:other].map {|o| "--#{o} " unless o.eql?('')}.join(' ')
end
end
# execute commands
unless File.exists?( verify_source )
instance_eval( params[:pre_download] ) if params[:pre_download]
execute commands[:download] do
cwd source_root
not_if { File.exists?( "#{source_root}/#{params[:filename]}" ) }
end
instance_eval( params[:post_download] ) if params[:post_download]
instance_eval( params[:pre_extract] ) if params[:pre_extract]
execute commands[:extract] do
cwd build_root
end
instance_eval( params[:post_extract] ) if params[:post_extract]
if params[:custom]
execute params[:custom][:build] do
cwd params[:custom][:directory]
end
else
instance_eval( params[:pre_configure] ) if params[:pre_configure]
execute commands[:configure] do
cwd build_directory
end
instance_eval( params[:post_configure] ) if params[:post_configure]
instance_eval( params[:pre_compile] ) if params[:pre_compile]
execute commands[:compile] do
cwd build_directory
end
instance_eval( params[:post_compile] ) if params[:post_compile]
instance_eval( params[:pre_install] ) if params[:pre_install]
execute commands[:install] do
cwd build_directory
end
instance_eval( params[:post_install] ) if params[:post_install]
end
end
end
options = {:with => %W( mpm=#{node[:apache][:worker]} ),
:enable => %w( mods-shared=all ssl deflate proxy=shared mem-cache cache authn-dbm authn-dbd authz-dbm dbd )}
source_package "apache" do
version node[:apache][:version]
location node[:apache][:mirror]
filename node[:apache][:filename]
prefix node[:apache][:path]
configure options
end
include_recipe 'build::apache'
include_recipe 'build::mysql'
options = {:with => %W( config-file-path=/usr/local/php/php.ini config-file-scan-dir=/usr/local/php/conf #{'libdir=lib64' if node[:machine].eql?('x86_64')} regex=php apxs2=#{node[:apache][:path]}/bin/apxs libxml-dir=/usr mysql=mysqlnd mysqli=mysqlnd pdo_mysql=mysqlnd),
:enable => %w( libxml )}
source_package "php" do
version node[:php][:version]
location node[:php][:mirror]
filename node[:php][:filename]
prefix node[:php][:path]
configure options
post_install <<-EOH
link "#{node[:php][:path]}/conf" do
to "/etc/httpd/php.d"
end
link "#{node[:php][:path]}/php.ini" do
to "/etc/httpd/php.ini"
end
execute "mv modules/libphp5.so modules/mod_php_#{node[:php][:version]}.so" do
cwd "#{node[:apache][:path]}"
end
execute "mkdir -p `#{node[:php][:path]}/bin/php-config --extension-dir`"
execute "ln -s lib/php/extensions/`#{node[:php][:path]}/bin/php-config --extension-dir | xargs basename` extensions" do
cwd "#{node[:php][:path]}"
end
EOH
end
node[:php][:mods].each do |m|
php_module m[:name] do
version node[:php][:version]
options m[:options] unless m[:options].nil?
source m[:source] unless m[:source].nil?
requires m[:requires] unless m[:requires].nil?
pre m[:pre] unless m[:pre].nil?
end
end
include_recipe "farms::default"
include_recipe "subversion"
include_recipe "git"
include_recipe "ruby"
include_recipe "apache::custom"
include_recipe "mysql::custom"
include_recipe "php::custom"
include_recipe "memcache::custom"
name "oyster"
description "IGN Media: Oyster"
recipes "farms::oyster"
override_attributes(
"users" => {
...
},
"groups" => {
...
},
"mounts" => [
...
],
"apache" => { "version" => "2.2.14-prefork" },
"mysql" => { "version" => "5.1.33" },
"php" => { "version" => "5.3.2" },
"memcache" => { "version" => "1.2.8" }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment