version "1.0.0"
depends "nginx"
depends "git"
+depends "systemd"
action [:delete]
restart_nginx false
end
+
+systemd_tmpfile "/run/mapserver-fastcgi" do
+ type "d"
+ owner "imagery"
+ group "imagery"
+ mode "0755"
+end
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
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
+++ /dev/null
-# 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
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
--- /dev/null
+#
+# 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
+# DO NOT EDIT - This file is being maintained by Chef
+
[Unit]
Description=<%= @description %>
<% if @after -%>
<% 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 -%>
--- /dev/null
+# DO NOT EDIT - This file is being maintained by Chef
+
+<%= @type %> <%= @path %> <%= @mode %> <%= @owner %> <%= @group %> <%= @age %> <%= @argument %>