2012-06-04 19:05:38 +00:00
|
|
|
class varnish($version, $vcl, $user = 'varnish', $group = 'varnish', $store_file_mb = 1024) {
|
2012-05-02 22:17:23 +00:00
|
|
|
$install_path = install_path($name, $version)
|
|
|
|
$config = config_path($name)
|
|
|
|
$share = share_path($name)
|
|
|
|
$data = data_path($name)
|
2012-05-08 19:10:26 +00:00
|
|
|
$sbin = sbin_path($name)
|
|
|
|
$bin_path = bin_path($name)
|
|
|
|
|
|
|
|
$bin = "${sbin}/${name}d"
|
|
|
|
$pid = pid_path($name)
|
|
|
|
$log = log_path($name)
|
|
|
|
|
|
|
|
$ncsa_bin = "${bin_path}/varnishncsa"
|
|
|
|
$ncsa_pid = pid_path('varnishncsa')
|
2012-05-14 13:15:05 +00:00
|
|
|
$ncsa_log = "${log}/access.log"
|
2012-05-02 22:17:23 +00:00
|
|
|
|
|
|
|
$vcl_path = "${config}/default.vcl"
|
|
|
|
|
|
|
|
$store_file_path = "${data}/store"
|
|
|
|
$store_file_size = $store_file_mb * 1024 * 1024
|
|
|
|
|
2012-06-04 19:05:38 +00:00
|
|
|
$varnish_start = "service varnish start"
|
|
|
|
$varnish_stop = "service varnish stop"
|
|
|
|
$varnish_rotate = "service varnish rotate"
|
|
|
|
|
|
|
|
$source = "http://repo.varnish-cache.org/source/varnish-${version}.tar.gz"
|
|
|
|
$dirs = [ $config, $log, $share, $data ]
|
|
|
|
|
2012-05-02 22:17:23 +00:00
|
|
|
build_and_install { $name:
|
|
|
|
version => $version,
|
2012-06-04 19:05:38 +00:00
|
|
|
source => $source
|
2012-05-02 22:17:23 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 19:05:38 +00:00
|
|
|
mkdir_p { $dirs:
|
2012-05-02 22:17:23 +00:00
|
|
|
path => $base::path,
|
|
|
|
require => Build_and_install[$name]
|
|
|
|
}
|
|
|
|
|
2012-06-04 19:05:38 +00:00
|
|
|
exec { "${name} create-store-file":
|
2012-05-02 22:17:23 +00:00
|
|
|
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
|
|
|
|
}
|
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-05-14 13:15:05 +00:00
|
|
|
require => Build_and_install[$name]
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
/* 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:
|
2012-06-04 20:30:49 +00:00
|
|
|
require => Mkdir_p[$dirs]
|
2012-06-04 19:05:38 +00:00
|
|
|
}
|
2012-05-02 22:17:23 +00:00
|
|
|
}
|
2012-06-04 19:05:38 +00:00
|
|
|
|