Allow running MailCatcher as a daemon.
This commit is contained in:
parent
8d6c237d62
commit
f8897680ce
|
@ -1,4 +1,5 @@
|
||||||
require 'active_support/all'
|
require 'active_support/all'
|
||||||
|
require 'daemons'
|
||||||
require 'eventmachine'
|
require 'eventmachine'
|
||||||
require 'thin'
|
require 'thin'
|
||||||
|
|
||||||
|
@ -16,13 +17,14 @@ module MailCatcher
|
||||||
:http_ip => '127.0.0.1',
|
:http_ip => '127.0.0.1',
|
||||||
:http_port => '1080',
|
:http_port => '1080',
|
||||||
:verbose => false,
|
:verbose => false,
|
||||||
|
:daemon => false,
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.parse! arguments=ARGV, defaults=@@defaults
|
def self.parse! arguments=ARGV, defaults=@@defaults
|
||||||
@@defaults.dup.tap do |options|
|
@@defaults.dup.tap do |options|
|
||||||
OptionParser.new do |parser|
|
OptionParser.new do |parser|
|
||||||
parser.banner = 'Usage: mailcatcher [options]'
|
parser.banner = 'Usage: mailcatcher [options]'
|
||||||
|
|
||||||
parser.on('--ip IP', 'Set the ip address of both servers') do |ip|
|
parser.on('--ip IP', 'Set the ip address of both servers') do |ip|
|
||||||
options[:smtp_ip] = options[:http_ip] = ip
|
options[:smtp_ip] = options[:http_ip] = ip
|
||||||
end
|
end
|
||||||
|
@ -43,6 +45,10 @@ module MailCatcher
|
||||||
options[:http_port] = port
|
options[:http_port] = port
|
||||||
end
|
end
|
||||||
|
|
||||||
|
parser.on('-d', '--daemon', 'Run as a daemon') do
|
||||||
|
options[:daemon] = true
|
||||||
|
end
|
||||||
|
|
||||||
parser.on('-v', '--verbose', 'Be more verbose') do
|
parser.on('-v', '--verbose', 'Be more verbose') do
|
||||||
options[:verbose] = true
|
options[:verbose] = true
|
||||||
end
|
end
|
||||||
|
@ -66,9 +72,18 @@ module MailCatcher
|
||||||
puts "==> http://#{options[:http_ip]}:#{options[:http_port]}"
|
puts "==> http://#{options[:http_ip]}:#{options[:http_port]}"
|
||||||
|
|
||||||
Thin::Logging.silent = true
|
Thin::Logging.silent = true
|
||||||
|
|
||||||
EventMachine.run do
|
EventMachine.run do
|
||||||
EventMachine.start_server options[:smtp_ip], options[:smtp_port], Smtp
|
EventMachine.start_server options[:smtp_ip], options[:smtp_port], Smtp
|
||||||
|
|
||||||
Thin::Server.start options[:http_ip], options[:http_port], Web
|
Thin::Server.start options[:http_ip], options[:http_port], Web
|
||||||
|
|
||||||
|
if options[:daemon]
|
||||||
|
# Make sure the servers start before daemonizing.
|
||||||
|
EventMachine.next_tick do
|
||||||
|
Daemons.daemonize :app_name => "mailcatcher"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue