working on more cleanup stuff

This commit is contained in:
John Bintz 2012-07-05 17:05:53 -04:00
parent dc101f527b
commit cf5170fbb1
10 changed files with 126 additions and 69 deletions

View File

@ -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"
}

View File

@ -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:

View File

@ -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]
}
}

View File

@ -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 \
"

View File

@ -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

View File

@ -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

View File

@ -6,4 +6,3 @@ module Puppet::Parser::Functions
end
end

View File

@ -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

View File

@ -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"

View File

@ -0,0 +1 @@