From: Tom Hughes Date: Sun, 1 Jul 2018 20:52:48 +0000 (+0100) Subject: Move passenger instance registry to /run/passenger X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/d6ed0a8d7822828b12aa2c90c6bcc62f780c2fa5 Move passenger instance registry to /run/passenger This avoids problems on 18.04 where apache2 defaults to a private temporary directory stopping the passenger registry being found. --- diff --git a/cookbooks/passenger/attributes/default.rb b/cookbooks/passenger/attributes/default.rb index adb0edc08..29f75e3ae 100644 --- a/cookbooks/passenger/attributes/default.rb +++ b/cookbooks/passenger/attributes/default.rb @@ -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"] diff --git a/cookbooks/passenger/recipes/default.rb b/cookbooks/passenger/recipes/default.rb index 07bc0750a..88570434f 100644 --- a/cookbooks/passenger/recipes/default.rb +++ b/cookbooks/passenger/recipes/default.rb @@ -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 index 000000000..c0acc4b3f --- /dev/null +++ b/cookbooks/passenger/resources/application.rb @@ -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 index 000000000..903fcfe34 --- /dev/null +++ b/cookbooks/passenger/templates/default/munin.erb @@ -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] %> diff --git a/cookbooks/passenger/templates/default/passenger.conf.erb b/cookbooks/passenger/templates/default/passenger.conf.erb index f2030660c..f15bc0fe9 100644 --- a/cookbooks/passenger/templates/default/passenger.conf.erb +++ b/cookbooks/passenger/templates/default/passenger.conf.erb @@ -7,4 +7,5 @@ PassengerMaxPoolSize <%= node[:passenger][:max_pool_size] %> PassengerPoolIdleTime <%= node[:passenger][:pool_idle_time] %> PassengerFriendlyErrorPages off + PassengerInstanceRegistryDir /run/passenger diff --git a/cookbooks/taginfo/templates/default/update-taginfo.erb b/cookbooks/taginfo/templates/default/update-taginfo.erb index 652a53a67..805129e05 100644 --- a/cookbooks/taginfo/templates/default/update-taginfo.erb +++ b/cookbooks/taginfo/templates/default/update-taginfo.erb @@ -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 diff --git a/cookbooks/web/resources/rails_port.rb b/cookbooks/web/resources/rails_port.rb index 8da12cc53..ca3fd8c06 100644 --- a/cookbooks/web/resources/rails_port.rb +++ b/cookbooks/web/resources/rails_port.rb @@ -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 diff --git a/cookbooks/web/templates/default/logrotate.web.erb b/cookbooks/web/templates/default/logrotate.web.erb index 850e38059..b0028af87 100644 --- a/cookbooks/web/templates/default/logrotate.web.erb +++ b/cookbooks/web/templates/default/logrotate.web.erb @@ -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 -%> diff --git a/cookbooks/web/templates/default/passenger.cron.erb b/cookbooks/web/templates/default/passenger.cron.erb index 086c41366..d3cef76ee 100644 --- a/cookbooks/web/templates/default/passenger.cron.erb +++ b/cookbooks/web/templates/default/passenger.cron.erb @@ -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.$$)