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.
21 include_recipe "munin"
23 if node[:squid][:version] >= 3
24 apt_package "squid" do
28 apt_package "squid-common" do
32 apt_package "squid" do
34 only_if "dpkg-query -W squid | fgrep -q 2."
37 apt_package "squid-common" do
39 only_if "dpkg-query -W squid-common | fgrep -q 2."
42 file "/store/squid/coss-01" do
47 package "squidclient" do
55 template "/etc/squid/squid.conf" do
56 source "squid.conf.erb"
62 directory "/etc/squid/squid.conf.d" do
68 Array(node[:squid][:cache_dir]).each do |cache_dir|
69 if cache_dir =~ /^coss (\S+) /
70 cache_dir = File.dirname(Regexp.last_match(1))
71 elsif cache_dir =~ /^\S+ (\S+) /
72 cache_dir = Regexp.last_match(1)
75 directory cache_dir do
80 notifies :restart, "service[squid]"
84 systemd_tmpfile "/var/run/squid" do
91 address_families = %w[AF_UNIX AF_INET AF_INET6]
93 file "/etc/systemd/system/squid.service" do
97 file "/etc/logrotate.d/squid.dpkg-dist" do
101 systemd_service "squid" do
106 protect_system "full"
108 restrict_address_families address_families
110 exec_start "/usr/sbin/squid --foreground -YC"
113 # Quick hack to cleanup bloated journal
114 execute "tmp_journal_clean_up" do
115 command "/bin/journalctl --vacuum-time=1d"
120 subscribes :restart, "systemd_service[squid]"
121 subscribes :restart, "template[/etc/squid/squid.conf]"
122 subscribes :reload, "template[/etc/resolv.conf]"
125 notify_group "squid-start" do
127 notifies :start, "service[squid]"
130 service "squid-restart" do
134 IO.popen(["squidclient", "--host=127.0.0.1", "--port=3128", "mgr:counters"]) do |io|
135 io.each.grep(/^[a-z][a-z_.]+ = -[0-9]+$/).count.positive?
140 munin_plugin "squid_cache"
141 munin_plugin "squid_times"
142 munin_plugin "squid_icp"
143 munin_plugin "squid_objectsize"
144 munin_plugin "squid_requests"
145 munin_plugin "squid_traffic"
147 munin_plugin "squid_delay_pools" do
151 munin_plugin "squid_delay_pools_noreferer" do