From: Tom Hughes Date: Sun, 29 May 2016 14:44:43 +0000 (+0100) Subject: Update imagery cookbook for Ubuntu 16.04 X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/9f13c244211f5683f232f7cc32fac53be8d0b3ec Update imagery cookbook for Ubuntu 16.04 --- diff --git a/cookbooks/imagery/metadata.rb b/cookbooks/imagery/metadata.rb index 07dd39838..5df29639d 100644 --- a/cookbooks/imagery/metadata.rb +++ b/cookbooks/imagery/metadata.rb @@ -7,3 +7,4 @@ long_description IO.read(File.join(File.dirname(__FILE__), "README.md")) version "1.0.0" depends "nginx" depends "git" +depends "systemd" diff --git a/cookbooks/imagery/recipes/default.rb b/cookbooks/imagery/recipes/default.rb index 809370d4a..d7827173b 100644 --- a/cookbooks/imagery/recipes/default.rb +++ b/cookbooks/imagery/recipes/default.rb @@ -77,3 +77,10 @@ nginx_site "default" do action [:delete] restart_nginx false end + +systemd_tmpfile "/run/mapserver-fastcgi" do + type "d" + owner "imagery" + group "imagery" + mode "0755" +end diff --git a/cookbooks/imagery/resources/layer.rb b/cookbooks/imagery/resources/layer.rb index 340ed0b6c..22509eb57 100644 --- a/cookbooks/imagery/resources/layer.rb +++ b/cookbooks/imagery/resources/layer.rb @@ -47,21 +47,23 @@ action :create do variables new_resource.to_hash end - template "/etc/init/mapserv-fcgi-layer-#{layer}.conf" do - cookbook "imagery" - source "mapserv_fcgi.conf.erb" - owner "root" - group "root" - mode 0644 - variables new_resource.to_hash + systemd_service "mapserv-fcgi-#{layer}" do + description "Map server for #{layer} layer" + limit_nofile 16384 + environment "MS_MAPFILE" => "/srv/imagery/mapserver/layer-#{layer}.map", + "MS_MAP_PATTERN" => "^/srv/imagery/mapserver/", + "MS_ERRORFILE" => "/tmp/mapserver-layer-#{layer}.log", + "MS_DEBUGLEVEL" => "5" + user "imagery" + group "imagery" + exec_start "/usr/bin/spawn-fcgi -n -s /run/mapserver-fastcgi/layer-#{layer}.socket -M 0666 -f /usr/lib/cgi-bin/mapserv" + restart "on-failure" end - service "mapserv-fcgi-layer-#{layer}" do - provider Chef::Provider::Service::Upstart + service "mapserv-fcgi-#{layer}" do action [:enable, :start] - supports :status => true, :restart => true, :reload => false subscribes :restart, "template[/srv/imagery/mapserver/layer-#{layer}.map]" - subscribes :restart, "template[/etc/init/mapserv-fcgi-layer-#{layer}.conf]" + subscribes :restart, "systemd_service[mapserv-fcgi]" end directory "/srv/imagery/nginx/#{site}" do @@ -83,16 +85,14 @@ end action :delete do service "mapserv-fcgi-layer-#{layer}" do - provider Chef::Provider::Service::Upstart action [:stop, :disable] - supports :status => true, :restart => true, :reload => false end file "/srv/imagery/mapserver/layer-#{layer}.map" do action :delete end - file "/etc/init/mapserv-fcgi-layer-#{layer}.conf" do + systemd_service "mapserv-fcgi-#{layer}" do action :delete end diff --git a/cookbooks/imagery/templates/default/mapserv_fcgi.conf.erb b/cookbooks/imagery/templates/default/mapserv_fcgi.conf.erb deleted file mode 100644 index 5615d3c00..000000000 --- a/cookbooks/imagery/templates/default/mapserv_fcgi.conf.erb +++ /dev/null @@ -1,33 +0,0 @@ -# DO NOT EDIT - This file is being maintained by Chef - -description "starts mapserver in daemon mode for fastcgi" - -start on (net-device-up - and local-filesystems - and runlevel [2345]) -stop on runlevel [!2345] - -respawn - -limit nofile 16384 16384 - -# https://trac.osgeo.org/mapserver/wiki/EnvironmentVariables -env MS_MAPFILE="/srv/imagery/mapserver/layer-<%= @layer %>.map" -env MS_MAP_PATTERN="^/srv/imagery/mapserver/" -env MS_ERRORFILE="/tmp/mapserver-layer-<%= @layer %>.log" -env MS_DEBUGLEVEL="5" - -pre-start script - mkdir -p -m 0775 /var/run/mapserver-fastcgi - chown imagery:imagery /var/run/mapserver-fastcgi -end script - -script - exec /usr/bin/spawn-fcgi \ - -n \ - -u imagery \ - -g imagery \ - -s /var/run/mapserver-fastcgi/layer-<%= @layer %>.socket \ - -M 0666 \ - -f /usr/lib/cgi-bin/mapserv -end script diff --git a/cookbooks/systemd/resources/service.rb b/cookbooks/systemd/resources/service.rb index e6fba41b5..8ef7dcdbb 100644 --- a/cookbooks/systemd/resources/service.rb +++ b/cookbooks/systemd/resources/service.rb @@ -28,6 +28,8 @@ property :type, String, property :limit_nofile, Fixnum property :environment, Hash, :default => {} property :environment_file, String +property :user, String +property :group, String property :exec_start_pre, String property :exec_start, String, :required => true property :exec_start_post, String diff --git a/cookbooks/systemd/resources/tmpfile.rb b/cookbooks/systemd/resources/tmpfile.rb new file mode 100644 index 000000000..8bf64ae09 --- /dev/null +++ b/cookbooks/systemd/resources/tmpfile.rb @@ -0,0 +1,57 @@ +# +# Cookbook Name:: systemd +# Resource:: systemd_tmpfile +# +# 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 :type, String, :required => true +property :path, String, :name_property => true +property :mode, String, :default => "-" +property :owner, String, :default => "-" +property :group, String, :default => "-" +property :age, String, :default => "-" +property :argument, String, :default => "-" + +action :create do + template "/etc/tmpfiles.d/#{unit_name}.conf" do + cookbook "systemd" + source "tmpfile.erb" + owner "root" + group "root" + mode 0644 + variables new_resource.to_hash + end + + execute "systemd-tmpfiles" do + action :nothing + command "systemd-tmpfiles --create /etc/tmpfiles.d/#{unit_name}.conf" + user "root" + group "root" + subscribes :run, "template[/etc/tmpfiles.d/#{unit_name}.conf]" + end +end + +action :delete do + file "/etc/tmpfiles.d/#{unit_name}.conf" do + action :delete + end +end + +def unit_name + path.sub(%r{^/}, "").gsub(%r{/}, "-") +end diff --git a/cookbooks/systemd/templates/default/service.erb b/cookbooks/systemd/templates/default/service.erb index 13983b02b..ffac55396 100644 --- a/cookbooks/systemd/templates/default/service.erb +++ b/cookbooks/systemd/templates/default/service.erb @@ -1,3 +1,5 @@ +# DO NOT EDIT - This file is being maintained by Chef + [Unit] Description=<%= @description %> <% if @after -%> @@ -15,6 +17,12 @@ Environment="<%= name %>=<%= value %>" <% if @environment_file -%> EnvironmentFile=<%= @environment_file %> <% end -%> +<% if @user -%> +User=<%= @user %> +<% end -%> +<% if @group -%> +Group=<%= @group %> +<% end -%> <% if @exec_start_pre -%> ExecStartPre=<%= @exec_start_pre %> <% end -%> diff --git a/cookbooks/systemd/templates/default/tmpfile.erb b/cookbooks/systemd/templates/default/tmpfile.erb new file mode 100644 index 000000000..90829dd6d --- /dev/null +++ b/cookbooks/systemd/templates/default/tmpfile.erb @@ -0,0 +1,3 @@ +# DO NOT EDIT - This file is being maintained by Chef + +<%= @type %> <%= @path %> <%= @mode %> <%= @owner %> <%= @group %> <%= @age %> <%= @argument %>