diff --git a/recipes/default.rb b/recipes/default.rb index 92025a6fa..a18c6bfb3 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -82,7 +82,7 @@ notifies :restart, 'service[elasticsearch]' end -# Increase open file limits +# Increase open file and memory limits # bash "enable user limits" do user 'root' @@ -94,20 +94,13 @@ not_if { ::File.read("/etc/pam.d/su").match(/^session required pam_limits\.so/) } end -bash "increase limits for the elasticsearch user" do - user 'root' +log "increase limits for the elasticsearch user" - code <<-END.gsub(/^ /, '') - echo '#{node.elasticsearch.fetch(:user, "elasticsearch")} - nofile #{node.elasticsearch[:limits][:nofile]}' >> /etc/security/limits.conf - echo '#{node.elasticsearch.fetch(:user, "elasticsearch")} - memlock #{node.elasticsearch[:limits][:memlock]}' >> /etc/security/limits.conf +file "/etc/security/limits.d/10-elasticsearch.conf" do + content <<-END.gsub(/^ /, '') + #{node.elasticsearch.fetch(:user, "elasticsearch")} - nofile #{node.elasticsearch[:limits][:nofile]} + #{node.elasticsearch.fetch(:user, "elasticsearch")} - memlock #{node.elasticsearch[:limits][:memlock]} END - - not_if do - file = ::File.read("/etc/security/limits.conf") - file.include?("#{node.elasticsearch.fetch(:user, "elasticsearch")} - nofile #{node.elasticsearch[:limits][:nofile]}") \ - && \ - file.include?("#{node.elasticsearch.fetch(:user, "elasticsearch")} - memlock #{node.elasticsearch[:limits][:memlock]}") - end end # Create file with ES environment variables