class SesProxy::StartCommand

Public Instance Methods

default_http_address() click to toggle source
# File lib/ses_proxy/main_command.rb, line 43
def default_http_address
  if SesProxy::Conf.get[:http] and SesProxy::Conf.get[:http][:host]
    SesProxy::Conf.get[:http][:host]
  else
    "0.0.0.0"
  end
end
default_http_port() click to toggle source
# File lib/ses_proxy/main_command.rb, line 34
def default_http_port
  if SesProxy::Conf.get[:http] and SesProxy::Conf.get[:http][:port]
    SesProxy::Conf.get[:http][:port]
  else
    9292
  end
end
default_smtp_host() click to toggle source
# File lib/ses_proxy/main_command.rb, line 25
def default_smtp_host
  if SesProxy::Conf.get[:smtp] and SesProxy::Conf.get[:smtp][:host]
    SesProxy::Conf.get[:smtp][:host]
  else
    "0.0.0.0"
  end
end
default_smtp_port() click to toggle source
# File lib/ses_proxy/main_command.rb, line 16
def default_smtp_port
  if SesProxy::Conf.get[:smtp] and SesProxy::Conf.get[:smtp][:port]
    SesProxy::Conf.get[:smtp][:port]
  else
    1025
  end
end
execute() click to toggle source
# File lib/ses_proxy/main_command.rb, line 62
def execute
  check_for_config_file config_file
  check_for_mongoid_config_file mongoid_config_file

  @@env = environment
  Mongoid.load! mongoid_config_file, @@env
  if @@env.eql?"development"
    Mongoid.logger.level = Logger::DEBUG
    Mongo::Logger.logger.level = Logger::DEBUG if defined?(Mongo)
  else
    Mongoid.logger.level = Logger::INFO
    Mongo::Logger.logger.level = Logger::INFO if defined?(Mongo)
  end

  ses = AWS::SimpleEmailService.new(SesProxy::Conf.get[:aws])
  VerifiedSender.update_identities ses.client

  app = Rack::Builder.new do
    use Rack::Reloader, 0 if @@env.eql?"development"
    map "/sns_endpoint" do
      run SesProxy::SnsEndpoint.new
    end
    run Sinatra::Application
  end.to_app
  options = {:app=>app, :environment=>environment, :server=>"thin", :Port=>http_port, :Host=>http_address}
  server = Rack::Server.new options

  SesProxy::SmtpServer.parms = {:auth => :required}
  if demonize?
    options = {:app_name => "ses_proxy", :dir_mode=>:normal, :dir=>pid_dir}
    group = Daemons::ApplicationGroup.new('ses_proxy', options)
    options[:mode] = :proc
    options[:proc] = Proc.new { EM.run{ SesProxy::SmtpServer.start smtp_host, smtp_port } }
    pid = Daemons::PidFile.new pid_dir, "ses_proxy_num.0"
    @smtp = Daemons::Application.new(group, options, pid)
    options[:proc] = Proc.new { server.start }
    pid = Daemons::PidFile.new pid_dir, "ses_proxy_num.1"
    @http = Daemons::Application.new(group, options, pid)
    @smtp.start
    @http.start
  else
    EM.run do
      SesProxy::SmtpServer.start smtp_host, smtp_port
      server.start
      trap(:INT) {
        SesProxy::SmtpServer.stop
        EM.stop
      }
    end
  end
end

Private Instance Methods

check_for_config_file(path) click to toggle source
# File lib/ses_proxy/main_command.rb, line 116
def check_for_config_file(path)
  if path.eql? File.join(Dir.home,'.ses-proxy','ses-proxy.yml').to_s
    unless File.directory? File.join(Dir.home,'.ses-proxy')
      Dir.mkdir(File.join(Dir.home,'.ses-proxy'))
    end
    unless File.exists? path
      FileUtils.cp File.join(ROOT,"template","ses-proxy.yml").to_s, path
      puts "ATTENTION: Edit '#{path}' file with your data and then restart ses_proxy."
      exit
    end
  else
    unless File.exists? path
      raise ArgumentError, "Configuration file '#{path}' not found!"
    end
  end
end
check_for_mongoid_config_file(path) click to toggle source
# File lib/ses_proxy/main_command.rb, line 133
def check_for_mongoid_config_file(path)
  if path.eql? File.join(Dir.home,'.ses-proxy','mongoid.yml').to_s
    unless File.directory? File.join(Dir.home,'.ses-proxy')
      Dir.mkdir(File.join(Dir.home,'.ses-proxy'))
    end
    unless File.exists? path
      FileUtils.cp File.join(ROOT,"template","mongoid.yml").to_s, path
      puts "ATTENTION: Edit '#{path}' file with your data and then restart ses_proxy."
      exit
    end
  else
    unless File.exists? path
      raise ArgumentError, "Configuration file '#{path}' not found!"
    end
  end
end