]> git.openstreetmap.org Git - chef.git/blob - cookbooks/squid/recipes/default.rb
Add support for squid 3.x
[chef.git] / cookbooks / squid / recipes / default.rb
1 #
2 # Cookbook Name:: 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 if node[:squid][:version] == "3"
21   package "squid" do
22     action :remove
23     only_if "dpkg-query -W squid | fgrep -q 2."
24   end
25
26   package "squid-common" do
27     action :remove
28     only_if "dpkg-query -W squid-common | fgrep -q 2."
29   end
30
31   apt_package "squid" do
32     action :unlock
33   end
34
35   apt_package "squid-common" do
36     action :unlock
37   end
38
39   file "/store/squid/coss-01" do
40     action :delete
41   end
42 end
43
44 package "squid"
45 package "squidclient"
46
47 template "/etc/squid/squid.conf" do
48   source "squid.conf.erb"
49   owner "root"
50   group "root"
51   mode 0o644
52 end
53
54 template "/etc/default/squid" do
55   source "squid.erb"
56   owner "root"
57   group "root"
58   mode 0o644
59 end
60
61 directory "/etc/squid/squid.conf.d" do
62   owner "root"
63   group "root"
64   mode 0o755
65 end
66
67 if node[:squid][:cache_dir] =~ /^coss (\S+) /
68   cache_dir = File.dirname(Regexp.last_match(1))
69 elsif node[:squid][:cache_dir] =~ /^\S+ (\S+) /
70   cache_dir = Regexp.last_match(1)
71 end
72
73 directory cache_dir do
74   owner "proxy"
75   group "proxy"
76   mode 0o750
77   recursive true
78 end
79
80 systemd_tmpfile "/var/run/squid" do
81   type "d"
82   owner "proxy"
83   group "proxy"
84   mode "0755"
85 end
86
87 systemd_service "squid" do
88   description "Squid caching proxy"
89   after ["network.target", "nss-lookup.target"]
90   type "forking"
91   limit_nofile 65536
92   exec_start_pre "/usr/sbin/squid -z"
93   exec_start "/usr/sbin/squid"
94   exec_reload "/usr/sbin/squid -k reconfigure"
95   exec_stop "/usr/sbin/squid -k shutdown"
96   private_tmp true
97   private_devices true
98   protect_system "full"
99   protect_home true
100   restart "on-failure"
101   timeout_sec 0
102 end
103
104 service "squid" do
105   action [:enable, :start]
106   subscribes :restart, "systemd_service[squid]"
107   subscribes :reload, "template[/etc/squid/squid.conf]"
108   subscribes :restart, "template[/etc/default/squid]"
109   subscribes :reload, "template[/etc/resolv.conf]"
110 end
111
112 log "squid-restart" do
113   message "Restarting squid due to counter wraparound"
114   notifies :restart, "service[squid]"
115   only_if do
116     IO.popen(["squidclient", "--host=127.0.0.1", "--port=80", "mgr:counters"]) do |io|
117       io.each.grep(/^[a-z][a-z_.]+ = -[0-9]+$/).count.positive?
118     end
119   end
120 end
121
122 munin_plugin "squid_cache"
123 munin_plugin "squid_delay_pools"
124 munin_plugin "squid_delay_pools_noreferer"
125 munin_plugin "squid_times"
126 munin_plugin "squid_icp"
127 munin_plugin "squid_objectsize"
128 munin_plugin "squid_requests"
129 munin_plugin "squid_traffic"
130
131 Dir.glob("/var/log/squid/zere.log*") do |log|
132   File.unlink(log)
133 end