diff --git a/shared/additional-modules/squid/manifests/init.pp b/shared/additional-modules/squid/manifests/init.pp index ac071fb..ff31a3d 100644 --- a/shared/additional-modules/squid/manifests/init.pp +++ b/shared/additional-modules/squid/manifests/init.pp @@ -1,49 +1,74 @@ -class squid($version, $user, $config_template, $error_template) { - $bin = bin_path($name) - $sbin = sbin_path($name) +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' - $build_dir = build_path($name, $version) - $log_dir = log_path($name) - $pid = pid_path($name) - $data_dir = data_path($name) - $config_dir = config_path($name) - $config = "${config_dir}/squid.conf" + package { 'squid3': ensure => latest } - 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 } - 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') + 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), - require => Build_and_install[$name] + content => template($config_template) } - $squid_start = 'service squid start' - $squid_stop = 'service squid stop' - 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'] - } } diff --git a/shared/additional-modules/varnish/manifests/init.pp b/shared/additional-modules/varnish/manifests/init.pp index d5379a2..29c54e7 100644 --- a/shared/additional-modules/varnish/manifests/init.pp +++ b/shared/additional-modules/varnish/manifests/init.pp @@ -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 } - } diff --git a/shared/lib/puppet/parser/functions/find_path.rb b/shared/lib/puppet/parser/functions/find_path.rb new file mode 100644 index 0000000..e4bbbac --- /dev/null +++ b/shared/lib/puppet/parser/functions/find_path.rb @@ -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 + diff --git a/shared/lib/puppet/provider/god_init/install.rb b/shared/lib/puppet/provider/god_init/install.rb index 5d4ad29..9bf8f9b 100644 --- a/shared/lib/puppet/provider/god_init/install.rb +++ b/shared/lib/puppet/provider/god_init/install.rb @@ -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