diff --git a/CHANGELOG b/CHANGELOG index 6016cf0450..c562dc737f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,7 @@ Release 6.0.25 (Not yet released) ------------- * [Standalone] Changes Passenger (not app) start and stop timeouts to 25s (from 15s) except for Nginx engine mode, which retains a stop timeout of 60s. - * + * [Ruby] Fixes an issue where Bundler would try to re-exec the process name instead of the script. Closes GH-2567 and GH-2577. Release 6.0.24 diff --git a/src/helper-scripts/meteor-loader.rb b/src/helper-scripts/meteor-loader.rb index 67ee524514..83c08b9e24 100755 --- a/src/helper-scripts/meteor-loader.rb +++ b/src/helper-scripts/meteor-loader.rb @@ -183,8 +183,13 @@ def self.load_app end exec("meteor run -p #{port} #{production} --settings settings.json") end - $0 = options["process_title"] if options["process_title"] - $0 = "#{$0} (#{pid})" + + if options["process_title"] && !options["process_title"].empty? + rename_process "#{options["process_title"]} (#{pid})" + else + rename_process "#{$0} (#{pid})" + end + return [pid, port] end diff --git a/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb b/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb index 3281441c93..11bafc1d59 100644 --- a/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb +++ b/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb @@ -304,9 +304,9 @@ def before_handling_requests(forked, options) end if options["process_title"] && !options["process_title"].empty? - $0 = options["process_title"] + ": " + options["app_group_name"] + rename_process "#{options["process_title"]}: #{options["app_group_name"]}" else - $0 = "Passenger App: " + options["app_group_name"] + rename_process "Passenger App: #{options["app_group_name"]}" end # If we were forked from a preloader process then clear or @@ -541,6 +541,14 @@ def dump_envvars try_write_file("#{dir}/envvars", ENV.to_a.map { |k, v| "#{k} = #{v}" }.join("\n")) end + def rename_process(name) + if Process.respond_to?(:setproctitle) + Process.setproctitle(name) + else + $0 = name + end + end + private def running_bundler(options) yield diff --git a/src/ruby_supportlib/phusion_passenger/preloader_shared_helpers.rb b/src/ruby_supportlib/phusion_passenger/preloader_shared_helpers.rb index 559fcd2532..62356c8015 100644 --- a/src/ruby_supportlib/phusion_passenger/preloader_shared_helpers.rb +++ b/src/ruby_supportlib/phusion_passenger/preloader_shared_helpers.rb @@ -37,7 +37,7 @@ module PreloaderSharedHelpers def init(main_app) options = LoaderSharedHelpers.init(main_app) - $0 = "#{SHORT_PROGRAM_NAME} AppPreloader: #{options['app_root']}" + LoaderSharedHelpers.rename_process pre_name(options) if !Kernel.respond_to?(:fork) message = "Smart spawning is not available on this Ruby " + @@ -56,7 +56,7 @@ def init(main_app) options end - def accept_and_process_next_client(server_socket) + def accept_and_process_next_client(server_socket, options) client = server_socket.accept client.binmode begin @@ -75,7 +75,7 @@ def accept_and_process_next_client(server_socket) end if doc['command'] == 'spawn' - handle_spawn_command(client, doc) + handle_spawn_command(client, doc, options) else client.write(Utils::JSON.generate( :result => 'error', @@ -94,7 +94,7 @@ def accept_and_process_next_client(server_socket) end end - def handle_spawn_command(client, doc) + def handle_spawn_command(client, doc, options) work_dir = doc['work_dir'] LoaderSharedHelpers.record_journey_step_end('PRELOADER_PREPARATION', 'STEP_PERFORMED', work_dir) @@ -114,7 +114,7 @@ def handle_spawn_command(client, doc) if pid.nil? begin - $0 = "#{$0} (forking...)" + LoaderSharedHelpers.rename_process "#{pre_name(options)} (forking...)" LoaderSharedHelpers.record_journey_step_end('PRELOADER_FORK_SUBPROCESS', 'STEP_PERFORMED', work_dir) LoaderSharedHelpers.run_block_and_record_step_progress('PRELOADER_SEND_RESPONSE', work_dir) do @@ -164,7 +164,7 @@ def run_main_loop(server, options) # https://code.google.com/p/phusion-passenger/issues/detail?id=915 ios = Kernel.select([server_socket, STDIN])[0] if ios.include?(server_socket) - result, subprocess_work_dir = accept_and_process_next_client(server_socket) + result, subprocess_work_dir = accept_and_process_next_client(server_socket, options) if result == :forked return subprocess_work_dir end @@ -188,6 +188,12 @@ def run_main_loop(server, options) File.unlink(socket_filename) rescue nil end end + + private + def pre_name(options) + "#{SHORT_PROGRAM_NAME} AppPreloader: #{options['app_root']}" + end + end end # module PhusionPassenger