#! /bin/bash # Author: gilbertas matusevicius, 2015 # This script fix rack gem issue with "too many open files" error # http://trac.kolmisoft.com/trac/ticket/11601 # http://stackoverflow.com/questions/27773368/rails-4-2-internal-server-error-with-maximum-file-multiparts-in-content-reached . /usr/src/k_framework/main.sh SCRIPT_NAME="Rack fix" VERSION="1.1.2" k_start k_config_details if [[ $ROCKY9 == 1 ]]; then report "Only for Centos with old Rack" 3 k_exit 0 fi source "/usr/local/rvm/scripts/rvm" > /dev/null RUBY_VER="2.2.2" cd /home/$SYSTEM_CONFIG_DIR gem_path=$(rvm ruby-"$RUBY_VER" do bundle show rack 2>/dev/null) if [ $(echo $gem_path | grep rack | wc -l) -lt 1 ]; then report "Rack path not found. Aborting" 1 k_exit 1 fi file_path="${gem_path}/lib/rack/utils.rb" if [ ! -f $file_path ];then report "Could not find file ${file_path}. Aborting" 1 k_exit 1 fi # offending line looks like this # self.multipart_part_limit = (ENV['RACK_MULTIPART_PART_LIMIT'] || 128).to_i # We will change this to this one # self.multipart_part_limit = 0 #Check if fix was already applied if grep -Fq 'self.multipart_part_limit = 0' $file_path; then report "Rack fix was already applied" 0 k_exit 0 fi #Fix offending line sed -i 's/\(self.multipart_part_limit\) \= (ENV.*/\1 \= 0/' $file_path #Check if change was applied ok if grep -Fq 'self.multipart_part_limit = 0' $file_path; then report "Rack multipart issue was fixed" 4 else report "Failed to fix rack issue" 3 report "Check line containing self.multipart_part_limit in $file_path" 3; EXIT_CODE=1 fi k_exit $EXIT_CODE