squid and varnish fixes

This commit is contained in:
John Bintz 2012-07-20 10:49:47 -04:00
parent 63a75fdb36
commit a3dcdbcece
4 changed files with 82 additions and 56 deletions

View File

@ -1,18 +1,34 @@
class squid($version, $user, $config_template, $error_template) { class squid($version = '', $user = 'proxy', $group = 'proxy', $config_template, $error_template) {
if ($::osfamily == 'debian') {
$cache_dir = '/var/spool/squid3'
$config_dir = "/etc/squid3"
$config = "${config_dir}/squid.conf"
$log_dir = "/var/log/squid3"
$sbin = '/usr/sbin'
package { 'squid3': ensure => latest }
service { squid3:
ensure => stopped,
require => Package[squid3]
}
Package['squid3'] -> File[$config]
exec { 'update-rc.d -f squid3 remove':
path => $::base::path
}
} else {
$bin = bin_path($name) $bin = bin_path($name)
$sbin = sbin_path($name) $sbin = sbin_path($name)
$build_dir = build_path($name, $version) $build_dir = build_path($name, $version)
$log_dir = log_path($name) $log_dir = log_path($name)
$pid = pid_path($name) $pid = pid_path($name)
$data_dir = data_path($name) $cache_dir = data_path($name)
$config_dir = config_path($name) $config_dir = config_path($name)
$config = "${config_dir}/squid.conf" $config = "${config_dir}/squid.conf"
mkdir_p { [ $log_dir, $data_dir, $config_dir ]:
path => $base::path
}
build_and_install { $name: build_and_install { $name:
version => $version, version => $version,
source => "http://www.squid-cache.org/Versions/v3/3.1/squid-${version}.tar.bz2", source => "http://www.squid-cache.org/Versions/v3/3.1/squid-${version}.tar.bz2",
@ -20,30 +36,39 @@ class squid($version, $user, $config_template, $error_template) {
preconfigure => template('squid/preconfigure') preconfigure => template('squid/preconfigure')
} }
file { $config: Build_and_install[$name] -> File[$config]
content => template($config_template),
require => Build_and_install[$name]
} }
$squid_start = 'service squid start' mkdir_p { [ $log_dir, $cache_dir, $config_dir ]:
$squid_stop = 'service squid stop' path => $base::path
}
exec { "chown -R ${user}:${group} ${log_dir}":
path => $::base::path,
require => Mkdir_p[$log_dir]
}
exec { cache_dir_perms:
command => "chown -R ${user}:${group} ${cache_dir}",
path => $::base::path,
require => Mkdir_p[$cache_dir]
}
exec { "${sbin}/squid3 -z":
path => $::base::path,
require => Exec[cache_dir_perms]
}
file { $config:
content => template($config_template)
}
god_init { $name: god_init { $name:
start => $squid_start, start => "${sbin}/squid3 -YC -f ${config} -N -a 80",
stop => $squid_stop, dir => config_path('god.d'),
restart => "${squid_stop} && ${squid_start}",
pid_file => $pid,
ensure => present, ensure => present,
require => File[$config], require => File[$config],
interval => 10 interval => 10
} }
file { [
"${data_dir}/errors/en/ERR_CANNOT_FORWARD",
"${data_dir}/errors/templates/ERR_CANNOT_FORWARD"
]:
content => template($error_template),
require => Build_and_install['squid']
}
} }

View File

@ -3,6 +3,7 @@ class varnish($version = '', $vcl, $user = 'varnish', $group = 'varnish') {
$config = '/etc/varnish' $config = '/etc/varnish'
$default_varnish = '/etc/default/varnish' $default_varnish = '/etc/default/varnish'
$bin = "/usr/sbin/varnishd"
} else { } else {
$install_path = install_path($name, $version) $install_path = install_path($name, $version)
$config = config_path($name) $config = config_path($name)
@ -37,6 +38,16 @@ class varnish($version = '', $vcl, $user = 'varnish', $group = 'varnish') {
] ]
} }
service { varnish:
ensure => stopped,
require => Package[varnish]
}
exec { 'update-rc.d -f varnish remove':
path => $::base::path,
require => Package[varnish]
}
$store_file_size = dir_size($cache_root) $store_file_size = dir_size($cache_root)
Package['varnish'] -> File[$default_varnish, $vcl_path] Package['varnish'] -> File[$default_varnish, $vcl_path]
@ -76,37 +87,24 @@ class varnish($version = '', $vcl, $user = 'varnish', $group = 'varnish') {
file { $default_varnish: file { $default_varnish:
content => template("varnish/default"), content => template("varnish/default"),
notify => Service[varnish] notify => Service['god']
} }
file { $vcl_path: file { $vcl_path:
content => $vcl, content => $vcl,
notify => Service[varnish] notify => Service['god']
} }
mkdir_p { $cache_dir: mkdir_p { $cache_dir:
path => $base::path 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: god_init { $name:
start => $varnish_start, 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",
stop => $varnish_stop,
dir => config_path('god.d'), dir => config_path('god.d'),
restart => "${varnish_stop} && ${varnish_start}",
pid_file => $pid,
ensure => present, ensure => present,
require => File[$vcl_path], require => File[$vcl_path],
interval => 10 interval => 10
} }
} }

View File

@ -0,0 +1,10 @@
module Puppet::Parser::Functions
newfunction(:find_path, :type => :rvalue) do |name, root|
Pathname(root).find do |file|
return file.to_s if file.basename == name
end
raise StandardError.new("File not found in #{root}: #{name}")
end
end

View File

@ -51,15 +51,8 @@ God.watch do |w|
<% end %> <% end %>
w.interval = <%= interval %>.seconds w.interval = <%= interval %>.seconds
w.start = %{<%= start %>} w.start = %{<%= start %>}
w.keepalive
w.start_if do |start|
start.condition(:process_running) do |c|
c.interval = <%= interval %>.seconds
c.running = false
end
end
end end
GOD GOD
end end