Created
April 6, 2009 21:00
-
-
Save andreareginato/90938 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'tlsmail' | |
RAILS_ROOT = "/Users/reggie/src/new_altomic/altomic" | |
FETCHER_SCRIPT = "RAILS_ENV=production #{RAILS_ROOT}/script/mailer_daemon_fetcher" | |
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE) | |
# mail settings | |
God::Contacts::Email.message_settings = { | |
:from => 'altomic.mail.test@altomic.com' | |
} | |
God::Contacts::Email.server_settings = { | |
:address => "smtp.gmail.com", | |
:tls => 'true', | |
:port => 587, | |
:domain => 'gmail.com', | |
:user_name => "********@gmail.com", | |
:password => "*******", | |
:authentication => :plain | |
} | |
God.contact(:email) do |c| | |
c.name = 'Andrea Reginato' | |
c.email = 'andrew@mikamai.com' | |
c.group = 'developers' | |
end | |
# process watching | |
God.watch do |w| | |
# this is a unique name that can be used also later on | |
# to call some of these commands | |
w.name = "fetcher-daemon" | |
w.interval = 5.seconds | |
w.uid = 'reggie' | |
# definition of commands | |
w.start = "#{FETCHER_SCRIPT} start" | |
w.stop = "#{FETCHER_SCRIPT} stop" | |
w.restart = "#{FETCHER_SCRIPT} restart" | |
# time to wait after the starting (understand better) | |
w.start_grace = 10.seconds | |
w.restart_grace = 10.seconds | |
# (be careful to set the pid file number to the correct name) | |
w.pid_file = File.join(RAILS_ROOT, 'log', 'MailerDaemonFetcherDaemon.pid') | |
w.behavior(:clean_pid_file) | |
# At any given time, a Watch will be in one of the init, up, start, or restart states. | |
# As different conditions are satisfied, the Watch will progress from state to state, | |
# enabling and disabling conditions along the way. (READ MORE ON TRANSITION DOC...) | |
# determine the state on startup | |
w.transition(:init, { true => :up, false => :start }) do |on| | |
on.condition(:process_running) do |c| | |
c.running = true | |
end | |
end | |
# determine when process has finished starting | |
w.transition([:start, :restart], :up) do |on| | |
on.condition(:process_running) do |c| | |
c.running = true | |
end | |
end | |
# start if process is not running | |
w.transition(:up, :start) do |on| | |
on.condition(:process_exits) | |
end | |
# # bind the notification via mail when some problems occours | |
w.transition(:up, :start) do |on| | |
on.condition(:process_exits) do |c| | |
c.notify = 'developers' | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment