From de740c98fbdd4bc7a14c5b28cf09051045586ddc Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 8 Jan 2016 23:05:19 +0000 Subject: [PATCH] Add a systemd unit for squid on Ubuntu 15.10 --- cookbooks/squid/recipes/default.rb | 39 +++++++++++++++---- .../squid/templates/default/squid.service.erb | 17 ++++++++ 2 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 cookbooks/squid/templates/default/squid.service.erb 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 -- 2.39.5