class H2OConfigurator::Builder

Public Class Methods

new(site_dirs=nil) click to toggle source
# File lib/h2o-configurator/builder.rb, line 5
def initialize(site_dirs=nil)
  @site_dirs = site_dirs ? site_dirs.map { |p| Path.new(p) } : Path.glob(SitesDirGlob)
end

Public Instance Methods

check_config(file) click to toggle source
# File lib/h2o-configurator/builder.rb, line 34
def check_config(file)
  system('h2o', '--mode=test', '--conf', file.to_s)
  raise Error, "h2o check failed: status #{$?.to_i}" unless $?.success?
end
make_config() click to toggle source
# File lib/h2o-configurator/builder.rb, line 9
def make_config
  @site_dirs.reject! { |p| p.extname == '.old' || p.extname == '.new' }
  raise "No sites defined" if @site_dirs.empty?
  config = {
    'compress' => 'ON',
    'reproxy' => 'ON',
    'error-log' => ErrorLogFile.to_s,
    'hosts' => {},
  }
  @site_dirs.sort.each do |dir|
    host = Host.new(dir)
    puts "%30s => %s" % [host.name, host.dir]
    config['hosts'].merge!(host.make_config)
  end
  config
end
write_config() click to toggle source
# File lib/h2o-configurator/builder.rb, line 26
def write_config
  H2OConfFile.write(YAML.dump(make_config))
  InstalledHandlersDir.rmtree if InstalledHandlersDir.exist?
  HandlersDir.cp_r(InstalledHandlersDir)
  H2OLogDir.mkpath
  check_config(H2OConfFile)
end