lib/foreman/engine.rb in foreman-0.3.1 vs lib/foreman/engine.rb in foreman-0.3.2
- old
+ new
@@ -75,14 +75,18 @@
Dir.chdir directory do
FileUtils.mkdir_p "log"
command = process.command
- PTY.spawn("#{process.command} 2>&1") do |stdin, stdout, pid|
- until stdin.eof?
- info stdin.gets, process
+ begin
+ PTY.spawn("#{process.command} 2>&1") do |stdin, stdout, pid|
+ until stdin.eof?
+ info stdin.gets, process
+ end
end
+ rescue PTY::ChildExited
+ # exited
end
end
end
def kill_and_exit(signal="TERM")
@@ -94,12 +98,26 @@
exit 0
end
def info(message, process=nil)
print process.color if process
- print "[#{Time.now.strftime("%H:%M:%S")}] [#{process ? process.name : "system"}] #{message.chomp}"
+ print "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(process)} | "
print Term::ANSIColor.reset
+ print message.chomp
puts
+ end
+
+ def longest_process_name
+ @longest_process_name ||= begin
+ longest = processes.keys.map { |name| name.length }.sort.last
+ longest = 6 if longest < 6 # system
+ longest
+ end
+ end
+
+ def pad_process_name(process)
+ name = process ? process.name : "system"
+ name.ljust(longest_process_name)
end
def print_info
info "currently running processes:"
running_processes.each do |pid, process|