From 8b204db2f04d99b78e0325d29ee033b7cde80b8e Mon Sep 17 00:00:00 2001 From: Indrek Juhkam Date: Tue, 31 Jul 2012 20:53:54 +0300 Subject: [PATCH] Use path and env variables in the inittab export --- lib/foreman/export/inittab.rb | 11 ++++++++++- spec/resources/export/inittab/inittab.concurrency | 4 ++-- spec/resources/export/inittab/inittab.default | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/foreman/export/inittab.rb b/lib/foreman/export/inittab.rb index 28b04a8..d8b1f4d 100644 --- a/lib/foreman/export/inittab.rb +++ b/lib/foreman/export/inittab.rb @@ -13,7 +13,16 @@ class Foreman::Export::Inittab < Foreman::Export::Base 1.upto(engine.formation[name]) do |num| id = app.slice(0, 2).upcase + sprintf("%02d", index) port = engine.port_for(process, num) - inittab << "#{id}:4:respawn:/bin/su - #{user} -c 'PORT=#{port} #{process.command} >> #{log}/#{name}-#{num}.log 2>&1'" + + commands = [] + commands << "cd #{engine.root}" + commands << "export PORT=#{port}" + engine.env.each_pair do |var, env| + commands << "export #{var.upcase}=#{shell_quote(env)}" + end + commands << "#{process.command} >> #{log}/#{name}-#{num}.log 2>&1" + + inittab << "#{id}:4:respawn:/bin/su - #{user} -c '#{commands.join(";")}'" index += 1 end end diff --git a/spec/resources/export/inittab/inittab.concurrency b/spec/resources/export/inittab/inittab.concurrency index 9799fda..1f78357 100644 --- a/spec/resources/export/inittab/inittab.concurrency +++ b/spec/resources/export/inittab/inittab.concurrency @@ -1,4 +1,4 @@ # ----- foreman app processes ----- -AP01:4:respawn:/bin/su - app -c 'PORT=5000 ./alpha >> /var/log/app/alpha-1.log 2>&1' -AP02:4:respawn:/bin/su - app -c 'PORT=5001 ./alpha >> /var/log/app/alpha-2.log 2>&1' +AP01:4:respawn:/bin/su - app -c 'cd /tmp/app;export PORT=5000;./alpha >> /var/log/app/alpha-1.log 2>&1' +AP02:4:respawn:/bin/su - app -c 'cd /tmp/app;export PORT=5001;./alpha >> /var/log/app/alpha-2.log 2>&1' # ----- end foreman app processes ----- diff --git a/spec/resources/export/inittab/inittab.default b/spec/resources/export/inittab/inittab.default index 0d5a094..f12762a 100644 --- a/spec/resources/export/inittab/inittab.default +++ b/spec/resources/export/inittab/inittab.default @@ -1,4 +1,4 @@ # ----- foreman app processes ----- -AP01:4:respawn:/bin/su - app -c 'PORT=5000 ./alpha >> /var/log/app/alpha-1.log 2>&1' -AP02:4:respawn:/bin/su - app -c 'PORT=5100 ./bravo >> /var/log/app/bravo-1.log 2>&1' +AP01:4:respawn:/bin/su - app -c 'cd /tmp/app;export PORT=5000;./alpha >> /var/log/app/alpha-1.log 2>&1' +AP02:4:respawn:/bin/su - app -c 'cd /tmp/app;export PORT=5100;./bravo >> /var/log/app/bravo-1.log 2>&1' # ----- end foreman app processes -----