]> git.openstreetmap.org Git - chef.git/blob - cookbooks/squid/recipes/default.rb
squid: disable forced syslog logging
[chef.git] / cookbooks / squid / recipes / default.rb
1 #
2 # Cookbook:: squid
3 # Recipe:: default
4 #
5 # Copyright:: 2011, OpenStreetMap Foundation
6 #
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
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19
20 include_recipe "apt"
21 include_recipe "munin"
22
23 if node[:squid][:version] >= 3
24   apt_package "squid" do
25     action :unlock
26   end
27
28   apt_package "squid-common" do
29     action :unlock
30   end
31
32   apt_package "squid" do
33     action :purge
34     only_if "dpkg-query -W squid | fgrep -q 2."
35   end
36
37   apt_package "squid-common" do
38     action :purge
39     only_if "dpkg-query -W squid-common | fgrep -q 2."
40   end
41
42   file "/store/squid/coss-01" do
43     action :delete
44     backup false
45   end
46
47   package "squidclient" do
48     action :upgrade
49   end
50 end
51
52 package "squid"
53 package "squidclient"
54
55 template "/etc/squid/squid.conf" do
56   source "squid.conf.erb"
57   owner "root"
58   group "root"
59   mode "644"
60 end
61
62 directory "/etc/squid/squid.conf.d" do
63   owner "root"
64   group "root"
65   mode "755"
66 end
67
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)
73   end
74
75   directory cache_dir do
76     owner "proxy"
77     group "proxy"
78     mode "750"
79     recursive true
80     notifies :restart, "service[squid]"
81   end
82 end
83
84 systemd_tmpfile "/var/run/squid" do
85   type "d"
86   owner "proxy"
87   group "proxy"
88   mode "0755"
89 end
90
91 address_families = %w[AF_UNIX AF_INET AF_INET6]
92
93 file "/etc/systemd/system/squid.service" do
94   action :delete
95 end
96
97 file "/etc/logrotate.d/squid.dpkg-dist" do
98   action :delete
99 end
100
101 systemd_service "squid" do
102   dropin "chef"
103   limit_nofile 98304
104   private_tmp true
105   private_devices true
106   protect_system "full"
107   protect_home true
108   restrict_address_families address_families
109   restart "always"
110   ExecStart "/usr/sbin/squid --foreground -YC"
111 end
112
113 service "squid" do
114   action :enable
115   subscribes :restart, "systemd_service[squid]"
116   subscribes :restart, "template[/etc/squid/squid.conf]"
117   subscribes :reload, "template[/etc/resolv.conf]"
118 end
119
120 notify_group "squid-start" do
121   action :run
122   notifies :start, "service[squid]"
123 end
124
125 service "squid-restart" do
126   service_name "squid"
127   action :restart
128   only_if do
129     IO.popen(["squidclient", "--host=127.0.0.1", "--port=3128", "mgr:counters"]) do |io|
130       io.each.grep(/^[a-z][a-z_.]+ = -[0-9]+$/).count.positive?
131     end
132   end
133 end
134
135 munin_plugin "squid_cache"
136 munin_plugin "squid_times"
137 munin_plugin "squid_icp"
138 munin_plugin "squid_objectsize"
139 munin_plugin "squid_requests"
140 munin_plugin "squid_traffic"
141
142 munin_plugin "squid_delay_pools" do
143   action :delete
144 end
145
146 munin_plugin "squid_delay_pools_noreferer" do
147   action :delete
148 end