From: Tom Hughes Date: Fri, 8 Jan 2016 23:05:19 +0000 (+0000) Subject: Add a systemd unit for squid on Ubuntu 15.10 X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/de740c98fbdd4bc7a14c5b28cf09051045586ddc Add a systemd unit for squid on Ubuntu 15.10 --- diff --git a/cookbooks/squid/recipes/default.rb b/cookbooks/squid/recipes/default.rb index aedc8923f..89377089f 100644 --- a/cookbooks/squid/recipes/default.rb +++ b/cookbooks/squid/recipes/default.rb @@ -40,13 +40,38 @@ directory "/etc/squid/squid.conf.d" do mode 0755 end -service "squid" do - provider Chef::Provider::Service::Upstart - action [:enable, :start] - supports :status => true, :restart => true, :reload => true - subscribes :reload, "template[/etc/squid/squid.conf]" - subscribes :restart, "template[/etc/default/squid]" - subscribes :reload, "template[/etc/resolv.conf]" +if node[:lsb][:release].to_f >= 15.10 + execute "systemctl-daemon-reload" do + action :nothing + command "systemctl daemon-reload" + end + + template "/etc/systemd/system/squid.service" do + source "squid.service.erb" + owner "root" + group "root" + mode 0644 + notifies :run, "execute[systemctl-daemon-reload]" + end + + service "squid" do + provider Chef::Provider::Service::Systemd + action [:enable, :start] + supports :status => true, :restart => true, :reload => true + subscribes :restart, "template[/etc/systemd/system/squid.service]" + subscribes :reload, "template[/etc/squid/squid.conf]" + subscribes :restart, "template[/etc/default/squid]" + subscribes :reload, "template[/etc/resolv.conf]" + end +else + service "squid" do + provider Chef::Provider::Service::Upstart + action [:enable, :start] + supports :status => true, :restart => true, :reload => true + subscribes :reload, "template[/etc/squid/squid.conf]" + subscribes :restart, "template[/etc/default/squid]" + subscribes :reload, "template[/etc/resolv.conf]" + end end munin_plugin "squid_cache" diff --git a/cookbooks/squid/templates/default/squid.service.erb b/cookbooks/squid/templates/default/squid.service.erb new file mode 100644 index 000000000..07b9bb276 --- /dev/null +++ b/cookbooks/squid/templates/default/squid.service.erb @@ -0,0 +1,17 @@ +[Unit] +Description=Squid caching proxy +After=network.target nss-lookup.target + +[Service] +LimitNOFILE=65536 +Environment=SQUID_ARGS=-D +EnvironmentFile=/etc/default/squid +ExecStartPre=/usr/sbin/squid $SQUID_ARGS -z +ExecStart=/usr/sbin/squid -N $SQUID_ARGS +ExecReload=/usr/sbin/squid -k reconfigure +ExecStop=/usr/sbin/squid -k shutdown +Restart=on-failure +TimeoutSec=0 + +[Install] +WantedBy=multi-user.target