From cf5170fbb1a1e5b61beda59766def6bb91a4bf64 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 5 Jul 2012 17:05:53 -0400 Subject: [PATCH] working on more cleanup stuff --- .../debian/manifests/init.pp | 10 +- .../additional-modules/ruby/manifests/init.pp | 4 +- .../varnish/manifests/init.pp | 145 ++++++++++-------- .../varnish/templates/default | 12 ++ shared/lib/facter/all_ip_addresses.rb | 8 + shared/lib/facter/varnish_cache_size.rb | 6 + .../lib/puppet/parser/functions/bin_path.rb | 1 - .../lib/puppet/parser/functions/dir_size.rb | 6 + shared/modules/debsource/manifests/init.pp | 2 +- shared/modules/package_data/manifests/init.pp | 1 + 10 files changed, 126 insertions(+), 69 deletions(-) create mode 100644 shared/additional-modules/varnish/templates/default create mode 100644 shared/lib/facter/all_ip_addresses.rb create mode 100644 shared/lib/facter/varnish_cache_size.rb create mode 100644 shared/lib/puppet/parser/functions/dir_size.rb create mode 100644 shared/modules/package_data/manifests/init.pp diff --git a/shared/additional-modules/debian/manifests/init.pp b/shared/additional-modules/debian/manifests/init.pp index 5c05507..8f31dec 100644 --- a/shared/additional-modules/debian/manifests/init.pp +++ b/shared/additional-modules/debian/manifests/init.pp @@ -1,6 +1,10 @@ class debian { - group { web: - gid => 30010 - } + $varnish_apt_source = "deb http://repo.varnish-cache.org/debian/ squeeze varnish-3.0" + $varnish_keyfile = "http://repo.varnish-cache.org/debian/GPG-key.txt" + $varnish_hash = "C4DEFFEB" + + $mongo_apt_source = "deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen" + $mongo_host = "keyserver.ubuntu.com" + $mongo_hash = "7F0CEB10" } diff --git a/shared/additional-modules/ruby/manifests/init.pp b/shared/additional-modules/ruby/manifests/init.pp index ec9d823..88973d3 100644 --- a/shared/additional-modules/ruby/manifests/init.pp +++ b/shared/additional-modules/ruby/manifests/init.pp @@ -1,10 +1,10 @@ -class ruby($version, $deb_url = '', $configure = "--disable-install-doc", $build_path = '') { +class ruby($version = '', $deb_url = '', $configure = "--disable-install-doc", $build_path = '') { gem { [ 'bundler', 'penchant' ]: path => "${path}:${base::path}", ensure => present } - if ($deb_url) { + if ($::osfamily == 'debian') { $path = '/usr/bin' remotedeb { ruby: diff --git a/shared/additional-modules/varnish/manifests/init.pp b/shared/additional-modules/varnish/manifests/init.pp index 5fd9a88..d5379a2 100644 --- a/shared/additional-modules/varnish/manifests/init.pp +++ b/shared/additional-modules/varnish/manifests/init.pp @@ -1,55 +1,102 @@ -class varnish($version, $vcl, $user = 'varnish', $group = 'varnish', $store_file_mb = 1024) { - $install_path = install_path($name, $version) - $config = config_path($name) - $share = share_path($name) - $data = data_path($name) - $sbin = sbin_path($name) - $bin_path = bin_path($name) +class varnish($version = '', $vcl, $user = 'varnish', $group = 'varnish') { + if ($::osfamily == 'debian') { + $config = '/etc/varnish' - $bin = "${sbin}/${name}d" - $pid = pid_path($name) - $log = log_path($name) + $default_varnish = '/etc/default/varnish' + } else { + $install_path = install_path($name, $version) + $config = config_path($name) + $share = share_path($name) + $data = data_path($name) + $sbin = sbin_path($name) + $bin_path = bin_path($name) - $ncsa_bin = "${bin_path}/varnishncsa" - $ncsa_pid = pid_path('varnishncsa') - $ncsa_log = "${log}/access.log" + $bin = "${sbin}/${name}d" + $pid = pid_path($name) + $log = log_path($name) + + $default_varnish = "${config}/defaults" + } $vcl_path = "${config}/default.vcl" - $store_file_path = "${data}/store" - $store_file_size = $store_file_mb * 1024 * 1024 + if ($::osfamily == 'debian') { + debsource { varnish: + apt_source => $debian::varnish_apt_source, + keyfile => $debian::varnish_keyfile, + hash => $debian::varnish_hash + } - $varnish_start = "service varnish start" - $varnish_stop = "service varnish stop" - $varnish_rotate = "service varnish rotate" + $cache_root = "/var/lib" + $cache_dir = "${cache_root}/varnish" - $source = "http://repo.varnish-cache.org/source/varnish-${version}.tar.gz" - $dirs = [ $config, $log, $share, $data ] + package { varnish: + ensure => latest, + require => [ + Debsource['varnish'], Mkdir_p[$cache_dir] + ] + } - build_and_install { $name: - version => $version, - source => $source + $store_file_size = dir_size($cache_root) + + Package['varnish'] -> File[$default_varnish, $vcl_path] + } else { + $source = "http://repo.varnish-cache.org/source/varnish-${version}.tar.gz" + $dirs = [ $config, $log, $share, $data ] + + $cache_dir = "${data}/store" + + build_and_install { $name: + version => $version, + source => $source + } + + mkdir_p { $dirs: + path => $base::path, + require => Build_and_install[$name] + } + + init_d { $name: + require => Mkdir_p[$dirs] + } + + Build_and_install['varnish'] -> File[$default_varnish, $vcl_path] + + /* + $ncsa_bin = "${bin_path}/varnishncsa" + $ncsa_pid = pid_path('varnishncsa') + $ncsa_log = "${log}/access.log" + + logrotate_d { 'varnishncsa': + postrotate => 'service varnish rotate', + pattern => "${log}/access.log" + } + */ } - mkdir_p { $dirs: - path => $base::path, - require => Build_and_install[$name] - } - - exec { "${name} create-store-file": - command => "dd if=/dev/zero of=${store_file_path} bs=${store_file_size} count=1", - timeout => 0, - unless => "test -f ${store_file_path}", - path => $base::path, - require => Mkdir_p[$data], - logoutput => true + file { $default_varnish: + content => template("varnish/default"), + notify => Service[varnish] } file { $vcl_path: content => $vcl, - require => Build_and_install[$name] + notify => Service[varnish] } + mkdir_p { $cache_dir: + path => $base::path + } + + service { varnish: + ensure => running, + require => File[$default_varnish, $vcl_path] + } + + $varnish_start = "service varnish start" + $varnish_stop = "service varnish stop" + $varnish_rotate = "service varnish rotate" + god_init { $name: start => $varnish_start, stop => $varnish_stop, @@ -61,31 +108,5 @@ class varnish($version, $vcl, $user = 'varnish', $group = 'varnish', $store_file interval => 10 } - /* debian stuff */ - if ($::osfamily == 'debian') { - user { $user: uid => 27835 } - - $packages = [ 'libpcre3', 'libpcre3-dev', 'pkg-config' ] - - package { $packages: - ensure => installed, - before => Build_and_install[$name] - } - - exec { 'ensure-data-store-ownership': - command => "chown -R ${user}:${group} ${data}", - path => $base::path, - require => Exec["${name} create-store-file"] - } - - logrotate_d { 'varnishncsa': - postrotate => 'service varnish rotate', - pattern => "${log}/access.log" - } - } - - init_d { $name: - require => Mkdir_p[$dirs] - } } diff --git a/shared/additional-modules/varnish/templates/default b/shared/additional-modules/varnish/templates/default new file mode 100644 index 0000000..8043898 --- /dev/null +++ b/shared/additional-modules/varnish/templates/default @@ -0,0 +1,12 @@ +START=1 + +DAEMON_OPTS=" \ + -a :80 \ + -T 127.0.0.1:6082 \ + -f <%= vcl_path %> \ + -s file,<%= cache_dir %>/cache,<%= store_file_size %>M \ + -u nobody \ + -g nogroup \ + -w <%= scope.lookupvar('::processorcount') %>,<%= scope.lookupvar('::processorcount').to_i * 2 %>,600 \ +" + diff --git a/shared/lib/facter/all_ip_addresses.rb b/shared/lib/facter/all_ip_addresses.rb new file mode 100644 index 0000000..cb1bd18 --- /dev/null +++ b/shared/lib/facter/all_ip_addresses.rb @@ -0,0 +1,8 @@ +Facter.add('all_ip_addresses') do + setcode do + Facter.collection.list.find_all { |fact| fact[%r{^ipaddress_}] }.collect do |fact| + Facter[fact].value + end.compact.join(',') + end +end + diff --git a/shared/lib/facter/varnish_cache_size.rb b/shared/lib/facter/varnish_cache_size.rb new file mode 100644 index 0000000..7563761 --- /dev/null +++ b/shared/lib/facter/varnish_cache_size.rb @@ -0,0 +1,6 @@ +Facter.add("varnish_cache_size") do + setcode do + %x{df -m /var}.lines.to_a.last.strip.split(/ +/)[1].to_i / 4 + end +end + diff --git a/shared/lib/puppet/parser/functions/bin_path.rb b/shared/lib/puppet/parser/functions/bin_path.rb index ba5ce29..0346601 100644 --- a/shared/lib/puppet/parser/functions/bin_path.rb +++ b/shared/lib/puppet/parser/functions/bin_path.rb @@ -6,4 +6,3 @@ module Puppet::Parser::Functions end end - diff --git a/shared/lib/puppet/parser/functions/dir_size.rb b/shared/lib/puppet/parser/functions/dir_size.rb new file mode 100644 index 0000000..6c410fb --- /dev/null +++ b/shared/lib/puppet/parser/functions/dir_size.rb @@ -0,0 +1,6 @@ +module Puppet::Parser::Functions + newfunction(:dir_size, :type => :rvalue) do |path| + %x{df -m #{path}}.lines.to_a.last.strip.split(/ +/)[1].to_i / 4 + end +end + diff --git a/shared/modules/debsource/manifests/init.pp b/shared/modules/debsource/manifests/init.pp index 31f5895..5f03d41 100644 --- a/shared/modules/debsource/manifests/init.pp +++ b/shared/modules/debsource/manifests/init.pp @@ -13,7 +13,7 @@ define debsource($apt_source, $keyfile = '', $host = '', $hash = '') { if ($keyfile != '') { exec { "debsource-${name}": - command => "curl $keyfile | apt-key add -", + command => "curl $keyfile | apt-key add - && apt-get update", path => $base::path, require => File[$file], unless => "test $(apt-key list | grep ${hash} | wc -l) -ne 0" diff --git a/shared/modules/package_data/manifests/init.pp b/shared/modules/package_data/manifests/init.pp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/shared/modules/package_data/manifests/init.pp @@ -0,0 +1 @@ +