squid and varnish fixes
This commit is contained in:
parent
63a75fdb36
commit
a3dcdbcece
@ -1,49 +1,74 @@
|
|||||||
class squid($version, $user, $config_template, $error_template) {
|
class squid($version = '', $user = 'proxy', $group = 'proxy', $config_template, $error_template) {
|
||||||
$bin = bin_path($name)
|
if ($::osfamily == 'debian') {
|
||||||
$sbin = sbin_path($name)
|
$cache_dir = '/var/spool/squid3'
|
||||||
|
$config_dir = "/etc/squid3"
|
||||||
|
$config = "${config_dir}/squid.conf"
|
||||||
|
$log_dir = "/var/log/squid3"
|
||||||
|
$sbin = '/usr/sbin'
|
||||||
|
|
||||||
$build_dir = build_path($name, $version)
|
package { 'squid3': ensure => latest }
|
||||||
$log_dir = log_path($name)
|
|
||||||
$pid = pid_path($name)
|
|
||||||
$data_dir = data_path($name)
|
|
||||||
$config_dir = config_path($name)
|
|
||||||
$config = "${config_dir}/squid.conf"
|
|
||||||
|
|
||||||
mkdir_p { [ $log_dir, $data_dir, $config_dir ]:
|
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)
|
||||||
|
$sbin = sbin_path($name)
|
||||||
|
|
||||||
|
$build_dir = build_path($name, $version)
|
||||||
|
$log_dir = log_path($name)
|
||||||
|
$pid = pid_path($name)
|
||||||
|
$cache_dir = data_path($name)
|
||||||
|
$config_dir = config_path($name)
|
||||||
|
$config = "${config_dir}/squid.conf"
|
||||||
|
|
||||||
|
build_and_install { $name:
|
||||||
|
version => $version,
|
||||||
|
source => "http://www.squid-cache.org/Versions/v3/3.1/squid-${version}.tar.bz2",
|
||||||
|
configure => template('squid/configure'),
|
||||||
|
preconfigure => template('squid/preconfigure')
|
||||||
|
}
|
||||||
|
|
||||||
|
Build_and_install[$name] -> File[$config]
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdir_p { [ $log_dir, $cache_dir, $config_dir ]:
|
||||||
path => $base::path
|
path => $base::path
|
||||||
}
|
}
|
||||||
|
|
||||||
build_and_install { $name:
|
exec { "chown -R ${user}:${group} ${log_dir}":
|
||||||
version => $version,
|
path => $::base::path,
|
||||||
source => "http://www.squid-cache.org/Versions/v3/3.1/squid-${version}.tar.bz2",
|
require => Mkdir_p[$log_dir]
|
||||||
configure => template('squid/configure'),
|
}
|
||||||
preconfigure => template('squid/preconfigure')
|
|
||||||
|
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:
|
file { $config:
|
||||||
content => template($config_template),
|
content => template($config_template)
|
||||||
require => Build_and_install[$name]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$squid_start = 'service squid start'
|
|
||||||
$squid_stop = 'service squid stop'
|
|
||||||
|
|
||||||
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']
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
shared/lib/puppet/parser/functions/find_path.rb
Normal file
10
shared/lib/puppet/parser/functions/find_path.rb
Normal 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
|
||||||
|
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user