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

113 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'
} 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-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"),
notify => Service[varnish]
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-05 21:05:53 +00:00
notify => Service[varnish]
2012-05-14 13:15:05 +00:00
}
2012-07-05 21:05:53 +00:00
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"
2012-05-08 19:10:26 +00:00
god_init { $name:
start => $varnish_start,
stop => $varnish_stop,
2012-06-01 18:24:53 +00:00
dir => config_path('god.d'),
2012-05-08 19:10:26 +00:00
restart => "${varnish_stop} && ${varnish_start}",
pid_file => $pid,
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-06-04 19:05:38 +00:00
2012-05-02 22:17:23 +00:00
}
2012-06-04 19:05:38 +00:00