Skip to content

Commit

Permalink
use Process.setproctitle to avoid bundler bug
Browse files Browse the repository at this point in the history
  • Loading branch information
CamJN committed Dec 19, 2024
1 parent c7599c4 commit 2dcd8f0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/helper-scripts/meteor-loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions src/ruby_supportlib/phusion_passenger/preloader_shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 " +
Expand All @@ -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
Expand All @@ -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',
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit 2dcd8f0

Please sign in to comment.