]> git.openstreetmap.org Git - chef.git/commitdiff
Move passenger instance registry to /run/passenger
authorTom Hughes <tom@compton.nu>
Sun, 1 Jul 2018 20:52:48 +0000 (21:52 +0100)
committerTom Hughes <tom@compton.nu>
Sun, 1 Jul 2018 21:34:09 +0000 (22:34 +0100)
This avoids problems on 18.04 where apache2 defaults to a private
temporary directory stopping the passenger registry being found.

cookbooks/passenger/attributes/default.rb
cookbooks/passenger/recipes/default.rb
cookbooks/passenger/resources/application.rb [new file with mode: 0644]
cookbooks/passenger/templates/default/munin.erb [new file with mode: 0644]
cookbooks/passenger/templates/default/passenger.conf.erb
cookbooks/taginfo/templates/default/update-taginfo.erb
cookbooks/web/resources/rails_port.rb
cookbooks/web/templates/default/logrotate.web.erb
cookbooks/web/templates/default/passenger.cron.erb

index adb0edc081e3155bb5293566cc6554d21b4f42ca..29f75e3aee6ebdeee9cbe0be58d140e1675b1273 100644 (file)
@@ -1,5 +1,6 @@
 default[:passenger][:ruby_version] = node[:lsb][:release].to_f >= 18.04 ? "2.5" : "2.3"
 default[:passenger][:max_pool_size] = 6
 default[:passenger][:pool_idle_time] = 300
 default[:passenger][:ruby_version] = node[:lsb][:release].to_f >= 18.04 ? "2.5" : "2.3"
 default[:passenger][:max_pool_size] = 6
 default[:passenger][:pool_idle_time] = 300
+default[:passenger][:instance_registry_dir] = "/run/passenger"
 
 default[:apt][:sources] = node[:apt][:sources] | ["passenger"]
 
 default[:apt][:sources] = node[:apt][:sources] | ["passenger"]
index 07bc0750a02d4f272e0e8fe565f6bf263a9e70f6..88570434f8984b90529df1ac14c2fe48c3e6b0f5 100644 (file)
@@ -35,10 +35,21 @@ template "/usr/local/bin/passenger-ruby" do
   notifies :reload, "service[apache2]"
 end
 
   notifies :reload, "service[apache2]"
 end
 
+systemd_tmpfile node[:passenger][:instance_registry_dir] do
+  type "d"
+  owner "root"
+  group "root"
+  mode "0755"
+end
+
 apache_module "passenger" do
   conf "passenger.conf.erb"
 end
 
 apache_module "passenger" do
   conf "passenger.conf.erb"
 end
 
+munin_plugin_conf "passenger" do
+  template "munin.erb"
+end
+
 munin_plugin "passenger_memory"
 munin_plugin "passenger_processes"
 munin_plugin "passenger_queues"
 munin_plugin "passenger_memory"
 munin_plugin "passenger_processes"
 munin_plugin "passenger_queues"
diff --git a/cookbooks/passenger/resources/application.rb b/cookbooks/passenger/resources/application.rb
new file mode 100644 (file)
index 0000000..c0acc4b
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# Cookbook Name:: passenger
+# Resource:: application
+#
+# Copyright 2018, 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
+#
+#     https://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 :nothing
+
+property :application, String, :name_attribute => true
+
+action :restart do
+  execute new_resource.application do
+    action :run
+    command "passenger-config restart-app --ignore-app-not-running --ignore-passenger-not-running #{new_resource.application}"
+    environment "PASSENGER_INSTANCE_REGISTRY_DIR" => node[:passenger][:instance_registry_dir]
+    user "root"
+    group "root"
+  end
+end
diff --git a/cookbooks/passenger/templates/default/munin.erb b/cookbooks/passenger/templates/default/munin.erb
new file mode 100644 (file)
index 0000000..903fcfe
--- /dev/null
@@ -0,0 +1,5 @@
+# DO NOT EDIT - This file is being maintained by Chef
+
+[passenger_*]
+user root
+env.PASSENGER_INSTANCE_REGISTRY_DIR <%= node[:passenger][:instance_registry_dir] %>
index f2030660cd39d6907bb0348e48fd93c4869eda5e..f15bc0fe915b5223c753519049d5d6705169b1e2 100644 (file)
@@ -7,4 +7,5 @@
   PassengerMaxPoolSize <%= node[:passenger][:max_pool_size] %>
   PassengerPoolIdleTime <%= node[:passenger][:pool_idle_time] %>
   PassengerFriendlyErrorPages off
   PassengerMaxPoolSize <%= node[:passenger][:max_pool_size] %>
   PassengerPoolIdleTime <%= node[:passenger][:pool_idle_time] %>
   PassengerFriendlyErrorPages off
+  PassengerInstanceRegistryDir /run/passenger
 </IfModule>
 </IfModule>
index 652a53a67c3462ab4e0e9cc477192993a4324cd6..805129e05fbebac1a7cefd5e24cbe44a8923562d 100644 (file)
@@ -19,6 +19,6 @@ mv $ROOT/data/taginfo-* $ROOT/data/old
 mv $ROOT/sources/taginfo-*.db $ROOT/sources/*/taginfo-*.db $ROOT/data
 mv $ROOT/sources/download/* $ROOT/download
 
 mv $ROOT/sources/taginfo-*.db $ROOT/sources/*/taginfo-*.db $ROOT/data
 mv $ROOT/sources/download/* $ROOT/download
 
-sudo /usr/bin/passenger-config restart-app $ROOT/taginfo/web > /dev/null
+sudo PASSENGER_INSTANCE_REGISTRY_DIR=<%= node[:passenger][:instance_registry_dir] %> /usr/bin/passenger-config restart-app $ROOT/taginfo/web > /dev/null
 
 find $ROOT/sources/log -mtime +28 -delete
 
 find $ROOT/sources/log -mtime +28 -delete
index 8da12cc53790319cfe2b8bb05cb9e83f832b31c9..ca3fd8c065c18cdd6aaddea6033ce8507ff79a42 100644 (file)
@@ -127,7 +127,7 @@ action :create do
     notifies :run, "execute[#{rails_directory}/Gemfile]"
     notifies :run, "execute[#{rails_directory}/public/assets]"
     notifies :delete, "file[#{rails_directory}/public/export/embed.html]"
     notifies :run, "execute[#{rails_directory}/Gemfile]"
     notifies :run, "execute[#{rails_directory}/public/assets]"
     notifies :delete, "file[#{rails_directory}/public/export/embed.html]"
-    notifies :run, "execute[#{rails_directory}]"
+    notifies :restart, "passenger_application[#{rails_directory}]"
   end
 
   declare_resource :directory, "#{rails_directory}/tmp" do
   end
 
   declare_resource :directory, "#{rails_directory}/tmp" do
@@ -151,7 +151,7 @@ action :create do
               :name => new_resource.database_name,
               :username => new_resource.database_username,
               :password => new_resource.database_password
               :name => new_resource.database_name,
               :username => new_resource.database_username,
               :password => new_resource.database_password
-    notifies :run, "execute[#{rails_directory}]"
+    notifies :restart, "passenger_application[#{rails_directory}]"
   end
 
   application_yml = edit_file "#{rails_directory}/config/example.application.yml" do |line|
   end
 
   application_yml = edit_file "#{rails_directory}/config/example.application.yml" do |line|
@@ -306,7 +306,7 @@ action :create do
     group "root"
     environment "NOKOGIRI_USE_SYSTEM_LIBRARIES" => "yes"
     subscribes :run, "gem_package[bundler#{new_resource.ruby}]"
     group "root"
     environment "NOKOGIRI_USE_SYSTEM_LIBRARIES" => "yes"
     subscribes :run, "gem_package[bundler#{new_resource.ruby}]"
-    notifies :run, "execute[#{rails_directory}]"
+    notifies :restart, "passenger_application[#{rails_directory}]"
   end
 
   execute "#{rails_directory}/db/migrate" do
   end
 
   execute "#{rails_directory}/db/migrate" do
@@ -316,7 +316,7 @@ action :create do
     user new_resource.user
     group new_resource.group
     subscribes :run, "git[#{rails_directory}]"
     user new_resource.user
     group new_resource.group
     subscribes :run, "git[#{rails_directory}]"
-    notifies :run, "execute[#{rails_directory}]"
+    notifies :restart, "passenger_application[#{rails_directory}]"
     only_if { new_resource.run_migrations }
   end
 
     only_if { new_resource.run_migrations }
   end
 
@@ -327,20 +327,14 @@ action :create do
     cwd rails_directory
     user new_resource.user
     group new_resource.group
     cwd rails_directory
     user new_resource.user
     group new_resource.group
-    notifies :run, "execute[#{rails_directory}]"
+    notifies :restart, "passenger_application[#{rails_directory}]"
   end
 
   file "#{rails_directory}/public/export/embed.html" do
     action :nothing
   end
 
   end
 
   file "#{rails_directory}/public/export/embed.html" do
     action :nothing
   end
 
-  execute rails_directory do
-    action :nothing
-    command "passenger-config restart-app --ignore-app-not-running --ignore-passenger-not-running #{rails_directory}"
-    user "root"
-    group "root"
-    only_if { ::File.exist?("/usr/bin/passenger-config") }
-  end
+  passenger_application rails_directory
 
   template "/etc/cron.daily/rails-#{new_resource.site.tr('.', '-')}" do
     cookbook "web"
 
   template "/etc/cron.daily/rails-#{new_resource.site.tr('.', '-')}" do
     cookbook "web"
@@ -353,11 +347,8 @@ action :create do
 end
 
 action :restart do
 end
 
 action :restart do
-  execute rails_directory do
-    action :run
-    command "passenger-config restart-app --ignore-app-not-running --ignore-passenger-not-running #{rails_directory}"
-    user "root"
-    group "root"
+  passenger_application rails_directory do
+    action :restart
   end
 end
 
   end
 end
 
index 850e3805926ac92dfc9cf57ac47932bb494c9e07..b0028af87d90318f976b13effa1b7ae6234658e5 100644 (file)
@@ -11,7 +11,7 @@
   sharedscripts
   postrotate
 <% if File.directory?("#{node[:web][:base_directory]}/rails") -%>
   sharedscripts
   postrotate
 <% if File.directory?("#{node[:web][:base_directory]}/rails") -%>
-    /usr/bin/passenger-config restart-app --ignore-app-not-running <%= node[:web][:base_directory] %>/rails > /dev/null
+    PASSENGER_INSTANCE_REGISTRY_DIR=<%= node[:passenger][:instance_registry_dir] %> /usr/bin/passenger-config restart-app --ignore-app-not-running <%= node[:web][:base_directory] %>/rails > /dev/null
 <% if node[:recipes].include?("logstash::forwarder") -%>
     /etc/init.d/logstash-forwarder restart > /dev/null
 <% end -%>
 <% if node[:recipes].include?("logstash::forwarder") -%>
     /etc/init.d/logstash-forwarder restart > /dev/null
 <% end -%>
index 086c41366048e073cf46ab99f57ed04825541255..d3cef76ee4c1c7591b50d7aa9eddd01b6ee05ae8 100644 (file)
@@ -4,7 +4,7 @@
 pgrep -u rails -f Rack | sort > /tmp/rails.actual.$$
 
 # Get a list of rack processes we expect to be running
 pgrep -u rails -f Rack | sort > /tmp/rails.actual.$$
 
 # Get a list of rack processes we expect to be running
-passenger-status | awk '/PID:/ { print $3 }' | sort > /tmp/rails.expected.$$
+PASSENGER_INSTANCE_REGISTRY_DIR=<%= node[:passenger][:instance_registry_dir] %> passenger-status | awk '/PID:/ { print $3 }' | sort > /tmp/rails.expected.$$
 
 # Get a list of unexpected rack processes
 pids=$(comm -23 /tmp/rails.actual.$$ /tmp/rails.expected.$$)
 
 # Get a list of unexpected rack processes
 pids=$(comm -23 /tmp/rails.actual.$$ /tmp/rails.expected.$$)