Merge branch 'master' of github.com:ddollar/foreman
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
module Foreman
|
||||
|
||||
VERSION = "0.1.0"
|
||||
VERSION = "0.2.0"
|
||||
|
||||
class AppDoesNotExist < Exception; end
|
||||
|
||||
|
||||
@@ -13,6 +13,20 @@ class Foreman::CLI < Thor
|
||||
Foreman::Engine.new(procfile).start
|
||||
end
|
||||
|
||||
desc "execute PROCESS [PROCFILE]", "Run an instance of the specified process from PROCFILE"
|
||||
|
||||
def execute(process, procfile="Procfile")
|
||||
error "#{procfile} does not exist." unless procfile_exists?(procfile)
|
||||
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")
|
||||
|
||||
+31
-7
@@ -1,5 +1,6 @@
|
||||
require "foreman"
|
||||
require "foreman/process"
|
||||
require "tempfile"
|
||||
|
||||
class Foreman::Engine
|
||||
|
||||
@@ -34,23 +35,46 @@ 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
|
||||
|
||||
private ######################################################################
|
||||
|
||||
def fork(process)
|
||||
pid = Process.fork do
|
||||
proctitle "ruby: foreman #{process.name}"
|
||||
|
||||
Dir.chdir directory do
|
||||
FileUtils.mkdir_p "log"
|
||||
system "#{process.command} >>log/#{process.name}.log 2>&1"
|
||||
exit $?.exitstatus || 255
|
||||
end
|
||||
run(process)
|
||||
end
|
||||
|
||||
info "started with pid #{pid}", process
|
||||
running_processes[pid] = process
|
||||
end
|
||||
|
||||
def run(process, log_to_file=true)
|
||||
proctitle "ruby: foreman #{process.name}"
|
||||
|
||||
Dir.chdir directory do
|
||||
FileUtils.mkdir_p "log"
|
||||
command = process.command
|
||||
command << " >>log/#{process.name}.log 2>&1" if log_to_file
|
||||
system command
|
||||
exit $?.exitstatus || 255
|
||||
end
|
||||
end
|
||||
|
||||
def kill_and_exit(signal="TERM")
|
||||
info "termination requested"
|
||||
running_processes.each do |pid, process|
|
||||
|
||||
Reference in New Issue
Block a user