]> git.openstreetmap.org Git - chef.git/commitdiff
Add a systemd unit for squid on Ubuntu 15.10
authorTom Hughes <tom@compton.nu>
Fri, 8 Jan 2016 23:05:19 +0000 (23:05 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 8 Jan 2016 23:05:19 +0000 (23:05 +0000)
cookbooks/squid/recipes/default.rb
cookbooks/squid/templates/default/squid.service.erb [new file with mode: 0644]

index aedc8923ff5b393a9b58ae776e23a332ce24b646..89377089f072bf912448f81180600dab10fc00f7 100644 (file)
@@ -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 (file)
index 0000000..07b9bb2
--- /dev/null
@@ -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