#!/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 = {multiple: true} daemon_options.update(dir_mode: :normal, dir: options.pid_dir) if options.pid_dir Daemons.run_proc('ar_mailer_aws', daemon_options) do # handle log files if defined? Rails ActiveRecord::Base.establish_connection logger = ActiveSupport::BufferedLogger.new(Rails.root.join("log/#{Rails.env}.log")) ActiveRecord::Base.logger = logger unless Rails.env.production? Rails.logger = ActionMailer::Base.logger = logger end if ArMailerAWS.logger.respond_to?(:reopen) ArMailerAWS.logger.reopen ArMailerAWS.logger.info 'Started daemon' end AWS.config.logger.reopen if AWS.config.logger.respond_to?(:reopen) # run mailer ArMailerAWS.run(options) end