#!/usr/bin/env ruby $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') require 'ar_mailer_aws' require 'daemons' require 'ostruct' require 'optparse' # require Rails environment expect running tests name = File.basename $0 unless name == 'rspec' begin require Dir.pwd + '/config/environment' ActiveRecord::Base.connection.disconnect! rescue LoadError <<-EOF #{name} must be run from a Rails application's root to deliver email. #{Dir.pwd} does not appear to be a Rails application root. EOF end end options = ArMailerAWS.parse_options(ARGV) daemon_options = options.pid_dir ? {dir_mode: :normal, dir: options.pid_dir} : {} Daemons.run_proc('ar_mailer_aws', daemon_options) do if defined? Rails ActiveRecord::Base.establish_connection Rails.logger = ActiveRecord::Base.logger = ActionMailer::Base.logger = ActiveSupport::BufferedLogger.new(Rails.root.join("log/#{Rails.env}.log")) end ArMailerAWS.run(options) end