squid and varnish fixes
This commit is contained in:
parent
63a75fdb36
commit
a3dcdbcece
@ -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)
|
||||
$sbin = sbin_path($name)
|
||||
|
||||
$build_dir = build_path($name, $version)
|
||||
$log_dir = log_path($name)
|
||||
$pid = pid_path($name)
|
||||
$data_dir = data_path($name)
|
||||
$cache_dir = data_path($name)
|
||||
$config_dir = config_path($name)
|
||||
$config = "${config_dir}/squid.conf"
|
||||
|
||||
mkdir_p { [ $log_dir, $data_dir, $config_dir ]:
|
||||
path => $base::path
|
||||
}
|
||||
|
||||
build_and_install { $name:
|
||||
version => $version,
|
||||
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')
|
||||
}
|
||||
|
||||
file { $config:
|
||||
content => template($config_template),
|
||||
require => Build_and_install[$name]
|
||||
Build_and_install[$name] -> File[$config]
|
||||
}
|
||||
|
||||
$squid_start = 'service squid start'
|
||||
$squid_stop = 'service squid stop'
|
||||
mkdir_p { [ $log_dir, $cache_dir, $config_dir ]:
|
||||
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:
|
||||
start => $squid_start,
|
||||
stop => $squid_stop,
|
||||
restart => "${squid_stop} && ${squid_start}",
|
||||
pid_file => $pid,
|
||||
start => "${sbin}/squid3 -YC -f ${config} -N -a 80",
|
||||
dir => config_path('god.d'),
|
||||
ensure => present,
|
||||
require => File[$config],
|
||||
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'
|
||||
|
||||
$default_varnish = '/etc/default/varnish'
|
||||
$bin = "/usr/sbin/varnishd"
|
||||
} else {
|
||||
$install_path = install_path($name, $version)
|
||||
$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)
|
||||
|
||||
Package['varnish'] -> File[$default_varnish, $vcl_path]
|
||||
@ -76,37 +87,24 @@ class varnish($version = '', $vcl, $user = 'varnish', $group = 'varnish') {
|
||||
|
||||
file { $default_varnish:
|
||||
content => template("varnish/default"),
|
||||
notify => Service[varnish]
|
||||
notify => Service['god']
|
||||
}
|
||||
|
||||
file { $vcl_path:
|
||||
content => $vcl,
|
||||
notify => Service[varnish]
|
||||
notify => Service['god']
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
god_init { $name:
|
||||
start => $varnish_start,
|
||||
stop => $varnish_stop,
|
||||
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",
|
||||
dir => config_path('god.d'),
|
||||
restart => "${varnish_stop} && ${varnish_start}",
|
||||
pid_file => $pid,
|
||||
ensure => present,
|
||||
require => File[$vcl_path],
|
||||
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 %>
|
||||
|
||||
w.interval = <%= interval %>.seconds
|
||||
|
||||
w.start = %{<%= start %>}
|
||||
|
||||
w.start_if do |start|
|
||||
start.condition(:process_running) do |c|
|
||||
c.interval = <%= interval %>.seconds
|
||||
c.running = false
|
||||
end
|
||||
end
|
||||
w.keepalive
|
||||
end
|
||||
GOD
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user