diff options
author | James Healy <james@yob.id.au> | 2016-05-19 14:02:13 +1000 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2016-08-09 11:22:29 -0500 |
commit | 9fcf54edea0370da23e7d84d135ea7a4d47024b9 (patch) | |
tree | 2262cbd961faac4ea3fed335033f96102715f758 | |
parent | 114d42b4591f18bffac0af1b87f5bc37a41d81e6 (diff) | |
download | bundler-9fcf54edea0370da23e7d84d135ea7a4d47024b9.tar.gz |
Manually set a process title when using load
With bundler 1.11.2, the process name for rake tasks looked like this:
$ bundle exec rake foo:bar
$ ps ux | grep rake
user 1758 62.2 2.4 385816 202032 pts/3 Sl+ 16:16 0:04 ruby /usr/bin/rake foo:bar
On bundler 1.12.0, the process name changed:
$ bundle exec rake foo:bar
$ ps ux | grep rake
user 1758 62.2 2.4 385816 202032 pts/3 Sl+ 16:16 0:04 /usr/bin/rake
The change in behaviour is caused by bundler 1.12 using `load` (instead of `exec`) where
possible, and manually using `$0=` to set the command name. Unfortunately, that also alters
the process title visible with ps, and using Process.setproctitle can help reverse that
-rw-r--r-- | lib/bundler/cli/exec.rb | 9 | ||||
-rw-r--r-- | spec/commands/exec_spec.rb | 6 |
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index f0ce450959..b02a610c21 100644 --- a/lib/bundler/cli/exec.rb +++ b/lib/bundler/cli/exec.rb @@ -63,6 +63,7 @@ module Bundler args.pop if args.last.is_a?(Hash) ARGV.replace(args) $0 = file + Process.setproctitle(process_title(file, *args)) ui = Bundler.ui Bundler.ui = nil require "bundler/setup" @@ -78,6 +79,14 @@ module Bundler abort "#{e.class}: #{e.message}\n #{backtrace.join("\n ")}" end + def process_title(file, *args) + if args.empty? + file + else + "#{file} #{args.join(" ")}".strip + end + end + def ruby_shebang?(file) possibilities = [ "#!/usr/bin/env ruby\n", diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index 4e2bdbbb7a..e2283d7aa4 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -462,6 +462,7 @@ describe "bundle exec" do puts "EXEC: \#{caller.grep(/load/).empty? ? 'exec' : 'load'}" puts "ARGS: \#{$0} \#{ARGV.join(' ')}" puts "RACK: \#{RACK}" + puts "PROCESS: \#{`ps --no-headers -oargs -p\#{Process.pid}`.strip}" RUBY before do @@ -476,8 +477,9 @@ describe "bundle exec" do let(:exec) { "EXEC: load" } let(:args) { "ARGS: #{path} arg1 arg2" } let(:rack) { "RACK: 1.0.0" } + let(:process) { "PROCESS: #{path} arg1 arg2" } let(:exit_code) { 0 } - let(:expected) { [exec, args, rack].join("\n") } + let(:expected) { [exec, args, rack, process].join("\n") } let(:expected_err) { "" } subject { bundle "exec #{path} arg1 arg2" } @@ -511,7 +513,7 @@ describe "bundle exec" do let(:exit_code) { 1 } let(:expected) { super() << "\nbundler: failed to load command: #{path} (#{path})" } let(:expected_err) do - "RuntimeError: ERROR\n #{path}:7" + + "RuntimeError: ERROR\n #{path}:8" + (Bundler.current_ruby.ruby_18? ? "" : ":in `<top (required)>'") end it_behaves_like "it runs" |