lib/gitdocs.rb in gitdocs-0.1.5 vs lib/gitdocs.rb in gitdocs-0.2.0
- old
+ new
@@ -7,24 +7,40 @@
require 'rb-fsevent'
require 'growl'
require 'yajl'
require 'dante'
+
module Gitdocs
- def self.run(config_root = nil, debug=false)
+
+ DEBUG = ENV['DEBUG']
+
+ def self.run(config_root = nil, debug = DEBUG)
loop do
- @config = Configuration.new(config_root)
+ config = Configuration.new(config_root)
puts "Gitdocs v#{VERSION}" if debug
- puts "Using configuration root: '#{@config.config_root}'" if debug
- puts "Watch paths: #{@config.paths.join(", ")}" if debug
- @threads = @config.paths.map do |path|
- t = Thread.new { Runner.new(path).run }
+ puts "Using configuration root: '#{config.config_root}'" if debug
+ puts "Watch paths: #{config.paths.join(", ")}" if debug
+ # Start the repo watchers
+ runners = []
+ threads = config.paths.map do |path|
+ t = Thread.new(runners) { |r|
+ runner = Runner.new(path)
+ r << runner
+ runner.run
+ }
t.abort_on_exception = true
t
end
- puts "Watch threads: #{@threads.map { |t| "Thread status: '#{t.status}', running: #{t.alive?}" }}" if debug
- puts "Joined #{@threads.size} watch threads...running" if debug
- @threads.each(&:join)
+ sleep 1
+ unless defined?(pid) && pid
+ # Start the web front-end
+ pid = fork { Server.new(*runners).start }
+ at_exit { Process.kill("KILL", pid) rescue nil }
+ end
+ puts "Watch threads: #{threads.map { |t| "Thread status: '#{t.status}', running: #{t.alive?}" }}" if debug
+ puts "Joined #{threads.size} watch threads...running" if debug
+ threads.each(&:join)
sleep(60)
end
end
end