depends "git"
depends "ohai"
depends "munin"
+depends "systemd"
end
if node[:lsb][:release].to_f >= 15.10
- execute "systemctl-daemon-reload" do
- action :nothing
- command "systemctl daemon-reload"
- end
-
- template "/etc/systemd/system/chef-client.service" do
- source "chef-client.service.erb"
- owner "root"
- group "root"
- mode 0644
- notifies :run, "execute[systemctl-daemon-reload]"
+ systemd_service "chef-client" do
+ description "Chef client"
+ after "network.target"
+ exec_start "/usr/bin/chef-client -i 1800 -s 20"
+ restart "on-failure"
end
service "chef-client" do
action [:enable, :start]
supports :status => true, :restart => true, :reload => true
subscribes :restart, "dpkg_package[chef]"
- subscribes :restart, "template[/etc/systemd/system/chef-client.service]"
+ subscribes :restart, "systemd_service[chef-client]"
subscribes :restart, "template[/etc/chef/client.rb]"
subscribes :restart, "template[/etc/chef/report.rb]"
end
+++ /dev/null
-[Unit]
-Description=Chef Client
-After=network.target
-
-[Service]
-ExecStart=/usr/bin/chef-client -i 1800 -s 20
-Restart=on-failure
-
-[Install]
-WantedBy=multi-user.target
description "Installs and configures squid"
long_description IO.read(File.join(File.dirname(__FILE__), "README.md"))
version "1.0.0"
+depends "systemd"
end
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]"
+ systemd_service "squid" do
+ description "Squid caching proxy"
+ after ["network.target", "nss-lookup.target"]
+ limit_nofile 65536
+ environment "SQUID_ARGS" => "-D"
+ environment_file "/etc/default/squid"
+ exec_start_pre "/usr/sbin/squid $SQUID_ARGS -z"
+ exec_start "/usr/sbin/squid -N $SQUID_ARGS"
+ exec_reload "/usr/sbin/squid -k reconfigure"
+ exec_stop "/usr/sbin/squid -k shutdown"
+ restart "on-failure"
+ timeout_sec 0
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 :restart, "systemd_service[squid]"
subscribes :reload, "template[/etc/squid/squid.conf]"
subscribes :restart, "template[/etc/default/squid]"
subscribes :reload, "template[/etc/resolv.conf]"
+++ /dev/null
-[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
--- /dev/null
+# Systemd Cookbook
+
+This cookbook provides lightweight resources to manage systemd units.
--- /dev/null
+name "systemd"
+maintainer "OpenStreetMap Administrators"
+maintainer_email "admins@openstreetmap.org"
+license "Apache 2.0"
+description "Installs and configures systemd units"
+long_description IO.read(File.join(File.dirname(__FILE__), "README.md"))
+version "1.0.0"
--- /dev/null
+#
+# Cookbook Name:: systemd
+# Resource:: systemd_service
+#
+# Copyright 2016, OpenStreetMap Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+default_action :create
+
+property :name, String
+property :description, String, :required => true
+property :after, [String, Array]
+property :type, String,
+ :default => "simple",
+ :is => %w(simple forking oneshot dbus notify idle)
+property :limit_nofile, Fixnum
+property :environment, Hash, :default => {}
+property :environment_file, String
+property :exec_start_pre, String
+property :exec_start, String, :required => true
+property :exec_start_post, String
+property :exec_stop, String
+property :exec_reload, String
+property :restart, String,
+ :is => %w(on-success on-failure on-abnormal on-watchdog on-abort always)
+property :timeout_sec, Fixnum
+
+action :create do
+ template "/etc/systemd/system/#{name}.service" do
+ cookbook "systemd"
+ source "service.erb"
+ owner "root"
+ group "root"
+ mode 0644
+ variables new_resource.to_hash
+ end
+
+ execute "systemctl-reload-#{name}.service" do
+ action :nothing
+ command "systemctl daemon-reload"
+ user "root"
+ group "root"
+ subscribes :run, "template[/etc/systemd/system/#{name}.service]"
+ end
+end
+
+action :delete do
+ file "/etc/systemd/system/#{name}.service" do
+ action :delete
+ end
+
+ execute "systemctl-reload-#{name}.service" do
+ action :nothing
+ command "systemctl daemon-reload"
+ user "root"
+ group "root"
+ subscribes :run, "file[/etc/systemd/system/#{name}.service]"
+ end
+end
--- /dev/null
+[Unit]
+Description=<%= @description %>
+<% if @after -%>
+After=<%= Array(@after).join(" ") %>
+<% end -%>
+
+[Service]
+Type=<%= @type %>
+<% if @limit_nofile -%>
+LimitNOFILE=<%= @limit_nofile %>
+<% end -%>
+<% @environment.each do |name,value| -%>
+Environment="<%= name %>=<%= value %>"
+<% end -%>
+<% if @environment_file -%>
+EnvironmentFile=<%= @environment_file %>
+<% end -%>
+<% if @exec_start_pre -%>
+ExecStartPre=<%= @exec_start_pre %>
+<% end -%>
+ExecStart=<%= @exec_start %>
+<% if @exec_start_post -%>
+ExecStartPost=<%= @exec_start_post %>
+<% end -%>
+<% if @exec_stop -%>
+ExecStop=<%= @exec_stop %>
+<% end -%>
+<% if @exec_reload -%>
+ExecReload=<%= @exec_reload %>
+<% end -%>
+<% if @restart -%>
+Restart=<%= @restart %>
+<% end -%>
+<% if @timeout_sec -%>
+TimeoutSec=<%= @timeout_sec %>
+<% end -%>
+
+[Install]
+WantedBy=multi-user.target