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 adb0edc..29f75e3 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][:instance_registry_dir] = "/run/passenger"
 
 default[:apt][:sources] = node[:apt][:sources] | ["passenger"]
index 07bc075..8857043 100644 (file)
@@ -35,10 +35,21 @@ template "/usr/local/bin/passenger-ruby" do
   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
 
+munin_plugin_conf "passenger" do
+  template "munin.erb"
+end
+
 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 f203066..f15bc0f 100644 (file)
@@ -7,4 +7,5 @@
   PassengerMaxPoolSize <%= node[:passenger][:max_pool_size] %>
   PassengerPoolIdleTime <%= node[:passenger][:pool_idle_time] %>
   PassengerFriendlyErrorPages off
+  PassengerInstanceRegistryDir /run/passenger
 </IfModule>
index 652a53a..805129e 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
 
-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
index 8da12cc..ca3fd8c 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}]"
+    notifies :restart, "passenger_application[#{rails_directory}]"
   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
-    notifies :run, "execute[#{rails_directory}]"
+    notifies :restart, "passenger_application[#{rails_directory}]"
   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}]"
-    notifies :run, "execute[#{rails_directory}]"
+    notifies :restart, "passenger_application[#{rails_directory}]"
   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}]"
-    notifies :run, "execute[#{rails_directory}]"
+    notifies :restart, "passenger_application[#{rails_directory}]"
     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
-    notifies :run, "execute[#{rails_directory}]"
+    notifies :restart, "passenger_application[#{rails_directory}]"
   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"
@@ -353,11 +347,8 @@ action :create 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
 
index 850e380..b0028af 100644 (file)
@@ -11,7 +11,7 @@
   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 -%>
index 086c413..d3cef76 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
-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.$$)