/usr/share/passenger/helper-scripts/rack-loader.rb is in ruby-passenger 4.0.53-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | #!/usr/bin/env ruby
# encoding: binary
# Phusion Passenger - https://www.phusionpassenger.com/
# Copyright (c) 2013-2014 Phusion
#
# "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
module PhusionPassenger
module App
def self.options
return @@options
end
def self.app
return @@app
end
def self.format_exception(e)
result = "#{e} (#{e.class})"
if !e.backtrace.empty?
if e.respond_to?(:html?) && e.html?
require 'erb' if !defined?(ERB)
result << "\n<pre> " << ERB::Util.h(e.backtrace.join("\n ")) << "</pre>"
else
result << "\n " << e.backtrace.join("\n ")
end
end
return result
end
def self.exit_code_for_exception(e)
if e.is_a?(SystemExit)
return e.status
else
return 1
end
end
def self.handshake_and_read_startup_request
STDOUT.sync = true
STDERR.sync = true
puts "!> I have control 1.0"
abort "Invalid initialization header" if STDIN.readline != "You have control 1.0\n"
@@options = {}
while (line = STDIN.readline) != "\n"
name, value = line.strip.split(/: */, 2)
@@options[name] = value
end
end
def self.init_passenger
require "#{options["ruby_libdir"]}/phusion_passenger"
PhusionPassenger.locate_directories(options["passenger_root"])
PhusionPassenger.require_passenger_lib 'native_support'
PhusionPassenger.require_passenger_lib 'ruby_core_enhancements'
PhusionPassenger.require_passenger_lib 'utils/tmpdir'
PhusionPassenger.require_passenger_lib 'loader_shared_helpers'
PhusionPassenger.require_passenger_lib 'request_handler'
PhusionPassenger.require_passenger_lib 'rack/thread_handler_extension'
@@options = LoaderSharedHelpers.init(@@options)
Utils.passenger_tmpdir = options["generation_dir"]
if defined?(NativeSupport)
NativeSupport.disable_stdio_buffering
end
RequestHandler::ThreadHandler.send(:include, Rack::ThreadHandlerExtension)
rescue Exception => e
LoaderSharedHelpers.about_to_abort(e) if defined?(LoaderSharedHelpers)
puts "!> Error"
puts "!> html: true" if e.respond_to?(:html?) && e.html?
puts "!> "
puts format_exception(e)
exit exit_code_for_exception(e)
end
def self.load_app
LoaderSharedHelpers.before_loading_app_code_step1('config.ru', options)
LoaderSharedHelpers.run_load_path_setup_code(options)
LoaderSharedHelpers.before_loading_app_code_step2(options)
begin
require 'rubygems'
rescue LoadError
end
require 'rack'
rackup_file = options["startup_file"] || "config.ru"
rackup_code = ::File.open(rackup_file, 'rb') do |f|
f.read
end
@@app = eval("Rack::Builder.new {( #{rackup_code}\n )}.to_app",
TOPLEVEL_BINDING, rackup_file)
LoaderSharedHelpers.after_loading_app_code(options)
rescue Exception => e
LoaderSharedHelpers.about_to_abort(e)
puts "!> Error"
puts "!> html: true" if e.respond_to?(:html?) && e.html?
puts "!> "
puts format_exception(e)
exit exit_code_for_exception(e)
end
################## Main code ##################
handshake_and_read_startup_request
init_passenger
load_app
LoaderSharedHelpers.before_handling_requests(false, options)
handler = RequestHandler.new(STDIN, options.merge("app" => app))
LoaderSharedHelpers.advertise_readiness
LoaderSharedHelpers.advertise_sockets(STDOUT, handler)
puts "!> "
handler.main_loop
handler.cleanup
LoaderSharedHelpers.after_handling_requests
end # module App
end # module PhusionPassenger
|