Class: SesProxy::StartCommand

Inherits:
Clamp::Command
  • Object
show all
Defined in:
lib/ses_proxy/main_command.rb

Constant Summary collapse

@@env =
"development"

Instance Method Summary collapse

Instance Method Details

#default_http_addressObject



43
44
45
46
47
48
49
# 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_portObject



34
35
36
37
38
39
40
# 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_hostObject



25
26
27
28
29
30
31
# 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_portObject



16
17
18
19
20
21
22
# 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

#executeObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# 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