puppet-standalone-mashup/shared/additional-modules/varnish/manifests/init.pp

111 lines
2.5 KiB
ObjectPascal
Raw Normal View History

2012-07-05 21:05:53 +00:00
class varnish($version = '', $vcl, $user = 'varnish', $group = 'varnish') {
if ($::osfamily == 'debian') {
$config = '/etc/varnish'
$default_varnish = '/etc/default/varnish'
2012-07-20 14:49:47 +00:00
$bin = "/usr/sbin/varnishd"
2012-07-05 21:05:53 +00:00
} 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)
$bin = "${sbin}/${name}d"
$pid = pid_path($name)
$log = log_path($name)
$default_varnish = "${config}/defaults"
}
2012-05-02 22:17:23 +00:00
$vcl_path = "${config}/default.vcl"
2012-07-05 21:05:53 +00:00
if ($::osfamily == 'debian') {
debsource { varnish:
apt_source => $debian::varnish_apt_source,
keyfile => $debian::varnish_keyfile,
hash => $debian::varnish_hash
}
2012-05-02 22:17:23 +00:00
2012-07-05 21:05:53 +00:00
$cache_root = "/var/lib"
$cache_dir = "${cache_root}/varnish"
2012-06-04 19:05:38 +00:00
2012-07-05 21:05:53 +00:00
package { varnish:
ensure => latest,
require => [
Debsource['varnish'], Mkdir_p[$cache_dir]
]
}
2012-06-04 19:05:38 +00:00
2012-07-20 14:49:47 +00:00
service { varnish:
ensure => stopped,
require => Package[varnish]
}
exec { 'update-rc.d -f varnish remove':
path => $::base::path,
require => Package[varnish]
}
2012-07-05 21:05:53 +00:00
$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]
}
2012-05-02 22:17:23 +00:00
2012-07-05 21:05:53 +00:00
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"
}
*/
2012-05-02 22:17:23 +00:00
}
2012-07-05 21:05:53 +00:00
file { $default_varnish:
content => template("varnish/default"),
2012-07-20 14:49:47 +00:00
notify => Service['god']
2012-05-02 22:17:23 +00:00
}
2012-05-08 19:10:26 +00:00
2012-05-14 13:15:05 +00:00
file { $vcl_path:
2012-06-04 19:05:38 +00:00
content => $vcl,
2012-07-20 14:49:47 +00:00
notify => Service['god']
2012-05-14 13:15:05 +00:00
}
2012-07-05 21:05:53 +00:00
mkdir_p { $cache_dir:
path => $base::path
}
2012-05-08 19:10:26 +00:00
god_init { $name:
2012-07-20 14:49:47 +00:00
start => "${bin} -T 127.0.0.1:6082 -F -u ${user} -g ${group} -w 1,1,3600 -f ${vcl_path} -s file,${cache_dir}/varnish",
2012-06-01 18:24:53 +00:00
dir => config_path('god.d'),
2012-05-08 19:10:26 +00:00
ensure => present,
2012-05-14 13:15:05 +00:00
require => File[$vcl_path],
interval => 10
2012-05-08 19:10:26 +00:00
}
2012-05-02 22:17:23 +00:00
}
2012-06-04 19:05:38 +00:00