5 # Copyright:: 2011, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # https://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 if node[:squid][:version] >= 3
21 apt_package "squid" do
25 apt_package "squid-common" do
29 apt_package "squid" do
31 only_if "dpkg-query -W squid | fgrep -q 2."
34 apt_package "squid-common" do
36 only_if "dpkg-query -W squid-common | fgrep -q 2."
39 file "/store/squid/coss-01" do
44 package "squidclient" do
52 template "/etc/squid/squid.conf" do
53 source "squid.conf.erb"
59 directory "/etc/squid/squid.conf.d" do
65 Array(node[:squid][:cache_dir]).each do |cache_dir|
66 if cache_dir =~ /^coss (\S+) /
67 cache_dir = File.dirname(Regexp.last_match(1))
68 elsif cache_dir =~ /^\S+ (\S+) /
69 cache_dir = Regexp.last_match(1)
72 directory cache_dir do
77 notifies :restart, "service[squid]"
81 systemd_tmpfile "/var/run/squid" do
88 address_families = %w[AF_UNIX AF_INET]
90 # address_families << "AF_INET6" unless node.interfaces(:family => :inet6).empty?
92 systemd_service "squid" do
93 description "Squid caching proxy"
94 after ["network.target", "nss-lookup.target"]
97 exec_start_pre "/usr/sbin/squid -N -z"
98 exec_start "/usr/sbin/squid -Y"
99 exec_reload "/usr/sbin/squid -k reconfigure"
100 exec_stop "/usr/sbin/squid -k shutdown"
103 protect_system "full"
105 restrict_address_families address_families
111 action [:enable, :start]
112 subscribes :restart, "systemd_service[squid]"
113 subscribes :reload, "template[/etc/squid/squid.conf]"
114 subscribes :reload, "template[/etc/resolv.conf]"
117 log "squid-restart" do
118 message "Restarting squid due to counter wraparound"
119 notifies :restart, "service[squid]"
121 IO.popen(["squidclient", "--host=127.0.0.1", "--port=80", "mgr:counters"]) do |io|
122 io.each.grep(/^[a-z][a-z_.]+ = -[0-9]+$/).count.positive?
127 munin_plugin "squid_cache"
128 munin_plugin "squid_times"
129 munin_plugin "squid_icp"
130 munin_plugin "squid_objectsize"
131 munin_plugin "squid_requests"
132 munin_plugin "squid_traffic"
134 munin_plugin "squid_delay_pools" do
138 munin_plugin "squid_delay_pools_noreferer" do