From 698e6ae092112e6b7404814ca8ecfbba14b42087 Mon Sep 17 00:00:00 2001 From: Aaron Kalin Date: Mon, 10 Sep 2012 19:10:47 -0500 Subject: [PATCH] Add command argument string splitting launchd uses exec() under the hood when you specify ProgramArguments or Program so you must break apart program arguments into separate strings in an array or the command will fail --- data/export/launchd/launchd.plist.erb | 4 ++- lib/foreman/export/launchd.rb | 1 + spec/foreman/export/launchd_spec.rb | 10 +++++++ .../export/launchd/launchd-c.default | 28 +++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 spec/resources/export/launchd/launchd-c.default diff --git a/data/export/launchd/launchd.plist.erb b/data/export/launchd/launchd.plist.erb index 1731c4c..8694564 100644 --- a/data/export/launchd/launchd.plist.erb +++ b/data/export/launchd/launchd.plist.erb @@ -13,7 +13,9 @@ ProgramArguments - <%= process.command %> + <%- command_args.each do |command| -%> + <%= command %> + <%- end -%> KeepAlive diff --git a/lib/foreman/export/launchd.rb b/lib/foreman/export/launchd.rb index 4b9571f..ceee3a8 100644 --- a/lib/foreman/export/launchd.rb +++ b/lib/foreman/export/launchd.rb @@ -8,6 +8,7 @@ class Foreman::Export::Launchd < Foreman::Export::Base engine.each_process do |name, process| 1.upto(engine.formation[name]) do |num| port = engine.port_for(process, num) + command_args = process.command.split(" ") write_template "launchd/launchd.plist.erb", "#{app}-#{name}-#{num}.plist", binding end end diff --git a/spec/foreman/export/launchd_spec.rb b/spec/foreman/export/launchd_spec.rb index 984b35c..3a22b5a 100644 --- a/spec/foreman/export/launchd_spec.rb +++ b/spec/foreman/export/launchd_spec.rb @@ -18,4 +18,14 @@ describe Foreman::Export::Launchd, :fakefs do File.read("/tmp/init/app-bravo-1.plist").should == example_export_file("launchd/launchd-b.default") end + context "with multiple command arguments" do + let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile", "charlie") } + + it "splits each command argument" do + launchd.export + File.read("/tmp/init/app-alpha-1.plist").should == example_export_file("launchd/launchd-c.default") + end + + end + end diff --git a/spec/resources/export/launchd/launchd-c.default b/spec/resources/export/launchd/launchd-c.default new file mode 100644 index 0000000..8059a9d --- /dev/null +++ b/spec/resources/export/launchd/launchd-c.default @@ -0,0 +1,28 @@ + + + + + Label + app-alpha-1 + EnvironmentVariables + + PORT + 5000 + + ProgramArguments + + ./alpha + charlie + + KeepAlive + + RunAtLoad + + StandardErrorPath + /var/log/app/app-alpha-1.log + UserName + app + WorkingDirectory + /tmp/app + +