diff --git a/lib/foreman/cli.rb b/lib/foreman/cli.rb index 32db1a6..a1be7ea 100644 --- a/lib/foreman/cli.rb +++ b/lib/foreman/cli.rb @@ -20,6 +20,13 @@ class Foreman::CLI < Thor Foreman::Engine.new(procfile).execute(process) end + desc "screen [PROCFILE]", "Run the app described in PROCFILE as screen windows" + + def screen(procfile="Procfile") + error "#{procfile} does not exist." unless procfile_exists?(procfile) + Foreman::Engine.new(procfile).screen + end + desc "export APP [PROCFILE] [FORMAT]", "Export the app described in PROCFILE as APP to another FORMAT" def export(app, procfile="Procfile", format="upstart") diff --git a/lib/foreman/engine.rb b/lib/foreman/engine.rb index a6c0d1f..d7d125d 100644 --- a/lib/foreman/engine.rb +++ b/lib/foreman/engine.rb @@ -1,5 +1,6 @@ require "foreman" require "foreman/process" +require "tempfile" class Foreman::Engine @@ -34,6 +35,19 @@ class Foreman::Engine run_loop end + def screen + tempfile = Tempfile.new("foreman") + tempfile.puts "sessionname foreman" + processes.each do |name, process| + tempfile.puts "screen -t #{name} #{process.command}" + end + tempfile.close + + system "screen -c #{tempfile.path}" + + tempfile.delete + end + def execute(name) run(processes[name], false) end