puppet-standalone-mashup/additional-modules/squid/manifests/init.pp

99 lines
2.5 KiB
ObjectPascal
Raw Normal View History

2012-07-20 14:49:47 +00:00
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 }
2012-08-14 22:52:55 +00:00
package { 'squidclient': ensure => latest }
2012-07-20 14:49:47 +00:00
service { squid3:
ensure => stopped,
require => Package[squid3]
}
Package['squid3'] -> File[$config]
2012-07-20 18:43:07 +00:00
Package['squid3'] -> Exec['stop-squid-for-good'] -> Exec['squid-cache']
2012-07-20 14:49:47 +00:00
2012-07-20 18:43:07 +00:00
exec { 'stop-squid-for-good':
command => 'service squid3 stop ; update-rc.d -f squid3 remove',
2012-07-20 14:49:47 +00:00
path => $::base::path
}
2012-07-20 18:43:07 +00:00
logrotate_d { 'squid3':
postrotate => 'god signal squid HUP',
pattern => "${log_dir}/access.log"
}
2012-07-20 14:49:47 +00:00
} 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]
2012-07-20 18:43:07 +00:00
Build_and_install[$name] -> Exec[cache_dir_perms]
2012-07-20 14:49:47 +00:00
}
mkdir_p { [ $log_dir, $cache_dir, $config_dir ]:
path => $base::path
2012-05-17 00:33:40 +00:00
}
2012-07-27 21:28:31 +00:00
exec { log_dir_params:
command => "chown -R ${user}:${group} ${log_dir}",
2012-07-20 14:49:47 +00:00
path => $::base::path,
require => Mkdir_p[$log_dir]
2012-05-17 00:33:40 +00:00
}
2012-07-20 18:43:07 +00:00
exec { 'cache_dir_perms':
2012-07-20 14:49:47 +00:00
command => "chown -R ${user}:${group} ${cache_dir}",
path => $::base::path,
require => Mkdir_p[$cache_dir]
}
2012-07-20 18:43:07 +00:00
exec { 'squid-cache':
command => "${sbin}/squid3 -z",
logoutput => true,
2012-07-27 21:28:31 +00:00
require => Exec[cache_dir_perms, log_dir_params],
2012-08-02 15:17:45 +00:00
unless => "test -d ${cache_dir}/00",
2012-07-20 18:43:07 +00:00
path => $::base::path
}
file { "${sbin}/clear-squid-cache":
content => template('squid/clear-squid-cache'),
mode => 0755
}
2012-07-20 18:43:07 +00:00
exec { 'cache_dir_perms_again':
command => "chown -R ${user}:${group} ${cache_dir}",
2012-07-20 14:49:47 +00:00
path => $::base::path,
2012-07-20 18:43:07 +00:00
require => Exec['squid-cache']
2012-05-17 00:33:40 +00:00
}
2012-07-20 14:49:47 +00:00
file { $config:
content => template($config_template)
}
2012-05-17 15:11:25 +00:00
god_init { $name:
2012-07-20 14:49:47 +00:00
start => "${sbin}/squid3 -YC -f ${config} -N -a 80",
dir => config_path('god.d'),
2012-05-17 15:11:25 +00:00
ensure => present,
require => File[$config],
interval => 10
2012-05-17 00:33:40 +00:00
}
}