From 95a1d49e9dd3c73e50c305e826b9eacede8f8727 Mon Sep 17 00:00:00 2001 From: Leonardo Mosquera Date: Thu, 14 Mar 2013 21:07:09 -0300 Subject: [PATCH 1/3] Set FOREMAN_PROCESS_NAME env var for spawned procs This way, processes can identify themselves to metrics logging systems. --- lib/foreman/engine.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/foreman/engine.rb b/lib/foreman/engine.rb index 7463e53..a79a025 100644 --- a/lib/foreman/engine.rb +++ b/lib/foreman/engine.rb @@ -307,6 +307,10 @@ private def name_for(pid) process, index = @running[pid] + name_for_index(process, index) + end + + def name_for_index(process, index) [ @names[process], index.to_s ].compact.join(".") end @@ -355,7 +359,8 @@ private reader, writer = create_pipe begin pid = process.run(:output => writer, :env => { - "PORT" => port_for(process, n).to_s + "PORT" => port_for(process, n).to_s, + "FOREMAN_PROCESS_NAME" => name_for_index(process, n) }) writer.puts "started with pid #{pid}" rescue Errno::ENOENT From 90848e7dea7250ce5842879085aabedc192fa0dc Mon Sep 17 00:00:00 2001 From: Leonardo Mosquera Date: Tue, 16 Apr 2013 22:31:15 -0300 Subject: [PATCH 2/3] Change FOREMAN_PROCESS_NAME to just PS --- lib/foreman/engine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/foreman/engine.rb b/lib/foreman/engine.rb index a79a025..7dd5cf4 100644 --- a/lib/foreman/engine.rb +++ b/lib/foreman/engine.rb @@ -360,7 +360,7 @@ private begin pid = process.run(:output => writer, :env => { "PORT" => port_for(process, n).to_s, - "FOREMAN_PROCESS_NAME" => name_for_index(process, n) + "PS" => name_for_index(process, n) }) writer.puts "started with pid #{pid}" rescue Errno::ENOENT From 9866a341caf8040c08f8ba4533690950ef10717d Mon Sep 17 00:00:00 2001 From: Leonardo Mosquera Date: Tue, 16 Apr 2013 22:31:34 -0300 Subject: [PATCH 3/3] Add unit test for PS env var --- spec/foreman/cli_spec.rb | 7 +++++++ spec/resources/Procfile | 1 + 2 files changed, 8 insertions(+) diff --git a/spec/foreman/cli_spec.rb b/spec/foreman/cli_spec.rb index 717ab52..7e5c410 100644 --- a/spec/foreman/cli_spec.rb +++ b/spec/foreman/cli_spec.rb @@ -44,6 +44,13 @@ describe "Foreman::CLI", :fakefs do output.should =~ /test.1 \| testing/ end end + + it "sets PS variable with the process name" do + without_fakefs do + output = foreman("start -f #{resource_path("Procfile")}") + output.should =~ /ps.1 \| PS env var is ps.1/ + end + end end end diff --git a/spec/resources/Procfile b/spec/resources/Procfile index f4bcb95..8c7a324 100644 --- a/spec/resources/Procfile +++ b/spec/resources/Procfile @@ -2,3 +2,4 @@ echo: bin/echo echoing env: bin/env FOO test: bin/test utf8: bin/utf8 +ps: bin/echo PS env var is $PS