class Postfix

Public Instance Methods

deploy() click to toggle source
# File lib/dust/recipes/postfix.rb, line 3
def deploy
  @config = default_config.merge @config
  @config.boolean_to_string! # parse 'no/yes' as string, not as boolean

  Array(@config['package']).each do |package|
    return unless @node.install_package(package)
  end

  if @config['main.cf']
    main_cf = ''
    @config['main.cf'].each { |key, value| main_cf << "#{key} = #{value}\n" }
    @node.write "#{@config['etc_dir']}/main.cf", main_cf
  end

  if @config['master.cf']
    master_cf = "# service\ttype\tprivate\tunpriv\tchroot\twakeup\tmaxproc\tcommand\n\n"
    @config['master.cf'].each do |s|
      return @node.messages.add("service missing: #{s.inspect}").failed unless s['service']
      s = default_service(s['service']).merge s

      master_cf << "#{s['service']}\t" +
                   "#{s['service'].length > 7 ? '' : "\t"}" + # adds second tab if needed
                   "#{s['type']}\t#{s['private']}\t" +
                   "#{s['unpriv']}\t#{s['chroot']}\t#{s['wakeup']}\t" +
                   "#{s['maxproc']}\t#{s['command']}\n"
      if s['args']
        Array(s['args']).each { |a|  master_cf << "  #{a}\n" }
        master_cf << "\n"
      end
    end

    @node.write "#{@config['etc_dir']}/master.cf", master_cf
  end

  if @config['sql']
    @node.messages.add("configuring sql database\n")
    @node.mkdir("#{@config['etc_dir']}/sql")

    @config['sql'].each do |file, config|
      content = ''
      config.each { |key, value| content << "#{key} = #{value}\n" }
      @node.write("#{@config['etc_dir']}/sql/#{file}", content, :indent => 2)
    end
  end

  @node.restart_service @config['service'] if @options.restart?
  @node.reload_service @config['service'] if @options.reload?
end

Private Instance Methods

default_config() click to toggle source

default dust configuration

# File lib/dust/recipes/postfix.rb, line 56
def default_config
  { 'package' => 'postfix', 'etc_dir' => '/etc/postfix', 'service' => 'postfix' }
end
default_service(service) click to toggle source

master.cf default service configuration

# File lib/dust/recipes/postfix.rb, line 61
def default_service(service)
  { 'type' => 'unix', 'private' => '-', 'unpriv' => '-', 'chroot' => '-',
    'wakeup' => '-', 'maxproc' => '-', 'command' => service }
end