This commit is contained in:
John Bintz 2012-05-17 11:11:25 -04:00
parent 3b6ff0cfa6
commit 4adce0258e
7 changed files with 137 additions and 23 deletions

View File

@ -19,7 +19,20 @@ Capistrano::Configuration.instance.load do
end
end
before 'apply', 'ensure_puppet'
before 'bootstrap', 'ensure_puppet'
desc "Fix DNS resolution if bitten by the VirtualBox DNS bug"
task :fix_dns do
result = capture("ping -w 1 -W 1 -c 1 -q google.com; echo $?").lines.to_a.last.strip
if result.to_i != 0
run "#{sudo} sed -i 's#10.0.2.3#10.0.2.2#g' /etc/resolv.conf"
result = capture("ping -w 1 -W 1 -c 1 -q google.com; echo $?").lines.to_a.last.strip
if result.to_i != 0
raise StandardError.new("Unable to fix DNS to get around VirtualBox DNS bug.")
end
end
end
before 'apply', 'ensure_puppet', 'fix_dns'
before 'bootstrap', 'ensure_puppet', 'fix_dns'
end

View File

@ -1,4 +1,4 @@
class squid::debian($version, $config_template) {
class squid::debian($version, $config_template, $error_template) {
$squid_user = 'squid'
$squid_group = 'squid'
@ -8,6 +8,7 @@ class squid::debian($version, $config_template) {
version => $version,
user => 'squid',
config_template => $config_template,
error_template => $error_template,
require => User['squid']
}
@ -18,7 +19,7 @@ class squid::debian($version, $config_template) {
}
exec { 'ensure-data-dir-ownership':
command => "chown -R ${squid_user}:${squid_group} ${squid::data}",
command => "chown -R ${squid_user}:${squid_group} ${squid::data_dir} ${squid::log_dir}",
path => $base::path,
require => Class['squid']
}

View File

@ -1,6 +1,8 @@
class squid($version, $user, $config_template) {
$build_command = template('squid/build-squid.sh')
class squid($version, $user, $config_template, $error_template) {
$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)
@ -18,29 +20,29 @@ class squid($version, $user, $config_template) {
preconfigure => template('squid/preconfigure')
}
$squid_imgsrc_ip = extlookup('squid_imgsrc_ip')
$squid_cache_dir_size = extlookup('squid_cache_dir_size')
$config = '/etc/squid3/squid.conf'
file { $config:
content => template($config_template),
require => Exec['build-squid']
require => Build_and_install[$name]
}
exec { 'squid -z':
require => [ File['/var/log/squid3'], File['/var/spool/squid3'] ],
path => '/usr/bin:/usr/sbin:/bin:/sbin',
unless => 'test -d /var/spool/squid3/10'
}
$squid_start = 'service squid start'
$squid_stop = 'service squid stop'
god_conf { $name: }
god_init { $name:
start => $squid_start,
stop => $squid_stop,
restart => "${squid_stop} && ${squid_start}",
pid_file => $pid,
ensure => present,
require => File[$config],
interval => 10
}
file { [
'/usr/share/squid3/errors/en/ERR_CANNOT_FORWARD',
'/usr/share/squid3/errors/templates/ERR_CANNOT_FORWARD'
"${data_dir}/errors/en/ERR_CANNOT_FORWARD",
"${data_dir}/errors/templates/ERR_CANNOT_FORWARD"
]:
content => template('squid/error_page.html'),
content => template($error_template),
require => Build_and_install['squid']
}
}

View File

@ -0,0 +1 @@
ulimit -n 65535

View File

@ -0,0 +1,14 @@
# squid3 Startup script for the SQUID HTTP proxy-cache.
#
# Version: @(#)squid3.rc 1.0 07-Jul-2006 luigi@debian.org
#
### BEGIN INIT INFO
# Provides: squid3
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Should-Start: $named
# Should-Stop: $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Squid HTTP Proxy version 3.0
### END INIT INFO

View File

@ -0,0 +1,76 @@
<%= scope.function_template('base/init-d-header') %>
<%= init_d_prolog %>
<%= init_d_prerun %>
PATH=<%= scope::lookupvar('squid::sbin') %>:<%= scope::lookupvar('squid::bin') %>:$PATH
BIN=<%= scope.lookupvar('squid::sbin') %>/squid
PID=<%= scope.lookupvar('squid::pid') %>
CONFIG=<%= scope.lookupvar('squid::config') %>
ARGS="-YC -f $CONFIG"
find_cache_dir() {
w=" " # space tab
res=`sed -ne '
s/^'$1'['"$w"']\+[^'"$w"']\+['"$w"']\+\([^'"$w"']\+\).*$/\1/p;
t end;
d;
:end q' < $CONFIG`
[ -n "$res" ] || res=$2
echo "$res"
}
find_cache_type() {
w=" " # space tab
res=`sed -ne '
s/^'$1'['"$w"']\+\([^'"$w"']\+\).*$/\1/p;
t end;
d;
:end q' < $CONFIG`
[ -n "$res" ] || res=$2
echo "$res"
}
start() {
cache_dir=`find_cache_dir cache_dir <%= scope.lookupvar('squid::data_dir') %>`
cache_type=`find_cache_type cache_dir ufs`
#
# Create spool dirs if they don't exist.
#
if [ "$cache_type" = "coss" -a -d "$cache_dir" -a ! -f "$cache_dir/stripe" ] || [ "$cache_type" != "coss" -a -d "$cache_dir" -a ! -d "$cache_dir/00" ]; then
echo "Creating $DESC cache structure"
$BIN -z
fi
umask 027
ulimit -n 65535
$BIN $ARGS
RETVAL=$?
return $RETVAL
}
stop() {
PIDID=`cat $PID 2>/dev/null`
if [ -f $PID ]; then
kill $PIDID
fi
cnt=0
while kill -0 $PIDID 2>/dev/null
do
cnt=`expr $cnt + 1`
if [ $cnt -gt 24 ]
then
RETVAL=1
return RETVAL
fi
sleep 5
done
return $RETVAL
}
<%= scope.function_template('base/init-d-actions') %>

View File

@ -1,8 +1,15 @@
define init_d_bundle($init_d_prolog, $init_d_prerun) {
$init_d_source = "${base::share_path}/${name}/${name}-init.d"
$share_path = "${base::share_path}/${name}"
file { $share_path:
ensure => directory
}
$init_d_source = "${share_path}/${name}-init.d"
file { $init_d_source:
content => template("${name}/${name}-init.d"),
mode => 755
mode => 755,
require => File[$share_path]
}
$init_d = "/etc/init.d/${name}"